Skip to content

Commit

Permalink
TimeSeries: Preserve RegExp series overrides when transforming from o…
Browse files Browse the repository at this point in the history
…ld graph (#36134) (#36158)

(cherry picked from commit b8b90ec)

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
  • Loading branch information
grafanabot and ashharrison90 committed Jun 25, 2021
1 parent 6007419 commit b5b8d22
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Expand Up @@ -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`] = `
Object {
"fieldConfig": Object {
Expand Down
13 changes: 13 additions & 0 deletions public/app/plugins/panel/timeseries/migrations.test.ts
@@ -1,5 +1,6 @@
import { PanelModel, FieldConfigSource } from '@grafana/data';
import { graphPanelChangedHandler } from './migrations';
import { cloneDeep } from 'lodash';

describe('Graph Migrations', () => {
let prevFieldConfig: FieldConfigSource;
Expand Down Expand Up @@ -67,6 +68,15 @@ describe('Graph Migrations', () => {
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', () => {
test('without values', () => {
const old: any = {
Expand Down Expand Up @@ -383,6 +393,9 @@ const customColor = {
datasource: null,
};

const customColorRegex = cloneDeep(customColor);
customColorRegex.seriesOverrides[0].alias = '/^A-/';

const stairscase = {
aliasColors: {},
dashLength: 10,
Expand Down
3 changes: 2 additions & 1 deletion public/app/plugins/panel/timeseries/migrations.ts
Expand Up @@ -112,9 +112,10 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
if (!seriesOverride.alias) {
continue; // the matcher config
}
const aliasIsRegex = seriesOverride.alias.startsWith('/') && seriesOverride.alias.endsWith('/');
const rule: ConfigOverrideRule = {
matcher: {
id: FieldMatcherID.byName,
id: aliasIsRegex ? FieldMatcherID.byRegexp : FieldMatcherID.byName,
options: seriesOverride.alias,
},
properties: [],
Expand Down

0 comments on commit b5b8d22

Please sign in to comment.