NewPanelEdit: Fixes issue with angular panel clean up, and cleanup after leaving edit mode (#24224)

This commit is contained in:
Torkel Ödegaard
2020-05-04 14:11:15 +02:00
committed by GitHub
parent 5f621a736a
commit 5a20782499
3 changed files with 10 additions and 3 deletions
@@ -33,7 +33,7 @@ describe('panelEditor actions', () => {
panels: [{ id: 12, type: 'graph' }],
});
const panel = sourcePanel.getEditClone();
const panel = dashboard.initEditPanel(sourcePanel);
panel.updateOptions({ prop: true });
const state: PanelEditorState = {
@@ -65,7 +65,7 @@ describe('panelEditor actions', () => {
panels: [{ id: 12, type: 'graph' }],
});
const panel = sourcePanel.getEditClone();
const panel = dashboard.initEditPanel(sourcePanel);
panel.type = 'table';
panel.plugin = getPanelPlugin({ id: 'table' });
panel.updateOptions({ prop: true });
@@ -77,6 +77,8 @@ describe('panelEditor actions', () => {
querySubscription: { unsubscribe: jest.fn() },
};
const panelDestroy = (panel.destroy = jest.fn());
const dispatchedActions = await thunkTester({
panelEditor: state,
dashboard: {
@@ -89,6 +91,7 @@ describe('panelEditor actions', () => {
expect(dispatchedActions.length).toBe(3);
expect(dispatchedActions[0].type).toBe(panelModelAndPluginReady.type);
expect(sourcePanel.plugin).toEqual(panel.plugin);
expect(panelDestroy.mock.calls.length).toEqual(1);
});
it('should discard changes when shouldDiscardChanges is true', async () => {
@@ -101,7 +104,7 @@ describe('panelEditor actions', () => {
panels: [{ id: 12, type: 'graph' }],
});
const panel = sourcePanel.getEditClone();
const panel = dashboard.initEditPanel(sourcePanel);
panel.updateOptions({ prop: true });
const state: PanelEditorState = {
@@ -341,6 +341,7 @@ export class DashboardModel {
}
exitPanelEditor() {
this.panelInEdit.destroy();
this.panelInEdit = undefined;
}
@@ -82,6 +82,9 @@ module.directive('grafanaPanel', ($rootScope, $document, $timeout) => {
scope.$on('$destroy', () => {
elem.off();
panel.events.emit(PanelEvents.panelTeardown);
panel.events.removeAllListeners();
if (panelScrollbar) {
panelScrollbar.dispose();
}