From f478504bc9f8cdf84cb53f0cfd8d521b398aa7e7 Mon Sep 17 00:00:00 2001 From: Victor Colomb <51762123+VictorColomb@users.noreply.github.com> Date: Tue, 16 May 2023 13:44:19 +0200 Subject: [PATCH] Dashboard: Fix library panels in collapsed rows not getting updated (#66643) --- .../dashboard/state/PanelModel.test.ts | 21 +++++++++++++++++++ .../features/dashboard/state/PanelModel.ts | 20 ++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/public/app/features/dashboard/state/PanelModel.test.ts b/public/app/features/dashboard/state/PanelModel.test.ts index ba83da44802..d4c1ddac190 100644 --- a/public/app/features/dashboard/state/PanelModel.test.ts +++ b/public/app/features/dashboard/state/PanelModel.test.ts @@ -195,6 +195,27 @@ describe('PanelModel', () => { expect(saveModel.events).toBe(undefined); }); + it('getSaveModel should clean libraryPanels from a collapsed row', () => { + const newmodelJson = { + type: 'row', + panels: [ + { + ...modelJson, + libraryPanel: { + uid: 'BVIBScisnl', + model: modelJson, + name: 'Library panel title', + }, + }, + modelJson, + ], + }; + const newmodel = new PanelModel(newmodelJson); + const saveModel = newmodel.getSaveModel(); + expect(saveModel.panels[0].tagrets).toBe(undefined); + expect(saveModel.panels[1].targets).toBeTruthy(); + }); + describe('variables interpolation', () => { beforeEach(() => { model.scopedVars = { diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index dc582275148..fddf8a198a3 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -310,6 +310,26 @@ export class PanelModel implements DataConfigSource, IPanelModel { model[property] = cloneDeep(this[property]); } + // clean libraryPanel from collapsed rows + if (this.type === 'row' && this.panels && this.panels.length > 0) { + model.panels = this.panels.map((panel) => { + if (panel.libraryPanel) { + const { id, title, libraryPanel, gridPos } = panel; + return { + id, + title, + gridPos, + libraryPanel: { + uid: libraryPanel.uid, + name: libraryPanel.name, + }, + }; + } + + return panel; + }); + } + return model; }