Browse Source

make Delete work

pull/5/head
rozetko 2 years ago
parent
commit
6acc0e2d7f
  1. 24
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx
  2. 8
      src/services/api_service.ts

24
src/panels/corpglory-dataexporter-panel/components/Panel.tsx

@ -3,7 +3,7 @@ import { PanelOptions, TaskTableRowConfig, QueryTableRowConfig, DatasourceType }
import { convertTimestampToDate, getDashboardUid } from '../../../utils'; 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 { 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 { getDashboardByUid, getDatasources } from '../../../services/grafana_backend_service';
import { contextSrv } from 'grafana/app/core/core'; import { contextSrv } from 'grafana/app/core/core';
@ -108,9 +108,17 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
}, [queries]); }, [queries]);
function refresh(): void { function refresh(): void {
console.log('rfrsh')
getTasks() 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)); .catch((err) => console.error(err));
} }
@ -317,17 +325,19 @@ export function Panel({ width, height, timeRange, eventBus }: Props) {
return dataFrames[0]; return dataFrames[0];
} }
function onDeleteClick(e: DataLinkClickEvent): void { async function onDeleteClick(e: DataLinkClickEvent): Promise<void> {
// TODO: make DELETE request to the api
const rowIndex = e.origin.rowIndex; 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); const filteredTasks = _.filter(tasks, (task, idx) => idx !== rowIndex);
setTasks(filteredTasks); setTasks(filteredTasks);
} }
function onDownloadClick(e: DataLinkClickEvent): void { function onDownloadClick(e: DataLinkClickEvent): void {
// TODO: make DELETE request to the api
const rowIndex = e.origin.rowIndex; const rowIndex = e.origin.rowIndex;
const task = _.find(tasks, (task, idx) => idx !== rowIndex); const task = _.find(tasks, (task, idx) => idx === rowIndex);
getStaticFile(task?.filename); getStaticFile(task?.filename);
} }

8
src/services/api_service.ts

@ -47,6 +47,14 @@ export async function getTasks(): Promise<TaskTableRowConfig[]> {
return queryApi<TaskTableRowConfig[]>('/task', {}); return queryApi<TaskTableRowConfig[]>('/task', {});
} }
export async function deleteTask(filename?: string): Promise<void> {
if (_.isEmpty(filename)) {
console.warn(`can't delete task without filename`);
return;
}
await queryApi<TaskTableRowConfig[]>('/task', { method: 'DELETE', data: { filename } });
}
export async function getStaticFile(filename?: string): Promise<void> { export async function getStaticFile(filename?: string): Promise<void> {
if (_.isEmpty(filename)) { if (_.isEmpty(filename)) {
console.warn(`can't download file without name`); console.warn(`can't download file without name`);

Loading…
Cancel
Save