Browse Source

bind tasks to a dashboard

pull/13/head
rozetko 1 year ago
parent
commit
57b80672fb
  1. 11
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx
  2. 1
      src/panels/corpglory-dataexporter-panel/types.ts
  3. 4
      src/services/api_service.ts
  4. 6
      src/utils/index.ts

11
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<any> {
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: {

1
src/panels/corpglory-dataexporter-panel/types.ts

@ -33,6 +33,7 @@ export type ExportProgress = {
};
export type ExportTask = {
dashboardUid: string;
username: string;
queries: DashboardQuery[];
timeRange: {

4
src/services/api_service.ts

@ -43,8 +43,8 @@ export const queryApi = async <RT = any>(path: string, config: RequestConfig) =>
return response.data as RT;
};
export async function getTasks(): Promise<ExportTask[]> {
return queryApi<ExportTask[]>('/task', {});
export async function getTasks(dashboardUid: string): Promise<ExportTask[]> {
return queryApi<ExportTask[]>('/task', { params: { dashboardUid } });
}
export async function deleteTask(taskId?: string): Promise<void> {

6
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];
}

Loading…
Cancel
Save