From 38ec4c0a09803964d67e5aa52079041204f08e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 18 Jul 2022 17:24:21 +0200 Subject: [PATCH] UnsavedChanges: Should not be triggered when only going into panel edit without changing anything (#52363) --- .../PanelEditor/state/actions.test.ts | 29 +++++++++++++++++++ .../components/PanelEditor/state/actions.ts | 2 +- 2 files changed, 30 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 b52df7d3ae9..6ea4ca3ff9f 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts @@ -134,6 +134,35 @@ describe('panelEditor actions', () => { expect(dispatchedActions.length).toBe(2); expect(sourcePanel.getOptions()).toEqual({}); }); + + 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({}); + + const dashboard = new DashboardModel({ + panels: [{ id: 12, type: 'graph' }], + }); + + const panel = dashboard.initEditPanel(sourcePanel); + + const state: PanelEditorState = { + ...initialState(), + getPanel: () => panel, + getSourcePanel: () => sourcePanel, + }; + + await thunkTester({ + panelEditor: state, + panels: {}, + dashboard: { + getModel: () => dashboard, + }, + }) + .givenThunk(exitPanelEditor) + .whenThunkIsDispatched(); + + expect(sourcePanel.configRev).toEqual(0); + }); }); 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 a2c037843eb..fca553ea7da 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.ts @@ -116,7 +116,7 @@ export function exitPanelEditor(): ThunkResult { dashboard.exitPanelEditor(); } - if (!shouldDiscardChanges) { + if (panel.hasChanged && !shouldDiscardChanges) { const modifiedSaveModel = panel.getSaveModel(); const sourcePanel = getSourcePanel(); const panelTypeChanged = sourcePanel.type !== panel.type;