Browse Source

Merge pull request 'display preloader while downloading && upd icons' (#14) from display-preloader into master

Reviewed-on: #14
pull/15/head
rozetko 2 years ago
parent
commit
c869a8326c
  1. 10
      src/icons.ts
  2. 36
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx

10
src/icons.ts

@ -1,8 +1,10 @@
export const CLOSE_ICON_BASE_64 = export const CLOSE_ICON_BASE_64 =
'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACJSURBVHgB7ZPRCcAgDESv0lWc0zhC53OIjmAVUpCSamL76YEoyfFIiAGWfldK6SwnKHyhep9xJ3iPcqgH5RyxV1VlBWYJypXVHMEiCaqBbRhAy3W3B76j954wq6ZSVZsOY+WXt6i9l2ymGTlUq0VpOcIqaQC96Zth01DN1zBBefVI4SNp9Za+6wLcH6DKFrfpxgAAAABJRU5ErkJggg=='; 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAACJSURBVHgB7ZPRCcAgDESv0lWc0zhC53OIjmAVUpCSamL76YEoyfFIiAGWfldK6SwnKHyhep9xJ3iPcqgH5RyxV1VlBWYJypXVHMEiCaqBbRhAy3W3B76j954wq6ZSVZsOY+WXt6i9l2ymGTlUq0VpOcIqaQC96Zth01DN1zBBefVI4SNp9Za+6wLcH6DKFrfpxgAAAABJRU5ErkJggg==';
export const OPTIONS_ICON_BASE_64 = export const OPTIONS_ICON_BASE_64 =
'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAS1BMVEUAAADH0NnH0NnH0NnH0NnH0NnH0NnH0NnH0N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AFAAUAAACMpSPqcvtDk6IT4RrABU7gRssEwNW5jOeBth5IcI2n5KqtvK1WVMmPZ3CZHSil01zS54KACH5BAkJAAIALAAAAAAUABQAAAIzlI+py40A3DshSFOtqCcukC2Bp4TX6UAoVZEKmGRuAtPzinfj15gPJ9ptNBsUEKfKKU8FACH5BAkJAAIALAAAAAAUABQAAAI0lI+py30QAnDPxEjFFVCauXTBB2plsmWqA5xqykBJx46zu+azp+AH/OD1eJjPqqhr6Za6AgAh+QQJCQACACwAAAAAFAAUAAACM5SPqcuNEdyCUAoqAASGM5x5l5iA1tkA5GkuWqJFqYyo6O1oa9e0XbD7eYAHmqSCSyqTBQA7';

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

@ -9,12 +9,18 @@ import {
} from '../types'; } from '../types';
import { convertTimestampToDate, convertTimeZoneTypeToName, getCurrentDashboardUid } from '../../../utils'; 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 { 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 { appEvents, contextSrv } from 'grafana/app/core/core'; import { contextSrv } from 'grafana/app/core/core';
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import { import {
@ -40,7 +46,6 @@ import {
DataSourceSettings, DataSourceSettings,
TimeRange, TimeRange,
OrgRole, OrgRole,
AppEvents,
} from '@grafana/data'; } from '@grafana/data';
import { RefreshEvent } from '@grafana/runtime'; import { RefreshEvent } from '@grafana/runtime';
@ -58,6 +63,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
const [tasks, setTasks] = useState<ExportTask[] | null>(null); const [tasks, setTasks] = useState<ExportTask[] | null>(null);
const [queries, setQueries] = useState<DashboardQuery[] | null>(null); const [queries, setQueries] = useState<DashboardQuery[] | null>(null);
const [taskIdBeingDownloaded, setTaskIdBeingDownloaded] = useState<string | null>(null);
const [tasksDataFrame, setTasksDataFrame] = useState<DataFrame | null>(null); const [tasksDataFrame, setTasksDataFrame] = useState<DataFrame | null>(null);
const [queriesDataFrame, setQueriesDataFrame] = useState<DataFrame | null>(null); const [queriesDataFrame, setQueriesDataFrame] = useState<DataFrame | null>(null);
@ -106,7 +112,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
} }
const dataFrame = getDataFrameForTaskTable(tasks); const dataFrame = getDataFrameForTaskTable(tasks);
setTasksDataFrame(dataFrame); 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 useEffect(fetchTasks, []); // eslint-disable-line react-hooks/exhaustive-deps
@ -243,10 +249,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
{ {
name: 'Select', name: 'Select',
type: FieldType.string, type: FieldType.string,
values: _.map( values: _.map(queries, (query) => (query.selected ? SELECT_ICON_BASE_64 : UNSELECT_ICON_BASE_64)),
queries,
(query) => `data:image/svg+xml;base64,${query.selected ? SELECT_ICON_BASE_64 : UNSELECT_ICON_BASE_64}`
),
config: { config: {
custom: { custom: {
filterable: false, filterable: false,
@ -348,11 +351,15 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
values: _.map(sortedTasks, (task) => { values: _.map(sortedTasks, (task) => {
switch (task.progress?.status) { switch (task.progress?.status) {
case ExportStatus.FINISHED: 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: case ExportStatus.ERROR:
return `data:image/png;base64,${CLOSE_ICON_BASE_64}`; return CLOSE_ICON_BASE_64;
case ExportStatus.EXPORTING: case ExportStatus.EXPORTING:
return ``; return '';
default: default:
throw new Error(`Unknown exporting status: ${task.progress?.status}`); throw new Error(`Unknown exporting status: ${task.progress?.status}`);
} }
@ -425,9 +432,10 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
setTasks(filteredTasks); setTasks(filteredTasks);
} }
function onDownloadClick(task: ExportTask): void { async function onDownloadClick(task: ExportTask): Promise<void> {
appEvents.emit(AppEvents.alertSuccess, ['CSV has started downloading...']); setTaskIdBeingDownloaded(task.id as string);
getStaticFile(task?.id); await getStaticFile(task?.id);
setTaskIdBeingDownloaded(null);
} }
function onDatasourceSelectClick(e: DataLinkClickEvent): void { function onDatasourceSelectClick(e: DataLinkClickEvent): void {

Loading…
Cancel
Save