From 9f4683b3d0254a983d856e28c2a5265b328966f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 20 Jul 2022 03:41:54 +0200 Subject: [PATCH] Dashboard: Fix iteration property change triggering unsaved changes warning (#51272) --- .../DashboardPrompt/DashboardPrompt.test.tsx | 6 ------ .../components/DashboardPrompt/DashboardPrompt.tsx | 3 --- .../app/features/dashboard/state/DashboardModel.ts | 14 +++++--------- public/app/features/dashboard/state/PanelModel.ts | 1 - 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx b/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx index 7beaa7a7d2a..34c97325d9b 100644 --- a/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx +++ b/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.test.tsx @@ -60,12 +60,6 @@ describe('DashboardPrompt', () => { expect(hasChanges(dash, original)).toBe(false); }); - it('Should ignore .iteration changes', () => { - const { original, dash } = getTestContext(); - dash.iteration = new Date().getTime() + 1; - expect(hasChanges(dash, original)).toBe(false); - }); - it('Should ignore row collapse change', () => { const { original, dash } = getTestContext(); dash.toggleRow(dash.panels[1]); diff --git a/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.tsx b/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.tsx index 8e945ce9a8c..7f19ae22ccb 100644 --- a/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.tsx +++ b/public/app/features/dashboard/components/DashboardPrompt/DashboardPrompt.tsx @@ -181,9 +181,6 @@ function cleanDashboardFromIgnoredChanges(dashData: any) { dash.schemaVersion = 0; dash.timezone = 0; - // ignore iteration property - delete dash.iteration; - dash.panels = []; // ignore template variable values diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts index 2bd035411c1..37a4298fe86 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -105,7 +105,6 @@ export class DashboardModel implements TimeModel { // ------------------ // repeat process cycles - iteration?: number; declare meta: DashboardMeta; events: EventBusExtended; @@ -507,13 +506,10 @@ export class DashboardModel implements TimeModel { return; } - this.iteration = (this.iteration || new Date().getTime()) + 1; // cleanup scopedVars deleteScopeVars(this.panels); - const panelsToRemove = this.panels.filter( - (p) => (!p.repeat || p.repeatedByRow) && p.repeatPanelId && p.repeatIteration !== this.iteration - ); + const panelsToRemove = this.panels.filter((p) => (!p.repeat || p.repeatedByRow) && p.repeatPanelId); // remove panels pull(this.panels, ...panelsToRemove); @@ -528,8 +524,6 @@ export class DashboardModel implements TimeModel { this.cleanUpRepeats(); - this.iteration = (this.iteration || new Date().getTime()) + 1; - for (let i = 0; i < this.panels.length; i++) { const panel = this.panels[i]; if (panel.repeat) { @@ -584,7 +578,6 @@ export class DashboardModel implements TimeModel { // insert after source panel + value index this.panels.splice(sourcePanelIndex + valueIndex, 0, clone); - clone.repeatIteration = this.iteration; clone.repeatPanelId = sourcePanel.id; clone.repeat = undefined; @@ -747,12 +740,13 @@ export class DashboardModel implements TimeModel { updateRepeatedPanelIds(panel: PanelModel, repeatedByRow?: boolean) { panel.repeatPanelId = panel.id; panel.id = this.getNextPanelId(); - panel.repeatIteration = this.iteration; + if (repeatedByRow) { panel.repeatedByRow = true; } else { panel.repeat = undefined; } + return panel; } @@ -827,9 +821,11 @@ export class DashboardModel implements TimeModel { delete newPanel.repeatIteration; delete newPanel.repeatPanelId; delete newPanel.scopedVars; + if (newPanel.alert) { delete newPanel.thresholds; } + delete newPanel.alert; // does it fit to the right? diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index d6208f74f94..1c7315e0bc8 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -76,7 +76,6 @@ const mustKeepProps: { [str: string]: boolean } = { title: true, scopedVars: true, repeat: true, - repeatIteration: true, repeatPanelId: true, repeatDirection: true, repeatedByRow: true,