Dashboard: Make dashboard scene serializer public (#102384)

Make dashboard scene seralizer public
pull/102403/head
Alexa V 9 months ago committed by GitHub
parent a8a88f858a
commit defa03b155
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 36
      public/app/features/dashboard-scene/scene/DashboardScene.tsx
  2. 2
      public/app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2.ts
  3. 2
      public/app/features/dashboard-scene/utils/dashboardSceneGraph.ts

@ -169,7 +169,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
protected _renderBeforeActivation = true; protected _renderBeforeActivation = true;
private _serializer: DashboardSceneSerializerLike< public serializer: DashboardSceneSerializerLike<
Dashboard | DashboardV2Spec, Dashboard | DashboardV2Spec,
DashboardMeta | DashboardWithAccessInfo<DashboardV2Spec>['metadata'] DashboardMeta | DashboardWithAccessInfo<DashboardV2Spec>['metadata']
>; >;
@ -187,7 +187,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
scopesBridge: config.featureToggles.scopeFilters ? new SceneScopesBridge({}) : undefined, scopesBridge: config.featureToggles.scopeFilters ? new SceneScopesBridge({}) : undefined,
}); });
this._serializer = this.serializer =
serializerVersion === 'v2' ? getDashboardSceneSerializer('v2') : getDashboardSceneSerializer('v1'); serializerVersion === 'v2' ? getDashboardSceneSerializer('v2') : getDashboardSceneSerializer('v1');
this._changeTracker = new DashboardSceneChangeTracker(this); this._changeTracker = new DashboardSceneChangeTracker(this);
@ -272,7 +272,7 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
}; };
public saveCompleted(saveModel: Dashboard | DashboardV2Spec, result: SaveDashboardResponseDTO, folderUid?: string) { public saveCompleted(saveModel: Dashboard | DashboardV2Spec, result: SaveDashboardResponseDTO, folderUid?: string) {
this._serializer.onSaveComplete(saveModel, result); this.serializer.onSaveComplete(saveModel, result);
this._changeTracker.stopTrackingChanges(); this._changeTracker.stopTrackingChanges();
@ -662,11 +662,11 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
} }
public getInitialSaveModel() { public getInitialSaveModel() {
return this._serializer.initialSaveModel; return this.serializer.initialSaveModel;
} }
public getSnapshotUrl = () => { public getSnapshotUrl = () => {
return this._serializer.getSnapshotUrl(); return this.serializer.getSnapshotUrl();
}; };
/** Hacky temp function until we refactor transformSaveModelToScene a bit */ /** Hacky temp function until we refactor transformSaveModelToScene a bit */
@ -676,26 +676,14 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
saveModel?: Dashboard | DashboardV2Spec, saveModel?: Dashboard | DashboardV2Spec,
meta?: DashboardMeta | DashboardWithAccessInfo<DashboardV2Spec>['metadata'] meta?: DashboardMeta | DashboardWithAccessInfo<DashboardV2Spec>['metadata']
): void { ): void {
this._serializer.initializeMapping(saveModel); this.serializer.initializeMapping(saveModel);
const sortedModel = sortedDeepCloneWithoutNulls(saveModel); const sortedModel = sortedDeepCloneWithoutNulls(saveModel);
this._serializer.initialSaveModel = sortedModel; this.serializer.initialSaveModel = sortedModel;
this._serializer.metadata = meta; this.serializer.metadata = meta;
} }
public getTrackingInformation() { public getTrackingInformation() {
return this._serializer.getTrackingInformation(this); return this.serializer.getTrackingInformation(this);
}
public getPanelIdForElement(elementId: string) {
return this._serializer.getPanelIdForElement(elementId);
}
public getElementPanelMapping() {
return this._serializer.getElementPanelMapping();
}
public getElementIdentifierForPanel(panelId: number) {
return this._serializer.getElementIdForPanel(panelId);
} }
public async onDashboardDelete() { public async onDashboardDelete() {
@ -740,15 +728,15 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> impleme
} }
getSaveModel(): Dashboard | DashboardV2Spec { getSaveModel(): Dashboard | DashboardV2Spec {
return this._serializer.getSaveModel(this); return this.serializer.getSaveModel(this);
} }
getSaveAsModel(options: SaveDashboardAsOptions): Dashboard | DashboardV2Spec { getSaveAsModel(options: SaveDashboardAsOptions): Dashboard | DashboardV2Spec {
return this._serializer.getSaveAsModel(this, options); return this.serializer.getSaveAsModel(this, options);
} }
getDashboardChanges(saveTimeRange?: boolean, saveVariables?: boolean, saveRefresh?: boolean): DashboardChangeInfo { getDashboardChanges(saveTimeRange?: boolean, saveVariables?: boolean, saveRefresh?: boolean): DashboardChangeInfo {
return this._serializer.getDashboardChangesFromScene(this, { saveTimeRange, saveVariables, saveRefresh }); return this.serializer.getDashboardChangesFromScene(this, { saveTimeRange, saveVariables, saveRefresh });
} }
getManagerKind(): ManagerKind | undefined { getManagerKind(): ManagerKind | undefined {

@ -341,7 +341,7 @@ function getVizPanelQueryOptions(vizPanel: VizPanel): QueryOptionsSpec {
function createElements(panels: Element[], scene: DashboardScene): Record<string, Element> { function createElements(panels: Element[], scene: DashboardScene): Record<string, Element> {
return panels.reduce<Record<string, Element>>((elements, panel) => { return panels.reduce<Record<string, Element>>((elements, panel) => {
let elementKey = scene.getElementIdentifierForPanel(panel.spec.id); let elementKey = scene.serializer.getElementIdForPanel(panel.spec.id);
elements[elementKey!] = panel; elements[elementKey!] = panel;
return elements; return elements;
}, {}); }, {});

@ -83,7 +83,7 @@ export function getCursorSync(scene: DashboardScene) {
export function getElementIdentifierForVizPanel(vizPanel: VizPanel): string { export function getElementIdentifierForVizPanel(vizPanel: VizPanel): string {
const scene = getDashboardSceneFor(vizPanel); const scene = getDashboardSceneFor(vizPanel);
const panelId = getPanelIdForVizPanel(vizPanel); const panelId = getPanelIdForVizPanel(vizPanel);
let elementKey = scene.getElementIdentifierForPanel(panelId); let elementKey = scene.serializer.getElementIdForPanel(panelId);
if (!elementKey) { if (!elementKey) {
// assign a panel-id key // assign a panel-id key

Loading…
Cancel
Save