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
This commit is contained in:
Torkel Ödegaard 2020-05-01 14:14:52 +02:00 committed by GitHub
parent 4f81125af0
commit a00636b2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 21 deletions

View File

@ -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 () => {

View File

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

View File

@ -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,

View File

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