Skip to content

Commit

Permalink
Migrate timeseries hideFrom graph->viz (#33806) (#33928)
Browse files Browse the repository at this point in the history
* Migrate timeseries hideFrom graph->viz

* Remove unused test

* Adds describing comment
  • Loading branch information
oscarkilhed authored May 11, 2021
1 parent deeef32 commit 3741757
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
42 changes: 42 additions & 0 deletions public/app/plugins/panel/timeseries/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
});
});

Expand Down
24 changes: 24 additions & 0 deletions public/app/plugins/panel/timeseries/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const graphPanelChangedHandler = (
return options;
}

//fixes graph -> viz renaming in custom.hideFrom field config by mutation.
migrateHideFrom(panel);

return {};
};

Expand Down Expand Up @@ -513,3 +516,24 @@ function getReducersFromLegend(obj: Record<string, any>): 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;
});
}
}

0 comments on commit 3741757

Please sign in to comment.