mirror of
https://github.com/grafana/grafana.git
synced 2025-09-23 07:23:04 +08:00
TimeSeries: Preserve RegExp series overrides when transforming from old graph (#36134)
This commit is contained in:
@ -155,6 +155,60 @@ Object {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Graph Migrations preserves series overrides using a regex alias 1`] = `
|
||||||
|
Object {
|
||||||
|
"fieldConfig": Object {
|
||||||
|
"defaults": Object {
|
||||||
|
"custom": Object {
|
||||||
|
"axisPlacement": "hidden",
|
||||||
|
"drawStyle": "line",
|
||||||
|
"fillOpacity": 60,
|
||||||
|
"gradientMode": "opacity",
|
||||||
|
"lineInterpolation": "stepAfter",
|
||||||
|
"lineWidth": 1,
|
||||||
|
"showPoints": "never",
|
||||||
|
"spanNulls": true,
|
||||||
|
},
|
||||||
|
"nullValueMode": "null",
|
||||||
|
"unit": "short",
|
||||||
|
},
|
||||||
|
"overrides": Array [
|
||||||
|
Object {
|
||||||
|
"matcher": Object {
|
||||||
|
"id": "byRegexp",
|
||||||
|
"options": "/^A-/",
|
||||||
|
},
|
||||||
|
"properties": Array [
|
||||||
|
Object {
|
||||||
|
"id": "color",
|
||||||
|
"value": Object {
|
||||||
|
"fixedColor": "rgba(165, 72, 170, 0.77)",
|
||||||
|
"mode": "fixed",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"options": Object {
|
||||||
|
"legend": Object {
|
||||||
|
"calcs": Array [
|
||||||
|
"mean",
|
||||||
|
"lastNotNull",
|
||||||
|
"max",
|
||||||
|
"min",
|
||||||
|
"sum",
|
||||||
|
],
|
||||||
|
"displayMode": "table",
|
||||||
|
"placement": "bottom",
|
||||||
|
},
|
||||||
|
"tooltip": Object {
|
||||||
|
"mode": "single",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Graph Migrations simple bars 1`] = `
|
exports[`Graph Migrations simple bars 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"fieldConfig": Object {
|
"fieldConfig": Object {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { PanelModel, FieldConfigSource } from '@grafana/data';
|
import { PanelModel, FieldConfigSource } from '@grafana/data';
|
||||||
import { graphPanelChangedHandler } from './migrations';
|
import { graphPanelChangedHandler } from './migrations';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
|
|
||||||
describe('Graph Migrations', () => {
|
describe('Graph Migrations', () => {
|
||||||
let prevFieldConfig: FieldConfigSource;
|
let prevFieldConfig: FieldConfigSource;
|
||||||
@ -67,6 +68,15 @@ describe('Graph Migrations', () => {
|
|||||||
expect(panel).toMatchSnapshot();
|
expect(panel).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('preserves series overrides using a regex alias', () => {
|
||||||
|
const old: any = {
|
||||||
|
angular: customColorRegex,
|
||||||
|
};
|
||||||
|
const panel = {} as PanelModel;
|
||||||
|
panel.options = graphPanelChangedHandler(panel, 'graph', old, prevFieldConfig);
|
||||||
|
expect(panel).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
describe('legend', () => {
|
describe('legend', () => {
|
||||||
test('without values', () => {
|
test('without values', () => {
|
||||||
const old: any = {
|
const old: any = {
|
||||||
@ -383,6 +393,9 @@ const customColor = {
|
|||||||
datasource: null,
|
datasource: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const customColorRegex = cloneDeep(customColor);
|
||||||
|
customColorRegex.seriesOverrides[0].alias = '/^A-/';
|
||||||
|
|
||||||
const stairscase = {
|
const stairscase = {
|
||||||
aliasColors: {},
|
aliasColors: {},
|
||||||
dashLength: 10,
|
dashLength: 10,
|
||||||
|
@ -112,9 +112,10 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
|
|||||||
if (!seriesOverride.alias) {
|
if (!seriesOverride.alias) {
|
||||||
continue; // the matcher config
|
continue; // the matcher config
|
||||||
}
|
}
|
||||||
|
const aliasIsRegex = seriesOverride.alias.startsWith('/') && seriesOverride.alias.endsWith('/');
|
||||||
const rule: ConfigOverrideRule = {
|
const rule: ConfigOverrideRule = {
|
||||||
matcher: {
|
matcher: {
|
||||||
id: FieldMatcherID.byName,
|
id: aliasIsRegex ? FieldMatcherID.byRegexp : FieldMatcherID.byName,
|
||||||
options: seriesOverride.alias,
|
options: seriesOverride.alias,
|
||||||
},
|
},
|
||||||
properties: [],
|
properties: [],
|
||||||
|
Reference in New Issue
Block a user