mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
PanelEdit: Fixed re-using query result after leaving panel edit (#24340)
This commit is contained in:
parent
8de6ef473f
commit
33123c7e7e
@ -58,10 +58,7 @@ export function panelEditorCleanUp(): ThunkResult<void> {
|
|||||||
// Resend last query result on source panel query runner
|
// Resend last query result on source panel query runner
|
||||||
// But do this after the panel edit editor exit process has completed
|
// But do this after the panel edit editor exit process has completed
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const lastResult = panel.getQueryRunner().getLastResult();
|
sourcePanel.getQueryRunner().useLastResultFrom(panel.getQueryRunner());
|
||||||
if (lastResult) {
|
|
||||||
sourcePanel.getQueryRunner().pipeDataToSubject(lastResult);
|
|
||||||
}
|
|
||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,10 +235,6 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
return panel.snapshotData && panel.snapshotData.length;
|
return panel.snapshotData && panel.snapshotData.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
panelHasLastResult = () => {
|
|
||||||
return !!this.props.panel.getQueryRunner().getLastResult();
|
|
||||||
};
|
|
||||||
|
|
||||||
get wantsQueryExecution() {
|
get wantsQueryExecution() {
|
||||||
return !(this.props.plugin.meta.skipDataQuery || this.hasPanelSnapshot);
|
return !(this.props.plugin.meta.skipDataQuery || this.hasPanelSnapshot);
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,10 @@ import {
|
|||||||
PanelProps,
|
PanelProps,
|
||||||
standardEditorsRegistry,
|
standardEditorsRegistry,
|
||||||
standardFieldConfigEditorRegistry,
|
standardFieldConfigEditorRegistry,
|
||||||
|
PanelData,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { ComponentClass } from 'react';
|
import { ComponentClass } from 'react';
|
||||||
|
import { PanelQueryRunner } from './PanelQueryRunner';
|
||||||
|
|
||||||
class TablePanelCtrl {}
|
class TablePanelCtrl {}
|
||||||
|
|
||||||
@ -336,5 +338,16 @@ describe('PanelModel', () => {
|
|||||||
expect(model.thresholds).toBeUndefined();
|
expect(model.thresholds).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('destroy', () => {
|
||||||
|
it('Should still preserve last query result', () => {
|
||||||
|
model.getQueryRunner().useLastResultFrom({
|
||||||
|
getLastResult: () => ({} as PanelData),
|
||||||
|
} as PanelQueryRunner);
|
||||||
|
|
||||||
|
model.destroy();
|
||||||
|
expect(model.getQueryRunner().getLastResult()).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -422,11 +422,8 @@ export class PanelModel implements DataConfigSource {
|
|||||||
clone.isEditing = true;
|
clone.isEditing = true;
|
||||||
const sourceQueryRunner = this.getQueryRunner();
|
const sourceQueryRunner = this.getQueryRunner();
|
||||||
|
|
||||||
// pipe last result to new clone query runner
|
// Copy last query result
|
||||||
const lastResult = sourceQueryRunner.getLastResult();
|
clone.getQueryRunner().useLastResultFrom(sourceQueryRunner);
|
||||||
if (lastResult) {
|
|
||||||
clone.getQueryRunner().pipeDataToSubject(lastResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
@ -469,7 +466,6 @@ export class PanelModel implements DataConfigSource {
|
|||||||
|
|
||||||
if (this.queryRunner) {
|
if (this.queryRunner) {
|
||||||
this.queryRunner.destroy();
|
this.queryRunner.destroy();
|
||||||
this.queryRunner = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,11 +190,6 @@ export class PanelQueryRunner {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeDataToSubject = (data: PanelData) => {
|
|
||||||
this.subject.next(data);
|
|
||||||
this.lastResult = data;
|
|
||||||
};
|
|
||||||
|
|
||||||
resendLastResult = () => {
|
resendLastResult = () => {
|
||||||
if (this.lastResult) {
|
if (this.lastResult) {
|
||||||
this.subject.next(this.lastResult);
|
this.subject.next(this.lastResult);
|
||||||
@ -215,6 +210,15 @@ export class PanelQueryRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useLastResultFrom(runner: PanelQueryRunner) {
|
||||||
|
this.lastResult = runner.getLastResult();
|
||||||
|
|
||||||
|
if (this.lastResult) {
|
||||||
|
// The subject is a replay subject so anyone subscribing will get this last result
|
||||||
|
this.subject.next(this.lastResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getLastResult(): PanelData {
|
getLastResult(): PanelData {
|
||||||
return this.lastResult;
|
return this.lastResult;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user