diff --git a/public/app/features/dashboard/api/legacy.ts b/public/app/features/dashboard/api/legacy.ts index 34a40225e32..32a2ee8c69c 100644 --- a/public/app/features/dashboard/api/legacy.ts +++ b/public/app/features/dashboard/api/legacy.ts @@ -12,6 +12,22 @@ import { SaveDashboardCommand } from '../components/SaveDashboard/types'; import { DashboardAPI, ListDeletedDashboardsOptions } from './types'; +interface HistoryResult { + continueToken?: string; + versions: RevisionsModel[]; +} +interface RevisionsModel { + id: number; + checked: boolean; + uid: string; + parentVersion: number; + version: number; + created: Date; + createdBy: string; + message: string; + data: Dashboard; +} + export class LegacyDashboardAPI implements DashboardAPI { constructor() {} @@ -53,6 +69,30 @@ export class LegacyDashboardAPI implements DashboardAPI return result; } + async listDashboardHistory(uid: string): Promise> { + const result = await getBackendSrv().get(`/api/dashboards/uid/${uid}/versions`); + return { + apiVersion: 'v0alpha1', + kind: 'DashboardList', + metadata: { resourceVersion: '0' }, + items: result.versions.map((v) => ({ + apiVersion: 'v0alpha1', + kind: 'Dashboard', + metadata: { + name: v.uid, + resourceVersion: v.version.toString(), + generation: v.version, + creationTimestamp: v.created ? v.created.toISOString() : new Date().toISOString(), + annotations: { + 'grafana.app/updatedBy': v.createdBy, + 'grafana.app/message': v.message, + }, + }, + spec: v.data, + })), + }; + } + /** * No-op for legacy API */ diff --git a/public/app/features/dashboard/api/types.ts b/public/app/features/dashboard/api/types.ts index 950ace6061c..e253fd4bf4c 100644 --- a/public/app/features/dashboard/api/types.ts +++ b/public/app/features/dashboard/api/types.ts @@ -15,6 +15,8 @@ export interface DashboardAPI { saveDashboard(options: SaveDashboardCommand): Promise; /** Delete a dashboard */ deleteDashboard(uid: string, showSuccessAlert: boolean): Promise; + /** List all versions of a dashboard */ + listDashboardHistory(uid: string): Promise>; /** List all deleted dashboards */ listDeletedDashboards(options: ListDeletedDashboardsOptions): Promise>; /** Restore a deleted dashboard by re-creating it */ diff --git a/public/app/features/dashboard/api/v1.ts b/public/app/features/dashboard/api/v1.ts index c69093258cb..aba4042bfca 100644 --- a/public/app/features/dashboard/api/v1.ts +++ b/public/app/features/dashboard/api/v1.ts @@ -206,6 +206,13 @@ export class K8sDashboardAPI implements DashboardAPI { } } + async listDashboardHistory(uid: string) { + return await this.client.list({ + labelSelector: 'grafana.app/get-history=true', + fieldSelector: `metadata.name=${uid}`, + }); + } + async listDeletedDashboards(options: ListDeletedDashboardsOptions) { return await this.client.list({ ...options, labelSelector: 'grafana.app/get-trash=true' }); } diff --git a/public/app/features/dashboard/api/v2.ts b/public/app/features/dashboard/api/v2.ts index 35c5e1a7a0d..834faf8d152 100644 --- a/public/app/features/dashboard/api/v2.ts +++ b/public/app/features/dashboard/api/v2.ts @@ -181,6 +181,13 @@ export class K8sDashboardV2API }; } + async listDashboardHistory(uid: string) { + return await this.client.list({ + labelSelector: 'grafana.app/get-history=true', + fieldSelector: `metadata.name=${uid}`, + }); + } + listDeletedDashboards(options: ListDeletedDashboardsOptions) { return this.client.list({ ...options, labelSelector: 'grafana.app/get-trash=true' }); }