Fix: Timeseries migration regex override (#49629) (#49837)

(cherry picked from commit 3d3cf74038)

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-05-30 17:32:23 +02:00
committed by GitHub
co-authored by Zoltán Bedi
parent c960454bd4
commit f8012e6789
3 changed files with 40 additions and 2 deletions
@@ -141,6 +141,21 @@ Object {
},
],
},
Object {
"matcher": Object {
"id": "byName",
"options": "B-series",
},
"properties": Array [
Object {
"id": "color",
"value": Object {
"fixedColor": "rgba(16, 72, 170, 0.77)",
"mode": "fixed",
},
},
],
},
],
},
"options": Object {
@@ -197,6 +212,21 @@ Object {
},
],
},
Object {
"matcher": Object {
"id": "byRegexp",
"options": "/.*Status: 2[0-9]+.*/i",
},
"properties": Array [
Object {
"id": "color",
"value": Object {
"fixedColor": "rgba(16, 72, 170, 0.77)",
"mode": "fixed",
},
},
],
},
],
},
"options": Object {
@@ -1,6 +1,6 @@
import { cloneDeep } from 'lodash';
import { PanelModel, FieldConfigSource } from '@grafana/data';
import { PanelModel, FieldConfigSource, FieldMatcherID } from '@grafana/data';
import { TooltipDisplayMode, SortOrder } from '@grafana/schema';
import { graphPanelChangedHandler } from './migrations';
@@ -78,6 +78,8 @@ describe('Graph Migrations', () => {
const panel = {} as PanelModel;
panel.options = graphPanelChangedHandler(panel, 'graph', old, prevFieldConfig);
expect(panel).toMatchSnapshot();
expect(panel.fieldConfig.overrides[0].matcher.id).toBe(FieldMatcherID.byRegexp);
expect(panel.fieldConfig.overrides[1].matcher.id).toBe(FieldMatcherID.byRegexp);
});
describe('legend', () => {
@@ -479,6 +481,11 @@ const customColor = {
alias: 'A-series',
color: 'rgba(165, 72, 170, 0.77)',
},
{
$$hashKey: 'object:13',
alias: 'B-series',
color: 'rgba(16, 72, 170, 0.77)',
},
],
spaceLength: 10,
steppedLine: true,
@@ -536,6 +543,7 @@ const customColor = {
const customColorRegex = cloneDeep(customColor);
customColorRegex.seriesOverrides[0].alias = '/^A-/';
customColorRegex.seriesOverrides[1].alias = '/.*Status: 2[0-9]+.*/i';
const stairscase = {
aliasColors: {},
@@ -119,7 +119,7 @@ export function flotToGraphOptions(angular: any): { fieldConfig: FieldConfigSour
if (!seriesOverride.alias) {
continue; // the matcher config
}
const aliasIsRegex = seriesOverride.alias.startsWith('/') && seriesOverride.alias.endsWith('/');
const aliasIsRegex = /^([/~@;%#'])(.*?)\1([gimsuy]*)$/.test(seriesOverride.alias);
const rule: ConfigOverrideRule = {
matcher: {
id: aliasIsRegex ? FieldMatcherID.byRegexp : FieldMatcherID.byName,