diff --git a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx index 8ebaa20..5ebbd74 100644 --- a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx +++ b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx @@ -1,7 +1,8 @@ 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 { PanelProps, toDataFrame, @@ -12,36 +13,62 @@ import { DataLinkClickEvent, } from '@grafana/data'; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import * as _ from 'lodash'; interface Props extends PanelProps {} export function Panel({ options, data, width, height, timeRange, onChangeTimeRange }: Props) { console.log('panel', data); - const configs: TableRowConfig[] = []; - const [tasks, setTasks] = useState(configs); - const dataFrame = getDataFrameForTable(tasks, setTasks); + + const [tasks, setTasks] = useState(null); + const [dataFrame, setDataFrame] = useState(null); + + useEffect(() => { + if(tasks === null) { + return; + } + const dataFrame = getDataFrameForTable(tasks, setTasks); + setDataFrame(dataFrame) + }, [tasks]); + + useEffect(() => { + // TODO: move this function to Network Service + async function getTasks(): Promise { + return makeRequest('/tasks', {}); + } + + getTasks().then(tasks => setTasks(tasks)).catch(err => console.error(err)); + }, []); function onAddTaskClick(): void { + if(tasks === null) { + return; + } const configs = [...tasks, createConfigItem()]; setTasks(configs); } return (
- - - - + {dataFrame === null ? + // TODO: if datasource responds with error, display the error + : +
+
+ + + + + } ); }