mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 20:54:22 -06:00
GraphPanel: don't listen to legacy onDataReceived events (#19054)
* don't listen to legacy data events in graph * fix test * rename function * add annotationsSrv stub * use const * fix preProcessPanelData * update test
This commit is contained in:
parent
55717769a3
commit
5b9901ebba
@ -187,8 +187,8 @@ export function getProcessedDataFrames(results?: DataQueryResponseData[]): DataF
|
||||
return dataFrames;
|
||||
}
|
||||
|
||||
export function preProcessPanelData(data: PanelData, lastResult: PanelData) {
|
||||
let { series } = data;
|
||||
export function preProcessPanelData(data: PanelData, lastResult: PanelData): PanelData {
|
||||
const { series } = data;
|
||||
|
||||
// for loading states with no data, use last result
|
||||
if (data.state === LoadingState.Loading && series.length === 0) {
|
||||
@ -199,6 +199,9 @@ export function preProcessPanelData(data: PanelData, lastResult: PanelData) {
|
||||
return { ...lastResult, state: LoadingState.Loading };
|
||||
}
|
||||
|
||||
// Makes sure the data is properly formatted
|
||||
return getProcessedDataFrames(series);
|
||||
// Make sure the data frames are properly formatted
|
||||
return {
|
||||
...data,
|
||||
series: getProcessedDataFrames(series),
|
||||
};
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import { axesEditorComponent } from './axes_editor';
|
||||
import config from 'app/core/config';
|
||||
import TimeSeries from 'app/core/time_series2';
|
||||
import { DataFrame, DataLink, DateTimeInput } from '@grafana/data';
|
||||
import { getColorFromHexRgbOrName, LegacyResponseData, VariableSuggestion } from '@grafana/ui';
|
||||
import { getColorFromHexRgbOrName, VariableSuggestion } from '@grafana/ui';
|
||||
import { getProcessedDataFrames } from 'app/features/dashboard/state/runRequest';
|
||||
import { GraphContextMenuCtrl } from './GraphContextMenuCtrl';
|
||||
import { getDataLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
|
||||
@ -147,7 +147,6 @@ class GraphCtrl extends MetricsPanelCtrl {
|
||||
this.contextMenuCtrl = new GraphContextMenuCtrl($scope);
|
||||
|
||||
this.events.on('render', this.onRender.bind(this));
|
||||
this.events.on('data-received', this.onDataReceived.bind(this));
|
||||
this.events.on('data-frames-received', this.onDataFramesReceived.bind(this));
|
||||
this.events.on('data-error', this.onDataError.bind(this));
|
||||
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));
|
||||
@ -199,7 +198,9 @@ class GraphCtrl extends MetricsPanelCtrl {
|
||||
panel: this.panel,
|
||||
range: this.range,
|
||||
});
|
||||
this.onDataReceived(snapshotData);
|
||||
|
||||
const frames = getProcessedDataFrames(snapshotData);
|
||||
this.onDataFramesReceived(frames);
|
||||
}
|
||||
|
||||
onDataError(err: any) {
|
||||
@ -208,12 +209,6 @@ class GraphCtrl extends MetricsPanelCtrl {
|
||||
this.render([]);
|
||||
}
|
||||
|
||||
// This should only be called from the snapshot callback
|
||||
onDataReceived(dataList: LegacyResponseData[]) {
|
||||
this.onDataFramesReceived(getProcessedDataFrames(dataList));
|
||||
}
|
||||
|
||||
// Directly support DataFrame skipping event callbacks
|
||||
onDataFramesReceived(data: DataFrame[]) {
|
||||
this.dataList = data;
|
||||
this.seriesList = this.processor.getSeriesList({
|
||||
|
@ -88,6 +88,9 @@ describe('grafanaGraph', () => {
|
||||
from: dateTime([2015, 1, 1, 10]),
|
||||
to: dateTime([2015, 1, 1, 22]),
|
||||
},
|
||||
annotationsSrv: {
|
||||
getAnnotations: () => Promise.resolve({}),
|
||||
},
|
||||
} as any;
|
||||
|
||||
ctx.data = [];
|
||||
|
@ -37,6 +37,9 @@ describe('GraphCtrl', () => {
|
||||
ctx.ctrl.events = {
|
||||
emit: () => {},
|
||||
};
|
||||
ctx.ctrl.annotationsSrv = {
|
||||
getAnnotations: () => Promise.resolve({}),
|
||||
};
|
||||
ctx.ctrl.annotationsPromise = Promise.resolve({});
|
||||
ctx.ctrl.updateTimeRange();
|
||||
});
|
||||
@ -51,7 +54,7 @@ describe('GraphCtrl', () => {
|
||||
];
|
||||
|
||||
ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() };
|
||||
ctx.ctrl.onDataReceived(data);
|
||||
ctx.ctrl.onDataSnapshotLoad(data);
|
||||
});
|
||||
|
||||
it('should set datapointsOutside', () => {
|
||||
@ -76,7 +79,7 @@ describe('GraphCtrl', () => {
|
||||
];
|
||||
|
||||
ctx.ctrl.range = range;
|
||||
ctx.ctrl.onDataReceived(data);
|
||||
ctx.ctrl.onDataSnapshotLoad(data);
|
||||
});
|
||||
|
||||
it('should set datapointsOutside', () => {
|
||||
@ -87,7 +90,7 @@ describe('GraphCtrl', () => {
|
||||
describe('datapointsCount given 2 series', () => {
|
||||
beforeEach(() => {
|
||||
const data: any = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
|
||||
ctx.ctrl.onDataReceived(data);
|
||||
ctx.ctrl.onDataSnapshotLoad(data);
|
||||
});
|
||||
|
||||
it('should set datapointsCount warning', () => {
|
||||
|
@ -120,7 +120,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
||||
|
||||
this.events.on('data-frames-received', this.onFramesReceived.bind(this));
|
||||
this.events.on('data-error', this.onDataError.bind(this));
|
||||
this.events.on('data-snapshot-load', this.onDataReceived.bind(this));
|
||||
this.events.on('data-snapshot-load', this.onSnapshotLoad.bind(this));
|
||||
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
|
||||
|
||||
this.useDataFrames = true;
|
||||
@ -154,8 +154,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
|
||||
this.handleDataFrames([]);
|
||||
}
|
||||
|
||||
// This should only be called from the snapshot callback
|
||||
onDataReceived(dataList: LegacyResponseData[]) {
|
||||
onSnapshotLoad(dataList: LegacyResponseData[]) {
|
||||
this.onFramesReceived(getProcessedDataFrames(dataList));
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ describe('SingleStatCtrl', () => {
|
||||
// @ts-ignore
|
||||
ctx.ctrl = new SingleStatCtrl($scope, $injector, {} as LinkSrv, $sanitize);
|
||||
setupFunc();
|
||||
ctx.ctrl.onDataReceived(ctx.input);
|
||||
ctx.ctrl.onSnapshotLoad(ctx.input);
|
||||
ctx.data = ctx.ctrl.data;
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user