StatPanel: Add migration for singlestat tableColumn to to fields property (#25901)

This commit is contained in:
Torkel Ödegaard
2020-07-01 08:52:49 +02:00
committed by GitHub
parent a02c6f2d36
commit 199f772bcf
2 changed files with 17 additions and 1 deletions
@@ -198,6 +198,18 @@ describe('sharedSingleStatMigrationHandler', () => {
expect(panel.fieldConfig.defaults.max).toBe(undefined);
});
it('change from angular singlestat with tableColumn set', () => {
const old: any = {
angular: {
tableColumn: 'info',
},
};
const panel = {} as PanelModel;
const newOptions = sharedSingleStatPanelChangedHandler(panel, 'singlestat', old);
expect(newOptions.reduceOptions.calcs).toEqual(['mean']);
expect(newOptions.reduceOptions.fields).toBe('/^info$/');
});
it('change from angular singlestat with no enabled gauge', () => {
const old: any = {
angular: {
@@ -55,7 +55,7 @@ function migrateFromAngularSinglestat(panel: PanelModel<Partial<SingleStatBaseOp
const prevPanel = prevOptions.angular;
const reducer = fieldReducers.getIfExists(prevPanel.valueName);
const options = {
fieldOptions: {
reduceOptions: {
calcs: [reducer ? reducer.id : ReducerID.mean],
},
orientation: VizOrientation.Horizontal,
@@ -67,6 +67,10 @@ function migrateFromAngularSinglestat(panel: PanelModel<Partial<SingleStatBaseOp
defaults.unit = prevPanel.format;
}
if (prevPanel.tableColumn) {
options.reduceOptions.fields = `/^${prevPanel.tableColumn}$/`;
}
if (prevPanel.nullPointMode) {
defaults.nullValueMode = prevPanel.nullPointMode;
}