mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -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',
|
||||
values: [100, 200, 300],
|
||||
labels: {
|
||||
name: 'POWAH!',
|
||||
},
|
||||
config: {
|
||||
displayName: 'The Power',
|
||||
},
|
||||
@ -60,6 +63,7 @@ describe('getFieldDisplayValuesProxy', () => {
|
||||
});
|
||||
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[1].numeric).toEqual(300);
|
||||
});
|
||||
|
@ -28,9 +28,18 @@ export function getFieldDisplayValuesProxy(
|
||||
field = frame.fields[k];
|
||||
}
|
||||
if (!field) {
|
||||
// 3. Match the title
|
||||
// 3. Match the 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) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -134,30 +134,36 @@ export const getDataFrameVars = (dataFrames: DataFrame[]) => {
|
||||
const suggestions: VariableSuggestion[] = [];
|
||||
const keys: KeyValue<true> = {};
|
||||
|
||||
for (const frame of dataFrames) {
|
||||
for (const field of frame.fields) {
|
||||
const displayName = getFieldDisplayName(field, frame, dataFrames);
|
||||
if (dataFrames.length !== 1) {
|
||||
// It's not possible to access fields of other dataframes. So if there are multiple dataframes we need to skip these suggestions.
|
||||
// Also return early if there are no dataFrames.
|
||||
return [];
|
||||
}
|
||||
|
||||
if (keys[displayName]) {
|
||||
continue;
|
||||
}
|
||||
const frame = dataFrames[0];
|
||||
|
||||
suggestions.push({
|
||||
value: `__data.fields${buildLabelPath(displayName)}`,
|
||||
label: `${displayName}`,
|
||||
documentation: `Formatted value for ${displayName} on the same row`,
|
||||
origin: VariableOrigin.Fields,
|
||||
});
|
||||
for (const field of frame.fields) {
|
||||
const displayName = getFieldDisplayName(field, frame, dataFrames);
|
||||
|
||||
keys[displayName] = true;
|
||||
if (keys[displayName]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!numeric && field.type === FieldType.number) {
|
||||
numeric = { ...field, name: displayName };
|
||||
}
|
||||
suggestions.push({
|
||||
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) {
|
||||
title = { ...field, name: displayName };
|
||||
}
|
||||
keys[displayName] = true;
|
||||
|
||||
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