Add migration from old graph panel

This commit is contained in:
Dominik Prokop 2022-02-02 15:27:49 +01:00
parent 3833d79911
commit 33b5a90b66
3 changed files with 75 additions and 0 deletions

View File

@ -481,6 +481,56 @@ Object {
}
`;
exports[`Graph Migrations transforms should preserve "constant" transform 1`] = `
Object {
"defaults": Object {
"custom": Object {
"drawStyle": "points",
"spanNulls": false,
},
},
"overrides": Array [
Object {
"matcher": Object {
"id": "byName",
"options": "out",
},
"properties": Array [
Object {
"id": "custom.transform",
"value": "constant",
},
],
},
],
}
`;
exports[`Graph Migrations transforms should preserve "negative-Y" transform 1`] = `
Object {
"defaults": Object {
"custom": Object {
"drawStyle": "points",
"spanNulls": false,
},
},
"overrides": Array [
Object {
"matcher": Object {
"id": "byName",
"options": "out",
},
"properties": Array [
Object {
"id": "custom.transform",
"value": "negative-Y",
},
],
},
],
}
`;
exports[`Graph Migrations twoYAxis 1`] = `
Object {
"alert": undefined,

View File

@ -406,6 +406,24 @@ describe('Graph Migrations', () => {
expect(panel.fieldConfig).toMatchSnapshot();
});
});
describe('transforms', () => {
test.each(['negative-Y', 'constant'])('should preserve %p transform', (transform) => {
const old: any = {
angular: {
seriesOverrides: [
{
alias: 'out',
transform,
},
],
},
};
const panel = {} as PanelModel;
panel.options = graphPanelChangedHandler(panel, 'graph', old, prevFieldConfig);
expect(panel.fieldConfig).toMatchSnapshot();
});
});
});
const customColor = {

View File

@ -27,6 +27,7 @@ import {
ScaleDistribution,
StackingMode,
SortOrder,
GraphTransform,
} from '@grafana/schema';
import { TimeSeriesOptions } from './types';
import { omitBy, pickBy, isNil, isNumber, isString } from 'lodash';
@ -242,6 +243,12 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
},
});
break;
case 'transform':
rule.properties.push({
id: 'custom.transform',
value: v === 'negative-Y' ? GraphTransform.NegativeY : GraphTransform.Constant,
});
break;
default:
console.log('Ignore override migration:', seriesOverride.alias, p, v);
}