grafana/public/app/features/dashboard/components/VersionHistory/HistorySrv.ts
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

49 lines
1.3 KiB
TypeScript

import { isNumber } from 'lodash';
import { getBackendSrv } from '@grafana/runtime';
import { DashboardModel } from '../../state/DashboardModel';
export interface HistoryListOpts {
limit: number;
start: number;
}
export interface RevisionsModel {
id: number;
checked: boolean;
dashboardId: number;
parentVersion: number;
version: number;
created: Date;
createdBy: string;
message: string;
}
export interface DiffTarget {
dashboardId: number;
version: number;
unsavedDashboard?: DashboardModel; // when doing diffs against unsaved dashboard version
}
export class HistorySrv {
getHistoryList(dashboard: DashboardModel, options: HistoryListOpts) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
return id ? getBackendSrv().get(`api/dashboards/id/${id}/versions`, options) : Promise.resolve([]);
}
getDashboardVersion(id: number, version: number) {
return getBackendSrv().get(`api/dashboards/id/${id}/versions/${version}`);
}
restoreDashboard(dashboard: DashboardModel, version: number) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
const url = `api/dashboards/id/${id}/restore`;
return id && isNumber(version) ? getBackendSrv().post(url, { version }) : Promise.resolve({});
}
}
const historySrv = new HistorySrv();
export { historySrv };