Commit 5b9901eb by Ryan McKinley Committed by Torkel Ödegaard

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
parent 55717769
...@@ -187,8 +187,8 @@ export function getProcessedDataFrames(results?: DataQueryResponseData[]): DataF ...@@ -187,8 +187,8 @@ export function getProcessedDataFrames(results?: DataQueryResponseData[]): DataF
return dataFrames; return dataFrames;
} }
export function preProcessPanelData(data: PanelData, lastResult: PanelData) { export function preProcessPanelData(data: PanelData, lastResult: PanelData): PanelData {
let { series } = data; const { series } = data;
// for loading states with no data, use last result // for loading states with no data, use last result
if (data.state === LoadingState.Loading && series.length === 0) { if (data.state === LoadingState.Loading && series.length === 0) {
...@@ -199,6 +199,9 @@ export function preProcessPanelData(data: PanelData, lastResult: PanelData) { ...@@ -199,6 +199,9 @@ export function preProcessPanelData(data: PanelData, lastResult: PanelData) {
return { ...lastResult, state: LoadingState.Loading }; return { ...lastResult, state: LoadingState.Loading };
} }
// Makes sure the data is properly formatted // Make sure the data frames are properly formatted
return getProcessedDataFrames(series); return {
...data,
series: getProcessedDataFrames(series),
};
} }
...@@ -12,7 +12,7 @@ import { axesEditorComponent } from './axes_editor'; ...@@ -12,7 +12,7 @@ import { axesEditorComponent } from './axes_editor';
import config from 'app/core/config'; import config from 'app/core/config';
import TimeSeries from 'app/core/time_series2'; import TimeSeries from 'app/core/time_series2';
import { DataFrame, DataLink, DateTimeInput } from '@grafana/data'; 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 { getProcessedDataFrames } from 'app/features/dashboard/state/runRequest';
import { GraphContextMenuCtrl } from './GraphContextMenuCtrl'; import { GraphContextMenuCtrl } from './GraphContextMenuCtrl';
import { getDataLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv'; import { getDataLinksVariableSuggestions } from 'app/features/panel/panellinks/link_srv';
...@@ -147,7 +147,6 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -147,7 +147,6 @@ class GraphCtrl extends MetricsPanelCtrl {
this.contextMenuCtrl = new GraphContextMenuCtrl($scope); this.contextMenuCtrl = new GraphContextMenuCtrl($scope);
this.events.on('render', this.onRender.bind(this)); 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-frames-received', this.onDataFramesReceived.bind(this));
this.events.on('data-error', this.onDataError.bind(this)); this.events.on('data-error', this.onDataError.bind(this));
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this)); this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));
...@@ -199,7 +198,9 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -199,7 +198,9 @@ class GraphCtrl extends MetricsPanelCtrl {
panel: this.panel, panel: this.panel,
range: this.range, range: this.range,
}); });
this.onDataReceived(snapshotData);
const frames = getProcessedDataFrames(snapshotData);
this.onDataFramesReceived(frames);
} }
onDataError(err: any) { onDataError(err: any) {
...@@ -208,12 +209,6 @@ class GraphCtrl extends MetricsPanelCtrl { ...@@ -208,12 +209,6 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render([]); 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[]) { onDataFramesReceived(data: DataFrame[]) {
this.dataList = data; this.dataList = data;
this.seriesList = this.processor.getSeriesList({ this.seriesList = this.processor.getSeriesList({
......
...@@ -88,6 +88,9 @@ describe('grafanaGraph', () => { ...@@ -88,6 +88,9 @@ describe('grafanaGraph', () => {
from: dateTime([2015, 1, 1, 10]), from: dateTime([2015, 1, 1, 10]),
to: dateTime([2015, 1, 1, 22]), to: dateTime([2015, 1, 1, 22]),
}, },
annotationsSrv: {
getAnnotations: () => Promise.resolve({}),
},
} as any; } as any;
ctx.data = []; ctx.data = [];
......
...@@ -37,6 +37,9 @@ describe('GraphCtrl', () => { ...@@ -37,6 +37,9 @@ describe('GraphCtrl', () => {
ctx.ctrl.events = { ctx.ctrl.events = {
emit: () => {}, emit: () => {},
}; };
ctx.ctrl.annotationsSrv = {
getAnnotations: () => Promise.resolve({}),
};
ctx.ctrl.annotationsPromise = Promise.resolve({}); ctx.ctrl.annotationsPromise = Promise.resolve({});
ctx.ctrl.updateTimeRange(); ctx.ctrl.updateTimeRange();
}); });
...@@ -51,7 +54,7 @@ describe('GraphCtrl', () => { ...@@ -51,7 +54,7 @@ describe('GraphCtrl', () => {
]; ];
ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() }; ctx.ctrl.range = { from: dateTime().valueOf(), to: dateTime().valueOf() };
ctx.ctrl.onDataReceived(data); ctx.ctrl.onDataSnapshotLoad(data);
}); });
it('should set datapointsOutside', () => { it('should set datapointsOutside', () => {
...@@ -76,7 +79,7 @@ describe('GraphCtrl', () => { ...@@ -76,7 +79,7 @@ describe('GraphCtrl', () => {
]; ];
ctx.ctrl.range = range; ctx.ctrl.range = range;
ctx.ctrl.onDataReceived(data); ctx.ctrl.onDataSnapshotLoad(data);
}); });
it('should set datapointsOutside', () => { it('should set datapointsOutside', () => {
...@@ -87,7 +90,7 @@ describe('GraphCtrl', () => { ...@@ -87,7 +90,7 @@ describe('GraphCtrl', () => {
describe('datapointsCount given 2 series', () => { describe('datapointsCount given 2 series', () => {
beforeEach(() => { beforeEach(() => {
const data: any = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }]; const data: any = [{ target: 'test.cpu1', datapoints: [] }, { target: 'test.cpu2', datapoints: [] }];
ctx.ctrl.onDataReceived(data); ctx.ctrl.onDataSnapshotLoad(data);
}); });
it('should set datapointsCount warning', () => { it('should set datapointsCount warning', () => {
......
...@@ -120,7 +120,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -120,7 +120,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
this.events.on('data-frames-received', this.onFramesReceived.bind(this)); this.events.on('data-frames-received', this.onFramesReceived.bind(this));
this.events.on('data-error', this.onDataError.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.events.on('init-edit-mode', this.onInitEditMode.bind(this));
this.useDataFrames = true; this.useDataFrames = true;
...@@ -154,8 +154,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { ...@@ -154,8 +154,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
this.handleDataFrames([]); this.handleDataFrames([]);
} }
// This should only be called from the snapshot callback onSnapshotLoad(dataList: LegacyResponseData[]) {
onDataReceived(dataList: LegacyResponseData[]) {
this.onFramesReceived(getProcessedDataFrames(dataList)); this.onFramesReceived(getProcessedDataFrames(dataList));
} }
......
...@@ -45,7 +45,7 @@ describe('SingleStatCtrl', () => { ...@@ -45,7 +45,7 @@ describe('SingleStatCtrl', () => {
// @ts-ignore // @ts-ignore
ctx.ctrl = new SingleStatCtrl($scope, $injector, {} as LinkSrv, $sanitize); ctx.ctrl = new SingleStatCtrl($scope, $injector, {} as LinkSrv, $sanitize);
setupFunc(); setupFunc();
ctx.ctrl.onDataReceived(ctx.input); ctx.ctrl.onSnapshotLoad(ctx.input);
ctx.data = ctx.ctrl.data; ctx.data = ctx.ctrl.data;
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment