From f53839e4fd95781c693bf0e8a8be2defaa1576ad Mon Sep 17 00:00:00 2001 From: Greg Tan Date: Wed, 29 Nov 2023 17:53:15 +0800 Subject: [PATCH] Dashboard: Call destroy when panel is removed (#77017) --- .../features/dashboard/state/DashboardModel.test.ts | 10 ++++++++++ public/app/features/dashboard/state/DashboardModel.ts | 1 + 2 files changed, 11 insertions(+) diff --git a/public/app/features/dashboard/state/DashboardModel.test.ts b/public/app/features/dashboard/state/DashboardModel.test.ts index a981c75a65a..99a1df997dd 100644 --- a/public/app/features/dashboard/state/DashboardModel.test.ts +++ b/public/app/features/dashboard/state/DashboardModel.test.ts @@ -189,6 +189,16 @@ describe('DashboardModel', () => { expect(dashboard.panels[1].repeat).toBe(undefined); expect(dashboard.panels[1].scopedVars).toBe(undefined); }); + + it('remove panel should call destroy', () => { + dashboard.addPanel({ type: 'test', title: 'test' }); + const panel = dashboard.panels[0]; + panel.destroy = jest.fn(); + + dashboard.removePanel(panel); + + expect(panel.destroy).toHaveBeenCalled(); + }); }); describe('Given editable false dashboard', () => { diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts index 31af7a3a5d3..531af6e9613 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -864,6 +864,7 @@ export class DashboardModel implements TimeModel { removePanel(panel: PanelModel) { this.panels = this.panels.filter((item) => item !== panel); + panel.destroy(); this.events.publish(new DashboardPanelsChangedEvent()); }