Files
grafana/public/app/features/dashboard/components/VersionHistory/HistorySrv.ts
Jack Westbrook c0dd1b6d11 Dashboard: migrate version history list (#29970)
* refactor(dashboard): remove redundant directive code from SaveDashboardAsButton

* feat(dashboard): initial commit of rendering version history with react

* feat(dashboard): append versions, use historySrv, UI as functional components

* feat(dashboard): initial commit of versions settings diff view

* refactor(historylist): remove code related to listing versions

* refactor(dashboard): use angular directive to render version comparison

* refactor(dashboard): clean up versions settings

* refactor(dashboard): move version history UI components into own files

* refactor(dashboard): update typings for version history react components

* feat(dashboard): initial commit of react revert dashboard modal

* test(dashboardsettings): clean up historylistctrl tests

* chore(dashboardsettings): remove unused state variable

* test(dashboardsettings): initial commit of VersionSettings component tests

* feat(grafana-ui): add className concatenation on Checkbox label

* Apply suggestions from code review

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>

* test(dashboardsettings): add more tests for Versions Settings react component

* test(dashboardsettings): add test to assert latest badge in Version history table

* fix(dashboardsettings): pass string to getDiff instead of react event object

* test(dashboardsettings): remove failing test from versions settings

* Moved scroll area to content, and fixed colors

* Update public/app/features/dashboard/components/DashboardSettings/VersionsSettings.test.tsx

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>

* style(dashboardsettings): add new lines to versions settings tests

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
2021-01-19 13:19:01 +01:00

56 lines
1.5 KiB
TypeScript

import _ from 'lodash';
import coreModule from 'app/core/core_module';
import { DashboardModel } from '../../state/DashboardModel';
import { getBackendSrv } from '@grafana/runtime';
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 CalculateDiffOptions {
new: DiffTarget;
base: DiffTarget;
diffType: 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([]);
}
calculateDiff(options: CalculateDiffOptions) {
return getBackendSrv().post('api/dashboards/calculate-diff', options);
}
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 };
coreModule.service('historySrv', HistorySrv);