From 169eeb4ee2d2dc0d9be01662c5a95c5fb0d0bf80 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Wed, 24 Aug 2022 09:17:36 +0200 Subject: [PATCH] AngularPanels: Fixing changing angular panel options not taking having affect when coming back from panel edit (#54087) (#54132) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 8880cbd7f68e6df7a23363798b3f9be66597c89d) Co-authored-by: Torkel Ödegaard --- .../PanelEditor/state/actions.test.ts | 36 +++++++++++++++++++ .../components/PanelEditor/state/actions.ts | 5 ++- .../features/dashboard/state/PanelModel.ts | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts index 6ea4ca3ff9f..64881c59fa4 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts @@ -138,6 +138,7 @@ describe('panelEditor actions', () => { it('should not increment configRev when no changes made and leaving panel edit', async () => { const sourcePanel = new PanelModel({ id: 12, type: 'graph' }); sourcePanel.plugin = getPanelPlugin({}); + sourcePanel.plugin.angularPanelCtrl = undefined; const dashboard = new DashboardModel({ panels: [{ id: 12, type: 'graph' }], @@ -163,6 +164,41 @@ describe('panelEditor actions', () => { expect(sourcePanel.configRev).toEqual(0); }); + + it('should apply changes when leaving panel edit with angular panel', async () => { + const sourcePanel = new PanelModel({ id: 12, type: 'graph' }); + sourcePanel.plugin = getPanelPlugin({}); + sourcePanel.plugin.angularPanelCtrl = {}; + + const dashboard = new DashboardModel({ + panels: [{ id: 12, type: 'graph' }], + }); + + const panel = dashboard.initEditPanel(sourcePanel); + + const state: PanelEditorState = { + ...initialState(), + getPanel: () => panel, + getSourcePanel: () => sourcePanel, + }; + + // not using panel.setProperty here to simulate any prop change done from angular + panel.title = 'Changed title'; + + await thunkTester({ + panelEditor: state, + panels: {}, + dashboard: { + getModel: () => dashboard, + }, + }) + .givenThunk(exitPanelEditor) + .whenThunkIsDispatched(); + + expect(sourcePanel.isAngularPlugin()).toBe(true); + expect(sourcePanel.title).toEqual('Changed title'); + expect(sourcePanel.configRev).toEqual(1); + }); }); describe('skipPanelUpdate', () => { diff --git a/public/app/features/dashboard/components/PanelEditor/state/actions.ts b/public/app/features/dashboard/components/PanelEditor/state/actions.ts index fca553ea7da..3290ce66189 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.ts @@ -116,7 +116,10 @@ export function exitPanelEditor(): ThunkResult { dashboard.exitPanelEditor(); } - if (panel.hasChanged && !shouldDiscardChanges) { + // For angular panels we always commit as panel.hasChanged will not have picked up changes done from angular + const commitChanges = !shouldDiscardChanges && (panel.hasChanged || panel.isAngularPlugin()); + + if (commitChanges) { const modifiedSaveModel = panel.getSaveModel(); const sourcePanel = getSourcePanel(); const panelTypeChanged = sourcePanel.type !== panel.type; diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index d5672ea97b1..b2d949cee4e 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -533,6 +533,7 @@ export class PanelModel implements DataConfigSource, IPanelModel { const clone = new PanelModel(sourceModel); clone.isEditing = true; + clone.plugin = this.plugin; const sourceQueryRunner = this.getQueryRunner();