From 5888f53aab4375ad0d3ea807e55698136bf35326 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 23 Nov 2022 13:32:52 -0800 Subject: [PATCH] Angular: auto-migrate graph panel when angular is disabled (#59247) --- .../DashExportModal/DashboardExporter.test.ts | 1 + public/app/features/dashboard/state/PanelModel.ts | 10 ++++++++-- public/test/jest-setup.ts | 11 +++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts index 1452dd272c5..11621cb2f4b 100644 --- a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts +++ b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts @@ -37,6 +37,7 @@ jest.mock('@grafana/runtime', () => ({ featureToggles: { newVariables: false, }, + angularSupportEnabled: true, }, })); diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index 59294a57330..ebf120deb6b 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -237,11 +237,17 @@ export class PanelModel implements DataConfigSource, IPanelModel { switch (this.type) { case 'graph': - if (config?.featureToggles?.autoMigrateGraphPanels) { + if (config.featureToggles?.autoMigrateGraphPanels || !config.angularSupportEnabled) { this.autoMigrateFrom = this.type; this.type = 'timeseries'; } break; + case 'table-old': + if (!config.angularSupportEnabled) { + this.autoMigrateFrom = this.type; + this.type = 'table'; + } + break; case 'heatmap-new': this.autoMigrateFrom = this.type; this.type = 'heatmap'; @@ -416,7 +422,7 @@ export class PanelModel implements DataConfigSource, IPanelModel { const version = getPluginVersion(plugin); if (this.autoMigrateFrom) { - const wasAngular = this.autoMigrateFrom === 'graph'; + const wasAngular = this.autoMigrateFrom === 'graph' || this.autoMigrateFrom === 'table-old'; this.callPanelTypeChangeHandler( plugin, this.autoMigrateFrom, diff --git a/public/test/jest-setup.ts b/public/test/jest-setup.ts index ecfce62c267..cf9b5f735ab 100644 --- a/public/test/jest-setup.ts +++ b/public/test/jest-setup.ts @@ -7,6 +7,7 @@ import angular from 'angular'; import { configure } from 'enzyme'; import { EventBusSrv } from '@grafana/data'; +import { GrafanaBootConfig } from '@grafana/runtime'; import 'blob-polyfill'; import 'mutationobserver-shim'; import './mocks/workers'; @@ -18,6 +19,16 @@ const testAppEvents = new EventBusSrv(); const global = window as any; global.$ = global.jQuery = $; +// mock the default window.grafanaBootData settings +const settings: Partial = { + angularSupportEnabled: true, +}; +global.grafanaBootData = { + settings, + user: {}, + navTree: [], +}; + // https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom Object.defineProperty(global, 'matchMedia', { writable: true,