History: list, compare and restore versions using UID (#51989)

This commit is contained in:
Ivan Ortega Alba 2022-07-21 11:52:36 +02:00 committed by GitHub
parent 0af09b8c57
commit 3fbec39952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 12 deletions

View File

@ -83,8 +83,8 @@ export class VersionsSettings extends PureComponent<Props, State> {
isLoading: true,
});
const lhs = await historySrv.getDashboardVersion(this.props.dashboard.id, baseInfo.version);
const rhs = await historySrv.getDashboardVersion(this.props.dashboard.id, newInfo.version);
const lhs = await historySrv.getDashboardVersion(this.props.dashboard.uid, baseInfo.version);
const rhs = await historySrv.getDashboardVersion(this.props.dashboard.uid, newInfo.version);
this.setState({
baseInfo,

View File

@ -2,6 +2,7 @@ export const versions = [
{
id: 249,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 10,
restoredFrom: 0,
version: 11,
@ -12,6 +13,7 @@ export const versions = [
{
id: 247,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 9,
restoredFrom: 0,
version: 10,
@ -22,6 +24,7 @@ export const versions = [
{
id: 246,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 8,
restoredFrom: 0,
version: 9,
@ -32,6 +35,7 @@ export const versions = [
{
id: 245,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 7,
restoredFrom: 0,
version: 8,
@ -42,6 +46,7 @@ export const versions = [
{
id: 239,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 6,
restoredFrom: 0,
version: 7,
@ -52,6 +57,7 @@ export const versions = [
{
id: 237,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 5,
restoredFrom: 0,
version: 6,
@ -62,6 +68,7 @@ export const versions = [
{
id: 236,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 4,
restoredFrom: 0,
version: 5,
@ -72,6 +79,7 @@ export const versions = [
{
id: 218,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 3,
restoredFrom: 0,
version: 4,
@ -82,6 +90,7 @@ export const versions = [
{
id: 217,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 2,
restoredFrom: 0,
version: 3,
@ -92,6 +101,7 @@ export const versions = [
{
id: 216,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 1,
restoredFrom: 0,
version: 2,
@ -102,6 +112,7 @@ export const versions = [
{
id: 215,
dashboardId: 74,
dashboardUID: '_U4zObQMz',
parentVersion: 1,
restoredFrom: 0,
version: 1,

View File

@ -25,7 +25,7 @@ describe('historySrv', () => {
let historySrv = new HistorySrv();
const dash = new DashboardModel({ id: 1 });
const dash = new DashboardModel({ uid: '_U4zObQMz' });
const emptyDash = new DashboardModel({});
const historyListOpts = { limit: 10, start: 0 };

View File

@ -12,7 +12,7 @@ export interface HistoryListOpts {
export interface RevisionsModel {
id: number;
checked: boolean;
dashboardId: number;
dashboardUID: string;
parentVersion: number;
version: number;
created: Date;
@ -21,26 +21,26 @@ export interface RevisionsModel {
}
export interface DiffTarget {
dashboardId: number;
dashboardUID: string;
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([]);
const uid = dashboard && dashboard.uid ? dashboard.uid : void 0;
return uid ? getBackendSrv().get(`api/dashboards/uid/${uid}/versions`, options) : Promise.resolve([]);
}
getDashboardVersion(id: number, version: number) {
return getBackendSrv().get(`api/dashboards/id/${id}/versions/${version}`);
getDashboardVersion(uid: string, version: number) {
return getBackendSrv().get(`api/dashboards/uid/${uid}/versions/${version}`);
}
restoreDashboard(dashboard: DashboardModel, version: number) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
const url = `api/dashboards/id/${id}/restore`;
const uid = dashboard && dashboard.uid ? dashboard.uid : void 0;
const url = `api/dashboards/uid/${uid}/restore`;
return id && isNumber(version) ? getBackendSrv().post(url, { version }) : Promise.resolve({});
return uid && isNumber(version) ? getBackendSrv().post(url, { version }) : Promise.resolve({});
}
}

View File

@ -3,6 +3,7 @@ export function versions() {
{
id: 4,
dashboardId: 1,
dashboardUID: '_U4zObQMz',
parentVersion: 3,
restoredFrom: 0,
version: 4,
@ -13,6 +14,7 @@ export function versions() {
{
id: 3,
dashboardId: 1,
dashboardUID: '_U4zObQMz',
parentVersion: 1,
restoredFrom: 1,
version: 3,
@ -23,6 +25,7 @@ export function versions() {
{
id: 2,
dashboardId: 1,
dashboardUID: '_U4zObQMz',
parentVersion: 0,
restoredFrom: -1,
version: 2,
@ -33,6 +36,7 @@ export function versions() {
{
id: 1,
dashboardId: 1,
dashboardUID: '_U4zObQMz',
parentVersion: 0,
restoredFrom: -1,
slug: 'history-dashboard',
@ -73,6 +77,7 @@ export function restore(version: any, restoredFrom?: any): any {
gnetId: null,
graphTooltip: 0,
id: 1,
uid: '_U4zObQMz',
links: [],
restoredFrom: restoredFrom,
rows: [