From 58e0b17546befa5fbef02bfee5d526518af84eb3 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 20 Jan 2023 22:23:04 +0300 Subject: [PATCH] display preloader while downloading && upd icons --- src/icons.ts | 10 +++--- .../components/Panel.tsx | 36 +++++++++++-------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/icons.ts b/src/icons.ts index 72e4d55..31cc44b 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -1,8 +1,10 @@ export const CLOSE_ICON_BASE_64 = - 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACJSURBVHgB7ZPRCcAgDESv0lWc0zhC53OIjmAVUpCSamL76YEoyfFIiAGWfldK6SwnKHyhep9xJ3iPcqgH5RyxV1VlBWYJypXVHMEiCaqBbRhAy3W3B76j954wq6ZSVZsOY+WXt6i9l2ymGTlUq0VpOcIqaQC96Zth01DN1zBBefVI4SNp9Za+6wLcH6DKFrfpxgAAAABJRU5ErkJggg=='; + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACJSURBVHgB7ZPRCcAgDESv0lWc0zhC53OIjmAVUpCSamL76YEoyfFIiAGWfldK6SwnKHyhep9xJ3iPcqgH5RyxV1VlBWYJypXVHMEiCaqBbRhAy3W3B76j954wq6ZSVZsOY+WXt6i9l2ymGTlUq0VpOcIqaQC96Zth01DN1zBBefVI4SNp9Za+6wLcH6DKFrfpxgAAAABJRU5ErkJggg=='; export const OPTIONS_ICON_BASE_64 = - 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAA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NBQAh+QQJCQACACwAAAAAFAAUAAACMpSPqcvtDk6IT4RrABU7gRssEwNW5jOeBth5IcI2n5KqtvK1WVMmPZ3CZHSil01zS54KACH5BAkJAAIALAAAAAAUABQAAAIzlI+py40A3DshSFOtqCcukC2Bp4TX6UAoVZEKmGRuAtPzinfj15gPJ9ptNBsUEKfKKU8FACH5BAkJAAIALAAAAAAUABQAAAI0lI+py30QAnDPxEjFFVCauXTBB2plsmWqA5xqykBJx46zu+azp+AH/OD1eJjPqqhr6Za6AgAh+QQJCQACACwAAAAAFAAUAAACM5SPqcuNEdyCUAoqAASGM5x5l5iA1tkA5GkuWqJFqYyo6O1oa9e0XbD7eYAHmqSCSyqTBQA7'; diff --git a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx index 90514ac..5021fce 100644 --- a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx +++ b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx @@ -9,12 +9,18 @@ import { } from '../types'; import { convertTimestampToDate, convertTimeZoneTypeToName, getCurrentDashboardUid } from '../../../utils'; -import { CLOSE_ICON_BASE_64, OPTIONS_ICON_BASE_64, SELECT_ICON_BASE_64, UNSELECT_ICON_BASE_64 } from '../../../icons'; +import { + CLOSE_ICON_BASE_64, + DOWNLOADING_ICON_BASE_64, + OPTIONS_ICON_BASE_64, + SELECT_ICON_BASE_64, + UNSELECT_ICON_BASE_64, +} from '../../../icons'; import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service'; import { getDashboardByUid, getDatasources } from '../../../services/grafana_backend_service'; -import { appEvents, contextSrv } from 'grafana/app/core/core'; +import { contextSrv } from 'grafana/app/core/core'; import { css } from '@emotion/css'; import { @@ -40,7 +46,6 @@ import { DataSourceSettings, TimeRange, OrgRole, - AppEvents, } from '@grafana/data'; import { RefreshEvent } from '@grafana/runtime'; @@ -58,6 +63,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { const [tasks, setTasks] = useState(null); const [queries, setQueries] = useState(null); + const [taskIdBeingDownloaded, setTaskIdBeingDownloaded] = useState(null); const [tasksDataFrame, setTasksDataFrame] = useState(null); const [queriesDataFrame, setQueriesDataFrame] = useState(null); @@ -106,7 +112,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { } const dataFrame = getDataFrameForTaskTable(tasks); setTasksDataFrame(dataFrame); - }, [tasks]); // eslint-disable-line react-hooks/exhaustive-deps + }, [tasks, taskIdBeingDownloaded]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(fetchTasks, []); // eslint-disable-line react-hooks/exhaustive-deps @@ -243,10 +249,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { { name: 'Select', type: FieldType.string, - values: _.map( - queries, - (query) => `data:image/svg+xml;base64,${query.selected ? SELECT_ICON_BASE_64 : UNSELECT_ICON_BASE_64}` - ), + values: _.map(queries, (query) => (query.selected ? SELECT_ICON_BASE_64 : UNSELECT_ICON_BASE_64)), config: { custom: { filterable: false, @@ -348,11 +351,15 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { values: _.map(sortedTasks, (task) => { switch (task.progress?.status) { case ExportStatus.FINISHED: - return `data:image/png;base64,${OPTIONS_ICON_BASE_64}`; + if (task.id === taskIdBeingDownloaded) { + return DOWNLOADING_ICON_BASE_64; + } else { + return OPTIONS_ICON_BASE_64; + } case ExportStatus.ERROR: - return `data:image/png;base64,${CLOSE_ICON_BASE_64}`; + return CLOSE_ICON_BASE_64; case ExportStatus.EXPORTING: - return ``; + return ''; default: throw new Error(`Unknown exporting status: ${task.progress?.status}`); } @@ -425,9 +432,10 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { setTasks(filteredTasks); } - function onDownloadClick(task: ExportTask): void { - appEvents.emit(AppEvents.alertSuccess, ['CSV has started downloading...']); - getStaticFile(task?.id); + async function onDownloadClick(task: ExportTask): Promise { + setTaskIdBeingDownloaded(task.id as string); + await getStaticFile(task?.id); + setTaskIdBeingDownloaded(null); } function onDatasourceSelectClick(e: DataLinkClickEvent): void {