PanelEditor: Fixes issue changing panel type from graph to stat and thresholds not taking affect after going back to dashboard (#24144)

* PanelEditor: Fixes issue with panel type change and query result reuse

* removed unused imports

* removed unused imports

(cherry picked from commit a00636b2ec)
This commit is contained in:
Torkel Ödegaard
2020-05-07 14:59:21 +02:00
committed by Arve Knudsen
parent 1df9921666
commit 92138de21b
4 changed files with 20 additions and 21 deletions
@@ -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 () => {
@@ -47,6 +47,10 @@ export function panelEditorCleanUp(): ThunkResult<void> {
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! }));
}
@@ -73,6 +73,7 @@ export class PanelChrome extends PureComponent<Props, State> {
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<Props, State> {
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<Props, State> {
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,
@@ -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();
}
}