From ce59479b13fbeba1ef2d4040a7e97de78c03ed59 Mon Sep 17 00:00:00 2001 From: rozetko Date: Mon, 6 Feb 2023 15:54:08 +0300 Subject: [PATCH 1/5] Panel: remove Status Updated At and User columns --- .../corpglory-dataexporter-panel/components/Panel.tsx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx index 012960f..581ffdc 100644 --- a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx +++ b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx @@ -341,11 +341,6 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { ], }, }, - { - name: 'Status Updated At', - type: FieldType.number, - values: _.map(sortedTasks, (task) => convertTimestampToDate(task.progress?.time)), - }, { name: 'From', type: FieldType.number, @@ -356,11 +351,6 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { type: FieldType.number, values: _.map(sortedTasks, (task) => convertTimestampToDate(task.timeRange.to)), }, - { - name: 'User', - type: FieldType.string, - values: _.map(sortedTasks, (task) => task.username), - }, { name: 'Exported Rows', type: FieldType.number, From 6c6c0ec2a446b030a4b83ed7108af4945f96ae2a Mon Sep 17 00:00:00 2001 From: rozetko Date: Mon, 6 Feb 2023 15:54:22 +0300 Subject: [PATCH 2/5] 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3503103..cf8fb1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corpglory-dataexporter-app", - "version": "1.0.3", + "version": "1.0.4", "description": "", "scripts": { "lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --max-warnings=0 ./src", From ae52125e5caf951ce2125a6a59b626d3e6ac4526 Mon Sep 17 00:00:00 2001 From: rozetko Date: Mon, 6 Feb 2023 17:26:55 +0300 Subject: [PATCH 3/5] download csv with a proper filename && replace alert-errors with warnings --- .../components/Panel.tsx | 10 +++++----- .../corpglory-dataexporter-panel/types.ts | 1 + src/services/api_service.ts | 20 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx index 581ffdc..f79dd14 100644 --- a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx +++ b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx @@ -398,7 +398,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { links: [ { targetBlank: false, - title: 'Download', + title: 'Delete', url: '#', onClick: (event: DataLinkClickEvent) => onDeleteClick(event), }, @@ -426,7 +426,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { const sortedTasks = _.orderBy(tasks, (task) => task.progress?.time, 'desc'); const taskToDelete = sortedTasks[rowIndex]; if (taskToDelete.progress?.status === ExportStatus.EXPORTING || taskToDelete.id === taskIdBeingDownloaded) { - appEvents.emit(AppEvents.alertError, ['Data Exporter', 'Active task can`t be deleted']); + appEvents.emit(AppEvents.alertWarning, ['Data Exporter', 'Active task can`t be deleted']); return; } await deleteTask(taskToDelete?.id); @@ -440,15 +440,15 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { const sortedTasks = _.orderBy(tasks, (task) => task.progress?.time, 'desc'); const task = sortedTasks[rowIndex]; if (task.progress?.status === ExportStatus.EXPORTING || task.id === taskIdBeingDownloaded) { - appEvents.emit(AppEvents.alertError, ['Data Exporter', 'Active task can`t be downloaded']); + appEvents.emit(AppEvents.alertWarning, ['Data Exporter', 'Active task can`t be downloaded']); return; } if (task.progress?.status === ExportStatus.ERROR) { - appEvents.emit(AppEvents.alertError, ['Data Exporter', 'Failed task can`t be downloaded']); + appEvents.emit(AppEvents.alertWarning, ['Data Exporter', 'Failed task can`t be downloaded']); return; } setTaskIdBeingDownloaded(task.id as string); - await getStaticFile(task?.id); + await getStaticFile(task?.filename); setTaskIdBeingDownloaded(null); } diff --git a/src/panels/corpglory-dataexporter-panel/types.ts b/src/panels/corpglory-dataexporter-panel/types.ts index 9c510c1..e47e047 100644 --- a/src/panels/corpglory-dataexporter-panel/types.ts +++ b/src/panels/corpglory-dataexporter-panel/types.ts @@ -43,6 +43,7 @@ export type ExportTask = { csvDelimiter: string; progress?: ExportProgress; id?: string; + filename?: string; }; export type DashboardQuery = { diff --git a/src/services/api_service.ts b/src/services/api_service.ts index ce0ee36..e871060 100644 --- a/src/services/api_service.ts +++ b/src/services/api_service.ts @@ -2,6 +2,8 @@ import { ExportTask } from '../panels/corpglory-dataexporter-panel/types'; import axios from 'axios'; import * as _ from 'lodash'; +import appEvents from 'grafana/app/core/app_events'; +import { AppEvents } from '@grafana/data'; export const API_HOST = `${window.location.protocol}//${window.location.host}/`; export const API_PROXY_PREFIX = 'api/plugin-proxy/corpglory-dataexporter-app'; @@ -55,24 +57,20 @@ export async function deleteTask(taskId?: string): Promise { await queryApi('/task', { method: 'DELETE', data: { taskId } }); } -export async function getStaticFile(taskId?: string): Promise { - if (_.isEmpty(taskId)) { - console.warn(`can't download file without taskId`); +export async function getStaticFile(filename?: string): Promise { + if (_.isEmpty(filename)) { + appEvents.emit(AppEvents.alertWarning, ['Data Exporter', 'Can`t download a file without filename']); + console.warn(`can't download file without filename`); return; } - const respData = await queryApi(`/static/${taskId}.csv`, {}); - // TODO: check if resp exists - // create file link in browser's memory - const href = URL.createObjectURL(new Blob([respData], { type: 'text/csv' })); // create "a" HTML element with href to file & click const link = document.createElement('a'); - link.href = href; - link.setAttribute('download', `${taskId}.csv`); + link.href = `${API_PROXY_PREFIX}${API_PATH_PREFIX}/static/${filename}.csv`; + link.target = '_blank'; + link.download = `${filename}.csv`; document.body.appendChild(link); link.click(); - // clean up "a" element & remove ObjectURL document.body.removeChild(link); - URL.revokeObjectURL(href); } From 15e027102152ab01035828689646cc374d225a5c Mon Sep 17 00:00:00 2001 From: rozetko Date: Mon, 6 Feb 2023 17:27:06 +0300 Subject: [PATCH 4/5] 1.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf8fb1f..fadda62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "corpglory-dataexporter-app", - "version": "1.0.4", + "version": "1.0.5", "description": "", "scripts": { "lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --max-warnings=0 ./src", From 3f0f1f99cb1be91568ee4a4bcdb88a382a93ae12 Mon Sep 17 00:00:00 2001 From: rozetko Date: Mon, 6 Feb 2023 17:29:14 +0300 Subject: [PATCH 5/5] hotfix --- src/services/api_service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/services/api_service.ts b/src/services/api_service.ts index e871060..8c0242c 100644 --- a/src/services/api_service.ts +++ b/src/services/api_service.ts @@ -1,10 +1,11 @@ import { ExportTask } from '../panels/corpglory-dataexporter-panel/types'; -import axios from 'axios'; -import * as _ from 'lodash'; import appEvents from 'grafana/app/core/app_events'; import { AppEvents } from '@grafana/data'; +import axios from 'axios'; +import * as _ from 'lodash'; + export const API_HOST = `${window.location.protocol}//${window.location.host}/`; export const API_PROXY_PREFIX = 'api/plugin-proxy/corpglory-dataexporter-app'; export const API_PATH_PREFIX = '/api';