AngularMigrate: Auto migrate graph to multiple panels (#83992)

* AngularMigrate: Auto migrate graph to multiple panels

* add unit test, and histogram migration

* add new cases to existing angular migration gdev dashboard

* fix stat feature toggle handling so all panels dont turn into stat panels 😅; fix betterer

* Use same function when clicking manual migrate button

* Update

---------

Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
This commit is contained in:
Torkel Ödegaard
2024-03-07 12:33:30 +01:00
committed by GitHub
parent 9c520acf9c
commit edd1864439
13 changed files with 560 additions and 163 deletions

View File

@@ -127,9 +127,6 @@ export class DashboardModel implements TimeModel {
options?: {
// By default this uses variables from redux state
getVariablesFromState?: GetVariables;
// Force the loader to migrate panels
autoMigrateOldPanels?: boolean;
}
) {
this.getVariablesFromState = options?.getVariablesFromState ?? getVariablesByKey;
@@ -169,59 +166,6 @@ export class DashboardModel implements TimeModel {
this.initMeta(meta);
this.updateSchema(data);
// Auto-migrate old angular panels
const shouldMigrateAllAngularPanels =
options?.autoMigrateOldPanels || !config.angularSupportEnabled || config.featureToggles.autoMigrateOldPanels;
const shouldMigrateExplicitAngularPanels =
config.featureToggles.autoMigrateGraphPanel ||
config.featureToggles.autoMigrateTablePanel ||
config.featureToggles.autoMigratePiechartPanel ||
config.featureToggles.autoMigrateWorldmapPanel ||
config.featureToggles.autoMigrateStatPanel;
// Handles both granular and all angular panel migration
if (shouldMigrateAllAngularPanels || shouldMigrateExplicitAngularPanels) {
for (const panel of this.panelIterator()) {
if (
!panel.autoMigrateFrom &&
panel.type === 'graph' &&
(config.featureToggles.autoMigrateGraphPanel || shouldMigrateAllAngularPanels)
) {
panel.autoMigrateFrom = panel.type;
panel.type = 'timeseries';
} else if (
!panel.autoMigrateFrom &&
panel.type === 'table-old' &&
(config.featureToggles.autoMigrateTablePanel || shouldMigrateAllAngularPanels)
) {
panel.autoMigrateFrom = panel.type;
panel.type = 'table';
} else if (
!panel.autoMigrateFrom &&
panel.type === 'grafana-piechart-panel' &&
(config.featureToggles.autoMigratePiechartPanel || shouldMigrateAllAngularPanels)
) {
panel.autoMigrateFrom = panel.type;
panel.type = 'piechart';
} else if (
!panel.autoMigrateFrom &&
panel.type === 'grafana-worldmap-panel' &&
(config.featureToggles.autoMigrateWorldmapPanel || shouldMigrateAllAngularPanels)
) {
panel.autoMigrateFrom = panel.type;
panel.type = 'geomap';
} else if (
!panel.autoMigrateFrom &&
(panel.type === 'singlestat' || panel.type === 'grafana-singlestat-panel') &&
(config.featureToggles.autoMigrateStatPanel || shouldMigrateAllAngularPanels)
) {
panel.autoMigrateFrom = panel.type;
panel.type = 'stat';
}
}
}
this.addBuiltInAnnotationQuery();
this.sortPanelsByGridPos();
this.panelsAffectedByVariableChange = null;