Commit 199f772b by Torkel Ödegaard Committed by GitHub

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

parent a02c6f2d
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment