diff --git a/public/app/plugins/panel/timeseries/migrations.test.ts b/public/app/plugins/panel/timeseries/migrations.test.ts index 0da3ecd6e53..8e678c64cd7 100644 --- a/public/app/plugins/panel/timeseries/migrations.test.ts +++ b/public/app/plugins/panel/timeseries/migrations.test.ts @@ -190,6 +190,48 @@ describe('Graph Migrations', () => { ] `); }); + + test('hide series', () => { + const panel = {} as PanelModel; + panel.fieldConfig = { + defaults: { + custom: { + hideFrom: { + tooltip: false, + graph: false, + legend: false, + }, + }, + }, + overrides: [ + { + matcher: { + id: 'byNames', + options: { + mode: 'exclude', + names: ['Bedroom'], + prefix: 'All except:', + readOnly: true, + }, + }, + properties: [ + { + id: 'custom.hideFrom', + value: { + graph: true, + legend: false, + tooltip: false, + }, + }, + ], + }, + ], + }; + + panel.options = graphPanelChangedHandler(panel, 'graph', {}); + expect(panel.fieldConfig.defaults.custom.hideFrom).toEqual({ viz: false, legend: false, tooltip: false }); + expect(panel.fieldConfig.overrides[0].properties[0].value).toEqual({ viz: true, legend: false, tooltip: false }); + }); }); }); diff --git a/public/app/plugins/panel/timeseries/migrations.ts b/public/app/plugins/panel/timeseries/migrations.ts index 9ac66b4e127..8a28461d94a 100644 --- a/public/app/plugins/panel/timeseries/migrations.ts +++ b/public/app/plugins/panel/timeseries/migrations.ts @@ -44,6 +44,9 @@ export const graphPanelChangedHandler = ( return options; } + //fixes graph -> viz renaming in custom.hideFrom field config by mutation. + migrateHideFrom(panel); + return {}; }; @@ -513,3 +516,24 @@ function getReducersFromLegend(obj: Record): string[] { } return ids; } + +function migrateHideFrom(panel: { + fieldConfig?: { defaults?: { custom?: { hideFrom?: any } }; overrides: ConfigOverrideRule[] }; +}) { + if (panel.fieldConfig?.defaults?.custom?.hideFrom?.graph !== undefined) { + panel.fieldConfig.defaults.custom.hideFrom.viz = panel.fieldConfig.defaults.custom.hideFrom.graph; + delete panel.fieldConfig.defaults.custom.hideFrom.graph; + } + if (panel.fieldConfig?.overrides) { + panel.fieldConfig.overrides = panel.fieldConfig.overrides.map((fr) => { + fr.properties = fr.properties.map((p) => { + if (p.id === 'custom.hideFrom' && p.value.graph) { + p.value.viz = p.value.graph; + delete p.value.graph; + } + return p; + }); + return fr; + }); + } +}