add history
This commit is contained in:
@@ -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<DashboardDTO, Dashboard> {
|
||||
constructor() {}
|
||||
|
||||
@@ -53,6 +69,30 @@ export class LegacyDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard>
|
||||
return result;
|
||||
}
|
||||
|
||||
async listDashboardHistory(uid: string): Promise<ResourceList<Dashboard, Dashboard, string>> {
|
||||
const result = await getBackendSrv().get<HistoryResult>(`/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
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,8 @@ export interface DashboardAPI<G, T> {
|
||||
saveDashboard(options: SaveDashboardCommand<T>): Promise<SaveDashboardResponseDTO>;
|
||||
/** Delete a dashboard */
|
||||
deleteDashboard(uid: string, showSuccessAlert: boolean): Promise<DeleteDashboardResponse>;
|
||||
/** List all versions of a dashboard */
|
||||
listDashboardHistory(uid: string): Promise<ResourceList<T>>;
|
||||
/** List all deleted dashboards */
|
||||
listDeletedDashboards(options: ListDeletedDashboardsOptions): Promise<ResourceList<T>>;
|
||||
/** Restore a deleted dashboard by re-creating it */
|
||||
|
||||
@@ -206,6 +206,13 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard> {
|
||||
}
|
||||
}
|
||||
|
||||
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' });
|
||||
}
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user