DataLinks: Fixes issue with data links not interpolating values with correct field config (#27622)
* DataLinks: Fixes issue with data links not having access to other fields field config
* Fixed test
(cherry picked from commit fcfd5cf0bc)
This commit is contained in:
committed by
Leonard Gram
parent
88905ca158
commit
0d8f2fbda8
@@ -19,6 +19,7 @@ import {
|
|||||||
GrafanaTheme,
|
GrafanaTheme,
|
||||||
InterpolateFunction,
|
InterpolateFunction,
|
||||||
ThresholdsMode,
|
ThresholdsMode,
|
||||||
|
ScopedVars,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { locationUtil, Registry } from '../utils';
|
import { locationUtil, Registry } from '../utils';
|
||||||
import { mockStandardProperties } from '../utils/tests/mockStandardProperties';
|
import { mockStandardProperties } from '../utils/tests/mockStandardProperties';
|
||||||
@@ -64,6 +65,16 @@ export const customFieldRegistry: FieldConfigOptionsRegistry = new Registry<Fiel
|
|||||||
return [property1, property2, property3, shouldApplyFalse, ...mockStandardProperties()];
|
return [property1, property2, property3, shouldApplyFalse, ...mockStandardProperties()];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
locationUtil.initialize({
|
||||||
|
getConfig: () => {
|
||||||
|
return { appSubUrl: '/subUrl' } as any;
|
||||||
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
buildParamsFromVariables: () => {},
|
||||||
|
// @ts-ignore
|
||||||
|
getTimeRangeForUrl: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
describe('Global MinMax', () => {
|
describe('Global MinMax', () => {
|
||||||
it('find global min max', () => {
|
it('find global min max', () => {
|
||||||
const f0 = new MutableDataFrame();
|
const f0 = new MutableDataFrame();
|
||||||
@@ -93,6 +104,7 @@ describe('applyFieldOverrides', () => {
|
|||||||
defaults: {
|
defaults: {
|
||||||
unit: 'xyz',
|
unit: 'xyz',
|
||||||
decimals: 2,
|
decimals: 2,
|
||||||
|
links: [{ title: 'link', url: '${__value.text}' }],
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
@@ -244,6 +256,28 @@ describe('applyFieldOverrides', () => {
|
|||||||
// Don't Automatically pick the min value
|
// Don't Automatically pick the min value
|
||||||
expect(config.min).toEqual(-20);
|
expect(config.min).toEqual(-20);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getLinks should use applied field config', () => {
|
||||||
|
const replaceVariablesCalls: any[] = [];
|
||||||
|
|
||||||
|
const data = applyFieldOverrides({
|
||||||
|
data: [f0], // the frame
|
||||||
|
fieldConfig: src as FieldConfigSource, // defaults + overrides
|
||||||
|
replaceVariables: ((value: string, variables: ScopedVars) => {
|
||||||
|
replaceVariablesCalls.push(variables);
|
||||||
|
return value;
|
||||||
|
}) as InterpolateFunction,
|
||||||
|
getDataSourceSettingsByUid: undefined as any,
|
||||||
|
theme: (undefined as any) as GrafanaTheme,
|
||||||
|
autoMinMax: true,
|
||||||
|
fieldConfigRegistry: customFieldRegistry,
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
data.fields[1].getLinks!({ valueRowIndex: 0 });
|
||||||
|
|
||||||
|
expect(data.fields[1].config.decimals).toEqual(1);
|
||||||
|
expect(replaceVariablesCalls[0].__value.value.text).toEqual('100.0');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setFieldConfigDefaults', () => {
|
describe('setFieldConfigDefaults', () => {
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ export function applyFieldOverrides(options: ApplyFieldOverrideOptions): DataFra
|
|||||||
}
|
}
|
||||||
|
|
||||||
return options.data.map((frame, index) => {
|
return options.data.map((frame, index) => {
|
||||||
|
// Need to define this new frame here as it's passed to the getLinkSupplier function inside the fields loop
|
||||||
|
const newFrame: DataFrame = { ...frame };
|
||||||
|
|
||||||
const scopedVars: ScopedVars = {
|
const scopedVars: ScopedVars = {
|
||||||
__series: { text: 'Series', value: { name: getFrameDisplayName(frame, index) } }, // might be missing
|
__series: { text: 'Series', value: { name: getFrameDisplayName(frame, index) } }, // might be missing
|
||||||
};
|
};
|
||||||
@@ -206,7 +209,7 @@ export function applyFieldOverrides(options: ApplyFieldOverrideOptions): DataFra
|
|||||||
|
|
||||||
// Attach data links supplier
|
// Attach data links supplier
|
||||||
f.getLinks = getLinksSupplier(
|
f.getLinks = getLinksSupplier(
|
||||||
frame,
|
newFrame,
|
||||||
f,
|
f,
|
||||||
fieldScopedVars,
|
fieldScopedVars,
|
||||||
context.replaceVariables,
|
context.replaceVariables,
|
||||||
@@ -220,10 +223,8 @@ export function applyFieldOverrides(options: ApplyFieldOverrideOptions): DataFra
|
|||||||
return f;
|
return f;
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
newFrame.fields = fields;
|
||||||
...frame,
|
return newFrame;
|
||||||
fields,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user