Dashboard: Call destroy when panel is removed (#77017)

pull/78669/head^2
Greg Tan 2 years ago committed by GitHub
parent 059ba25973
commit f53839e4fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      public/app/features/dashboard/state/DashboardModel.test.ts
  2. 1
      public/app/features/dashboard/state/DashboardModel.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', () => {

@ -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());
}

Loading…
Cancel
Save