Variables: Fixes error with: cannot read property length of undefined (#31458) (#31527)

* Variables: Fixes error with: cannot read property length of undefined

* A different fix

(cherry picked from commit e9d2592481)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
Grot (@grafanabot)andTorkel Ödegaard authored and GitHub committed 2021-02-28 08:11:16 +01:00
1 parent 2d890b8f02
commit d46acaf1dd
1 file changed
+4 -1
@@ -9,6 +9,7 @@ import { DataSourceApi, FieldType, getFieldDisplayName, isDataFrame, MetricFindV
import { updateVariableOptions, updateVariableTags } from './reducer';
import { getTimeSrv, TimeSrv } from '../../dashboard/services/TimeSrv';
import { getLegacyQueryOptions, getTemplatedRegex } from '../utils';
import { getProcessedDataFrames } from 'app/features/query/state/runRequest';
export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValue[]> {
return (source) =>
@@ -23,6 +24,7 @@ export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValu
return frames;
}
const processedDataFrames = getProcessedDataFrames(frames);
const metrics: MetricFindValue[] = [];
let valueIndex = -1;
@@ -30,7 +32,7 @@ export function toMetricFindValues(): OperatorFunction<PanelData, MetricFindValu
let stringIndex = -1;
let expandableIndex = -1;
for (const frame of frames) {
for (const frame of processedDataFrames) {
for (let index = 0; index < frame.fields.length; index++) {
const field = frame.fields[index];
const fieldName = getFieldDisplayName(field, frame, frames).toLowerCase();
@@ -181,6 +183,7 @@ export function areMetricFindValues(data: any[]): data is MetricFindValue[] {
}
const firstValue: any = data[0];
if (isDataFrame(firstValue)) {
return false;
}