FieldConfig: support overrides model (#20986)

This commit is contained in:
Ryan McKinley
2019-12-12 14:55:30 -08:00
committed by GitHub
parent 1f73e2aadf
commit 1aa39ee458
12 changed files with 418 additions and 129 deletions

View File

@@ -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();
});
});

View File

@@ -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;
}

View File

@@ -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 {