diff --git a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx index 2bbb81b..0c1b1d6 100644 --- a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx +++ b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx @@ -3,7 +3,7 @@ import { PanelOptions, TaskTableRowConfig, QueryTableRowConfig, DatasourceType } import { convertTimestampToDate, getDashboardUid } from '../../../utils'; import { CLOSE_ICON_BASE_64, DOWNLOAD_ICON_BASE_64, SELECT_ICON_BASE_64, UNSELECT_ICON_BASE_64 } from '../../../icons'; -import { getStaticFile, getTasks, queryApi } from '../../../services/api_service'; +import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service'; import { getDashboardByUid, getDatasources } from '../../../services/grafana_backend_service'; import { contextSrv } from 'grafana/app/core/core'; @@ -108,9 +108,17 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { }, [queries]); function refresh(): void { - console.log('rfrsh') getTasks() - .then((tasks) => setTasks(tasks)) + .then((tasks) => { + setTasks(tasks); + for (let task of tasks) { + // TODO: ExportStatus enum + if (task.status === 'exporting') { + setTimeout(refresh, 1000); + return; + } + } + }) .catch((err) => console.error(err)); } @@ -317,17 +325,19 @@ export function Panel({ width, height, timeRange, eventBus }: Props) { return dataFrames[0]; } - function onDeleteClick(e: DataLinkClickEvent): void { - // TODO: make DELETE request to the api + async function onDeleteClick(e: DataLinkClickEvent): Promise { const rowIndex = e.origin.rowIndex; + + const task = _.find(tasks, (task, idx) => idx === rowIndex); + await deleteTask(task?.filename); + const filteredTasks = _.filter(tasks, (task, idx) => idx !== rowIndex); setTasks(filteredTasks); } function onDownloadClick(e: DataLinkClickEvent): void { - // TODO: make DELETE request to the api const rowIndex = e.origin.rowIndex; - const task = _.find(tasks, (task, idx) => idx !== rowIndex); + const task = _.find(tasks, (task, idx) => idx === rowIndex); getStaticFile(task?.filename); } diff --git a/src/services/api_service.ts b/src/services/api_service.ts index 43dc643..a803327 100644 --- a/src/services/api_service.ts +++ b/src/services/api_service.ts @@ -47,6 +47,14 @@ export async function getTasks(): Promise { return queryApi('/task', {}); } +export async function deleteTask(filename?: string): Promise { + if (_.isEmpty(filename)) { + console.warn(`can't delete task without filename`); + return; + } + await queryApi('/task', { method: 'DELETE', data: { filename } }); +} + export async function getStaticFile(filename?: string): Promise { if (_.isEmpty(filename)) { console.warn(`can't download file without name`);