mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remove datalink template suggestions for accessing specific fields when there are multiple dataframes. (#32057)
* Don't suggest template strings using fields when there are mutliple dataframes * Change to use label instead of state
This commit is contained in:
parent
8854001b67
commit
f48a52e590
@ -13,6 +13,9 @@ describe('getFieldDisplayValuesProxy', () => {
|
|||||||
{
|
{
|
||||||
name: 'power',
|
name: 'power',
|
||||||
values: [100, 200, 300],
|
values: [100, 200, 300],
|
||||||
|
labels: {
|
||||||
|
name: 'POWAH!',
|
||||||
|
},
|
||||||
config: {
|
config: {
|
||||||
displayName: 'The Power',
|
displayName: 'The Power',
|
||||||
},
|
},
|
||||||
@ -60,6 +63,7 @@ describe('getFieldDisplayValuesProxy', () => {
|
|||||||
});
|
});
|
||||||
expect(p.power.numeric).toEqual(300);
|
expect(p.power.numeric).toEqual(300);
|
||||||
expect(p['power'].numeric).toEqual(300);
|
expect(p['power'].numeric).toEqual(300);
|
||||||
|
expect(p['POWAH!'].numeric).toEqual(300);
|
||||||
expect(p['The Power'].numeric).toEqual(300);
|
expect(p['The Power'].numeric).toEqual(300);
|
||||||
expect(p[1].numeric).toEqual(300);
|
expect(p[1].numeric).toEqual(300);
|
||||||
});
|
});
|
||||||
|
@ -28,9 +28,18 @@ export function getFieldDisplayValuesProxy(
|
|||||||
field = frame.fields[k];
|
field = frame.fields[k];
|
||||||
}
|
}
|
||||||
if (!field) {
|
if (!field) {
|
||||||
// 3. Match the title
|
// 3. Match the config displayName
|
||||||
field = frame.fields.find((f) => key === f.config.displayName);
|
field = frame.fields.find((f) => key === f.config.displayName);
|
||||||
}
|
}
|
||||||
|
if (!field) {
|
||||||
|
// 4. Match the name label
|
||||||
|
field = frame.fields.find((f) => {
|
||||||
|
if (f.labels) {
|
||||||
|
return key === f.labels.name;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!field) {
|
if (!field) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -134,30 +134,36 @@ export const getDataFrameVars = (dataFrames: DataFrame[]) => {
|
|||||||
const suggestions: VariableSuggestion[] = [];
|
const suggestions: VariableSuggestion[] = [];
|
||||||
const keys: KeyValue<true> = {};
|
const keys: KeyValue<true> = {};
|
||||||
|
|
||||||
for (const frame of dataFrames) {
|
if (dataFrames.length !== 1) {
|
||||||
for (const field of frame.fields) {
|
// It's not possible to access fields of other dataframes. So if there are multiple dataframes we need to skip these suggestions.
|
||||||
const displayName = getFieldDisplayName(field, frame, dataFrames);
|
// Also return early if there are no dataFrames.
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
if (keys[displayName]) {
|
const frame = dataFrames[0];
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
suggestions.push({
|
for (const field of frame.fields) {
|
||||||
value: `__data.fields${buildLabelPath(displayName)}`,
|
const displayName = getFieldDisplayName(field, frame, dataFrames);
|
||||||
label: `${displayName}`,
|
|
||||||
documentation: `Formatted value for ${displayName} on the same row`,
|
|
||||||
origin: VariableOrigin.Fields,
|
|
||||||
});
|
|
||||||
|
|
||||||
keys[displayName] = true;
|
if (keys[displayName]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!numeric && field.type === FieldType.number) {
|
suggestions.push({
|
||||||
numeric = { ...field, name: displayName };
|
value: `__data.fields${buildLabelPath(displayName)}`,
|
||||||
}
|
label: `${displayName}`,
|
||||||
|
documentation: `Formatted value for ${displayName} on the same row`,
|
||||||
|
origin: VariableOrigin.Fields,
|
||||||
|
});
|
||||||
|
|
||||||
if (!title && field.config.displayName && field.config.displayName !== field.name) {
|
keys[displayName] = true;
|
||||||
title = { ...field, name: displayName };
|
|
||||||
}
|
if (!numeric && field.type === FieldType.number) {
|
||||||
|
numeric = { ...field, name: displayName };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!title && field.config.displayName && field.config.displayName !== field.name) {
|
||||||
|
title = { ...field, name: displayName };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,4 +424,28 @@ describe('getDataFrameVars', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when called with multiple DataFrames', () => {
|
||||||
|
it('it should not return any suggestions', () => {
|
||||||
|
const frame1 = toDataFrame({
|
||||||
|
name: 'server1',
|
||||||
|
fields: [
|
||||||
|
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
|
||||||
|
{ name: 'value', type: FieldType.number, values: [10, 11, 12] },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const frame2 = toDataFrame({
|
||||||
|
name: 'server2',
|
||||||
|
fields: [
|
||||||
|
{ name: 'time', type: FieldType.time, values: [1, 2, 3] },
|
||||||
|
{ name: 'value', type: FieldType.number, values: [10, 11, 12] },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const suggestions = getDataFrameVars([frame1, frame2]);
|
||||||
|
|
||||||
|
expect(suggestions).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user