|
|
@ -1,7 +1,8 @@ |
|
|
|
import { PanelOptions, TableRowConfig } from '../types'; |
|
|
|
import { PanelOptions, TableRowConfig } from '../types'; |
|
|
|
|
|
|
|
|
|
|
|
import { Table, Button, HorizontalGroup } from '@grafana/ui'; |
|
|
|
import { makeRequest } from 'services/network_service'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Table, Button, HorizontalGroup, LoadingPlaceholder } from '@grafana/ui'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
PanelProps, |
|
|
|
PanelProps, |
|
|
|
toDataFrame, |
|
|
|
toDataFrame, |
|
|
@ -12,23 +13,50 @@ import { |
|
|
|
DataLinkClickEvent, |
|
|
|
DataLinkClickEvent, |
|
|
|
} from '@grafana/data'; |
|
|
|
} from '@grafana/data'; |
|
|
|
|
|
|
|
|
|
|
|
import React, { useState } from 'react'; |
|
|
|
import React, { useState, useEffect } from 'react'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
|
|
|
|
|
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
interface Props extends PanelProps<PanelOptions> {} |
|
|
|
|
|
|
|
|
|
|
|
export function Panel({ options, data, width, height, timeRange, onChangeTimeRange }: Props) { |
|
|
|
export function Panel({ options, data, width, height, timeRange, onChangeTimeRange }: Props) { |
|
|
|
console.log('panel', data); |
|
|
|
console.log('panel', data); |
|
|
|
const configs: TableRowConfig[] = []; |
|
|
|
|
|
|
|
const [tasks, setTasks] = useState(configs); |
|
|
|
const [tasks, setTasks] = useState<TableRowConfig[] | null>(null); |
|
|
|
|
|
|
|
const [dataFrame, setDataFrame] = useState<DataFrame | null>(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if(tasks === null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
const dataFrame = getDataFrameForTable(tasks, setTasks); |
|
|
|
const dataFrame = getDataFrameForTable(tasks, setTasks); |
|
|
|
|
|
|
|
setDataFrame(dataFrame) |
|
|
|
|
|
|
|
}, [tasks]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
// TODO: move this function to Network Service
|
|
|
|
|
|
|
|
async function getTasks(): Promise<TableRowConfig[]> { |
|
|
|
|
|
|
|
return makeRequest<TableRowConfig[]>('/tasks', {}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getTasks().then(tasks => setTasks(tasks)).catch(err => console.error(err)); |
|
|
|
|
|
|
|
}, 2000); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
function onAddTaskClick(): void { |
|
|
|
function onAddTaskClick(): void { |
|
|
|
|
|
|
|
if(tasks === null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
const configs = [...tasks, createConfigItem()]; |
|
|
|
const configs = [...tasks, createConfigItem()]; |
|
|
|
setTasks(configs); |
|
|
|
setTasks(configs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
{dataFrame === null ?
|
|
|
|
|
|
|
|
// TODO: if datasource responds with error, display the error
|
|
|
|
|
|
|
|
<LoadingPlaceholder text="Loading..."></LoadingPlaceholder> : |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<Table width={width} height={height - 40} data={dataFrame} /> |
|
|
|
<Table width={width} height={height - 40} data={dataFrame} /> |
|
|
|
<HorizontalGroup justify="flex-end"> |
|
|
|
<HorizontalGroup justify="flex-end"> |
|
|
@ -43,6 +71,8 @@ export function Panel({ options, data, width, height, timeRange, onChangeTimeRan |
|
|
|
</Button> |
|
|
|
</Button> |
|
|
|
</HorizontalGroup> |
|
|
|
</HorizontalGroup> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|