mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
FieldConfig: support overrides model (#20986)
This commit is contained in:
@@ -36,4 +36,30 @@ describe('sharedSingleStatMigrationHandler', () => {
|
||||
|
||||
expect(sharedSingleStatMigrationHandler(panel as any)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('Remove unused `overrides` option', () => {
|
||||
const panel = {
|
||||
options: {
|
||||
fieldOptions: {
|
||||
unit: 'watt',
|
||||
stat: 'last',
|
||||
decimals: 5,
|
||||
defaults: {
|
||||
min: 0,
|
||||
max: 100,
|
||||
mappings: [],
|
||||
},
|
||||
override: {
|
||||
min: 0,
|
||||
max: 100,
|
||||
mappings: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
title: 'Usage',
|
||||
type: 'bargauge',
|
||||
};
|
||||
|
||||
expect(sharedSingleStatMigrationHandler(panel as any)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
VizOrientation,
|
||||
PanelModel,
|
||||
FieldDisplayOptions,
|
||||
ConfigOverrideRule,
|
||||
} from '@grafana/data';
|
||||
|
||||
export interface SingleStatBaseOptions {
|
||||
@@ -33,7 +34,7 @@ export function sharedSingleStatPanelChangedHandler(
|
||||
const options = {
|
||||
fieldOptions: {
|
||||
defaults: {} as FieldConfig,
|
||||
override: {} as FieldConfig,
|
||||
overrides: [] as ConfigOverrideRule[],
|
||||
calcs: [reducer ? reducer.id : ReducerID.mean],
|
||||
},
|
||||
orientation: VizOrientation.Horizontal,
|
||||
@@ -110,6 +111,20 @@ export function sharedSingleStatMigrationHandler(panel: PanelModel<SingleStatBas
|
||||
options = moveThresholdsAndMappingsToField(options);
|
||||
}
|
||||
|
||||
if (previousVersion < 6.6) {
|
||||
// discard the old `override` options and enter an empty array
|
||||
if (options.fieldOptions && options.fieldOptions.override) {
|
||||
const { override, ...rest } = options.fieldOptions;
|
||||
options = {
|
||||
...options,
|
||||
fieldOptions: {
|
||||
...rest,
|
||||
overrides: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return options as SingleStatBaseOptions;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,22 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`sharedSingleStatMigrationHandler Remove unused \`overrides\` option 1`] = `
|
||||
Object {
|
||||
"fieldOptions": Object {
|
||||
"decimals": 5,
|
||||
"defaults": Object {
|
||||
"mappings": undefined,
|
||||
"max": 100,
|
||||
"min": 0,
|
||||
"thresholds": undefined,
|
||||
},
|
||||
"overrides": Array [],
|
||||
"stat": "last",
|
||||
"unit": "watt",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`sharedSingleStatMigrationHandler from old valueOptions model without pluginVersion 1`] = `
|
||||
Object {
|
||||
"fieldOptions": Object {
|
||||
|
||||
Reference in New Issue
Block a user