diff --git a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx index 9d85bee..82488a1 100644 --- a/src/panels/corpglory-dataexporter-panel/components/Panel.tsx +++ b/src/panels/corpglory-dataexporter-panel/components/Panel.tsx @@ -8,7 +8,7 @@ import { Dashboard, } from '../types'; -import { convertTimestampToDate, convertTimeZoneTypeToName, getDashboardUid } from '../../../utils'; +import { convertTimestampToDate, convertTimeZoneTypeToName, getCurrentDashboardUid } from '../../../utils'; import { CLOSE_ICON_BASE_64, DOWNLOAD_ICON_BASE_64, SELECT_ICON_BASE_64, UNSELECT_ICON_BASE_64 } from '../../../icons'; import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service'; @@ -83,7 +83,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { useEffect(() => { async function getCurrentDashboard(): Promise { - const currentDashboardUid = getDashboardUid(window.location.toString()); + const currentDashboardUid = getCurrentDashboardUid(); return getDashboardByUid(currentDashboardUid); } @@ -145,7 +145,9 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { } function fetchTasks(): void { - getTasks() + const dashboardUid = getCurrentDashboardUid(); + + getTasks(dashboardUid) .then((tasks) => { setTasks(tasks); setPanelStatusWithValidate(PanelStatus.OK); @@ -187,7 +189,10 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) { const selectedQueries = _.filter(queries, (query: DashboardQuery) => query.selected); const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()]; + const dashboardUid = getCurrentDashboardUid(); + const task: ExportTask = { + dashboardUid, // @ts-ignore username: contextSrv.user.name, timeRange: { diff --git a/src/panels/corpglory-dataexporter-panel/types.ts b/src/panels/corpglory-dataexporter-panel/types.ts index f369b40..5d10ebc 100644 --- a/src/panels/corpglory-dataexporter-panel/types.ts +++ b/src/panels/corpglory-dataexporter-panel/types.ts @@ -33,6 +33,7 @@ export type ExportProgress = { }; export type ExportTask = { + dashboardUid: string; username: string; queries: DashboardQuery[]; timeRange: { diff --git a/src/services/api_service.ts b/src/services/api_service.ts index d12acd0..ce0ee36 100644 --- a/src/services/api_service.ts +++ b/src/services/api_service.ts @@ -43,8 +43,8 @@ export const queryApi = async (path: string, config: RequestConfig) => return response.data as RT; }; -export async function getTasks(): Promise { - return queryApi('/task', {}); +export async function getTasks(dashboardUid: string): Promise { + return queryApi('/task', { params: { dashboardUid } }); } export async function deleteTask(taskId?: string): Promise { diff --git a/src/utils/index.ts b/src/utils/index.ts index 07acebd..cfa615f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -6,10 +6,12 @@ export function openNotification(message: React.ReactNode) { appEvents.emit(AppEvents.alertSuccess, [message]); } -export function getDashboardUid(url: string): string { +export function getCurrentDashboardUid(): string { + const url = window.location.toString(); + const matches = new URL(url).pathname.match(/\/d\/([^/]+)/); if (!matches) { - throw new Error(`Couldn't parse uid from ${url}`); + throw new Error(`Can't get current dashboard uid. If it's a new dashboard, please save it first.`); } else { return matches[1]; }