Browse Source

bind tasks to a dashboard

pull/13/head
rozetko 2 years 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, Dashboard,
} from '../types'; } 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 { 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'; import { deleteTask, getStaticFile, getTasks, queryApi } from '../../../services/api_service';
@ -83,7 +83,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
useEffect(() => { useEffect(() => {
async function getCurrentDashboard(): Promise<any> { async function getCurrentDashboard(): Promise<any> {
const currentDashboardUid = getDashboardUid(window.location.toString()); const currentDashboardUid = getCurrentDashboardUid();
return getDashboardByUid(currentDashboardUid); return getDashboardByUid(currentDashboardUid);
} }
@ -145,7 +145,9 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
} }
function fetchTasks(): void { function fetchTasks(): void {
getTasks() const dashboardUid = getCurrentDashboardUid();
getTasks(dashboardUid)
.then((tasks) => { .then((tasks) => {
setTasks(tasks); setTasks(tasks);
setPanelStatusWithValidate(PanelStatus.OK); 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 selectedQueries = _.filter(queries, (query: DashboardQuery) => query.selected);
const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()]; const timerange: [number, number] = [selectedTimeRange.from.unix(), selectedTimeRange.to.unix()];
const dashboardUid = getCurrentDashboardUid();
const task: ExportTask = { const task: ExportTask = {
dashboardUid,
// @ts-ignore // @ts-ignore
username: contextSrv.user.name, username: contextSrv.user.name,
timeRange: { timeRange: {

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

@ -33,6 +33,7 @@ export type ExportProgress = {
}; };
export type ExportTask = { export type ExportTask = {
dashboardUid: string;
username: string; username: string;
queries: DashboardQuery[]; queries: DashboardQuery[];
timeRange: { 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; return response.data as RT;
}; };
export async function getTasks(): Promise<ExportTask[]> { export async function getTasks(dashboardUid: string): Promise<ExportTask[]> {
return queryApi<ExportTask[]>('/task', {}); return queryApi<ExportTask[]>('/task', { params: { dashboardUid } });
} }
export async function deleteTask(taskId?: string): Promise<void> { 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]); 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\/([^/]+)/); const matches = new URL(url).pathname.match(/\/d\/([^/]+)/);
if (!matches) { 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 { } else {
return matches[1]; return matches[1];
} }

Loading…
Cancel
Save