diff --git a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts index a640c4f14f3..0a17952c866 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.test.ts @@ -88,6 +88,7 @@ describe('panelEditor actions', () => { expect(dispatchedActions.length).toBe(3); expect(dispatchedActions[0].type).toBe(panelModelAndPluginReady.type); + expect(sourcePanel.plugin).toEqual(panel.plugin); }); it('should discard changes when shouldDiscardChanges is true', async () => { diff --git a/public/app/features/dashboard/components/PanelEditor/state/actions.ts b/public/app/features/dashboard/components/PanelEditor/state/actions.ts index b2edde42681..78541e2260d 100644 --- a/public/app/features/dashboard/components/PanelEditor/state/actions.ts +++ b/public/app/features/dashboard/components/PanelEditor/state/actions.ts @@ -47,6 +47,10 @@ export function panelEditorCleanUp(): ThunkResult { sourcePanel.restoreModel(modifiedSaveModel); + // Loaded plugin is not included in the persisted properties + // So is not handled by restoreModel + sourcePanel.plugin = panel.plugin; + if (panelTypeChanged) { dispatch(panelModelAndPluginReady({ panelId: sourcePanel.id, plugin: panel.plugin! })); } diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index b8ca99b21d7..47602ccfe1b 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -73,6 +73,7 @@ export class PanelChrome extends PureComponent { panel.events.on(PanelEvents.refresh, this.onRefresh); panel.events.on(PanelEvents.render, this.onRender); + dashboard.panelInitialized(this.props.panel); // Move snapshot data into the query response @@ -99,6 +100,15 @@ export class PanelChrome extends PureComponent { this.setState({ isFirstLoad: false }); } } + + if (!this.querySubscription) { + this.querySubscription = panel + .getQueryRunner() + .getData() + .subscribe({ + next: data => this.onDataUpdate(data), + }); + } } componentWillUnmount() { @@ -184,15 +194,7 @@ export class PanelChrome extends PureComponent { return; } - const queryRunner = panel.getQueryRunner(); - - if (!this.querySubscription) { - this.querySubscription = queryRunner.getData().subscribe({ - next: data => this.onDataUpdate(data), - }); - } - - queryRunner.run({ + panel.getQueryRunner().run({ datasource: panel.datasource, queries: panel.targets, panelId: panel.id, diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts index 5051cdfbbee..e462b17e805 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -314,18 +314,10 @@ export class DashboardModel { panelInitialized(panel: PanelModel) { panel.initialized(); - if (this.panelInEdit === panel) { - if (this.panelInEdit.getQueryRunner().getLastResult()) { - return; - } else { - // refresh if panel is in edit mode and there is no last result - panel.refresh(); - } - } else { - // refresh new panels unless we are in fullscreen / edit mode - if (!this.otherPanelInFullscreen(panel)) { - panel.refresh(); - } + const lastResult = panel.getQueryRunner().getLastResult(); + + if (!this.otherPanelInFullscreen(panel) && !lastResult) { + panel.refresh(); } }