Add dashbaord version to scene metadata
This commit is contained in:
@@ -8,7 +8,7 @@ import { Prompt } from 'app/core/components/FormPrompt/Prompt';
|
|||||||
import { contextSrv } from 'app/core/services/context_srv';
|
import { contextSrv } from 'app/core/services/context_srv';
|
||||||
|
|
||||||
import { SaveLibraryVizPanelModal } from '../panel-edit/SaveLibraryVizPanelModal';
|
import { SaveLibraryVizPanelModal } from '../panel-edit/SaveLibraryVizPanelModal';
|
||||||
import { DashboardScene, isV2Dashboard } from '../scene/DashboardScene';
|
import { DashboardScene } from '../scene/DashboardScene';
|
||||||
import { getLibraryPanelBehavior, isLibraryPanel } from '../utils/utils';
|
import { getLibraryPanelBehavior, isLibraryPanel } from '../utils/utils';
|
||||||
|
|
||||||
interface DashboardPromptProps {
|
interface DashboardPromptProps {
|
||||||
@@ -155,16 +155,12 @@ const getStyles = () => ({
|
|||||||
export function ignoreChanges(scene: DashboardScene | null) {
|
export function ignoreChanges(scene: DashboardScene | null) {
|
||||||
const original = scene?.getInitialSaveModel();
|
const original = scene?.getInitialSaveModel();
|
||||||
|
|
||||||
if (original && isV2Dashboard(original)) {
|
|
||||||
throw new Error('isV2Dashboard is not implemented');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!original) {
|
if (!original) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore changes if original is unsaved
|
// Ignore changes if original is unsaved
|
||||||
if (original.version === 0) {
|
if (scene?.state.meta.version === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ describe('DashboardScene', () => {
|
|||||||
expect(scene.state.isDirty).toBe(false);
|
expect(scene.state.isDirty).toBe(false);
|
||||||
scene.exitEditMode({ skipConfirm: true });
|
scene.exitEditMode({ skipConfirm: true });
|
||||||
expect(scene.state.title).toEqual('Updated title');
|
expect(scene.state.title).toEqual('Updated title');
|
||||||
|
expect(scene.state.meta.version).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should start the detect changes worker', () => {
|
it('Should start the detect changes worker', () => {
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
|||||||
slug: result.slug,
|
slug: result.slug,
|
||||||
folderUid: folderUid,
|
folderUid: folderUid,
|
||||||
isNew: false,
|
isNew: false,
|
||||||
|
version: result.version,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -120,7 +120,9 @@ export function transformSaveModelSchemaV2ToScene(dto: DashboardWithAccessInfo<D
|
|||||||
isDirty: false,
|
isDirty: false,
|
||||||
links: dashboard.links,
|
links: dashboard.links,
|
||||||
// TODO: Combine access and metadata to compose the V1 meta object
|
// TODO: Combine access and metadata to compose the V1 meta object
|
||||||
meta: {},
|
meta: {
|
||||||
|
version: parseInt(metadata.resourceVersion, 10),
|
||||||
|
},
|
||||||
tags: dashboard.tags,
|
tags: dashboard.tags,
|
||||||
title: dashboard.title,
|
title: dashboard.title,
|
||||||
uid: metadata.name,
|
uid: metadata.name,
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export function ensureV1Response(
|
|||||||
isFolder: false,
|
isFolder: false,
|
||||||
uid: dashboard.metadata.name,
|
uid: dashboard.metadata.name,
|
||||||
k8s: dashboard.metadata,
|
k8s: dashboard.metadata,
|
||||||
|
version: parseInt(dashboard.metadata.resourceVersion, 10),
|
||||||
},
|
},
|
||||||
dashboard: spec,
|
dashboard: spec,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO> {
|
|||||||
isFolder: false,
|
isFolder: false,
|
||||||
uid: dash.metadata.name,
|
uid: dash.metadata.name,
|
||||||
k8s: dash.metadata,
|
k8s: dash.metadata,
|
||||||
|
version: parseInt(dash.metadata.resourceVersion, 10),
|
||||||
},
|
},
|
||||||
dashboard: dash.spec,
|
dashboard: dash.spec,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ export interface DashboardMeta {
|
|||||||
dashboardNotFound?: boolean;
|
dashboardNotFound?: boolean;
|
||||||
isEmbedded?: boolean;
|
isEmbedded?: boolean;
|
||||||
isNew?: boolean;
|
isNew?: boolean;
|
||||||
|
version?: number;
|
||||||
|
|
||||||
// When loaded from kubernetes, we stick the raw metadata here
|
// When loaded from kubernetes, we stick the raw metadata here
|
||||||
// yes weird, but this means all the editor structures can exist unchanged
|
// yes weird, but this means all the editor structures can exist unchanged
|
||||||
|
|||||||
Reference in New Issue
Block a user