mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FieldOverrides: Clear displayName caching after applying field overrides (#93651)
* FieldOverrides: Clear displayName caching after applying field overrides * Remove old comment
This commit is contained in:
parent
5193318c56
commit
f04e032cf1
@ -309,6 +309,63 @@ describe('applyFieldOverrides', () => {
|
|||||||
expect(config.decimals).toEqual(1);
|
expect(config.decimals).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('displayName should be able to reference itself', () => {
|
||||||
|
const data = applyFieldOverrides({
|
||||||
|
data: [f0], // the frame
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {
|
||||||
|
displayName: '${__field.displayName} and more!',
|
||||||
|
},
|
||||||
|
overrides: [],
|
||||||
|
},
|
||||||
|
replaceVariables: (v, scopedVars) => {
|
||||||
|
const dataContext = scopedVars?.__dataContext?.value;
|
||||||
|
if (dataContext) {
|
||||||
|
// Trying to fake what would happen with the real interpolation function
|
||||||
|
return getFieldDisplayName(dataContext.field, dataContext.frame) + ' and more!';
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
},
|
||||||
|
theme: createTheme(),
|
||||||
|
fieldConfigRegistry: customFieldRegistry,
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
const valueColumn = data.fields[1];
|
||||||
|
const displayName = getFieldDisplayName(valueColumn, data);
|
||||||
|
|
||||||
|
expect(displayName).toEqual('value and more!');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displayName should be able to reference itself in an override', () => {
|
||||||
|
const data = applyFieldOverrides({
|
||||||
|
data: [f0], // the frame
|
||||||
|
fieldConfig: {
|
||||||
|
defaults: {},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
matcher: { id: FieldMatcherID.byName, options: 'value' },
|
||||||
|
properties: [{ id: 'displayName', value: '${__field.displayName} and more!' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
replaceVariables: (v, scopedVars) => {
|
||||||
|
const dataContext = scopedVars?.__dataContext?.value;
|
||||||
|
if (dataContext) {
|
||||||
|
// Trying to fake what would happen with the real interpolation function
|
||||||
|
return getFieldDisplayName(dataContext.field, dataContext.frame) + ' and more!';
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
},
|
||||||
|
theme: createTheme(),
|
||||||
|
fieldConfigRegistry: customFieldRegistry,
|
||||||
|
})[0];
|
||||||
|
|
||||||
|
const valueColumn = data.fields[1];
|
||||||
|
const displayName = getFieldDisplayName(valueColumn, data);
|
||||||
|
|
||||||
|
expect(displayName).toEqual('value and more!');
|
||||||
|
});
|
||||||
|
|
||||||
it('will apply set min/max when asked', () => {
|
it('will apply set min/max when asked', () => {
|
||||||
const data = applyFieldOverrides({
|
const data = applyFieldOverrides({
|
||||||
data: [f0], // the frame
|
data: [f0], // the frame
|
||||||
|
@ -162,6 +162,8 @@ export function applyFieldOverrides(options: ApplyFieldOverrideOptions): DataFra
|
|||||||
const { range, newGlobalRange } = calculateRange(config, field, globalRange, options.data!);
|
const { range, newGlobalRange } = calculateRange(config, field, globalRange, options.data!);
|
||||||
globalRange = newGlobalRange;
|
globalRange = newGlobalRange;
|
||||||
|
|
||||||
|
// Clear any cached displayName as it can change during field overrides process
|
||||||
|
field.state!.displayName = null;
|
||||||
field.state!.seriesIndex = seriesIndex;
|
field.state!.seriesIndex = seriesIndex;
|
||||||
field.state!.range = range;
|
field.state!.range = range;
|
||||||
field.type = type;
|
field.type = type;
|
||||||
|
Loading…
Reference in New Issue
Block a user