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

This commit is contained in:
Greg Tan 2023-11-29 17:53:15 +08:00 committed by GitHub
parent 059ba25973
commit f53839e4fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -189,6 +189,16 @@ describe('DashboardModel', () => {
expect(dashboard.panels[1].repeat).toBe(undefined); expect(dashboard.panels[1].repeat).toBe(undefined);
expect(dashboard.panels[1].scopedVars).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', () => { describe('Given editable false dashboard', () => {

View File

@ -864,6 +864,7 @@ export class DashboardModel implements TimeModel {
removePanel(panel: PanelModel) { removePanel(panel: PanelModel) {
this.panels = this.panels.filter((item) => item !== panel); this.panels = this.panels.filter((item) => item !== panel);
panel.destroy();
this.events.publish(new DashboardPanelsChangedEvent()); this.events.publish(new DashboardPanelsChangedEvent());
} }