-
Notifications
You must be signed in to change notification settings - Fork 11.6k
/
getPanelPluginToMigrateTo.ts
79 lines (64 loc) · 2.21 KB
/
getPanelPluginToMigrateTo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import config from 'app/core/config';
import { autoMigrateRemovedPanelPlugins, autoMigrateAngular } from './PanelModel';
export function getPanelPluginToMigrateTo(panel: any, forceMigration?: boolean): string | undefined {
if (autoMigrateRemovedPanelPlugins[panel.type]) {
return autoMigrateRemovedPanelPlugins[panel.type];
}
const isUrlFeatureFlagEnabled = (featureName: string) => {
const flag = '__feature.' + featureName;
const urlParams = new URLSearchParams(window.location.search);
const featureFlagValue = urlParams.get(flag);
return featureFlagValue === 'true' || featureFlagValue === '';
};
// Auto-migrate old angular panels
const shouldMigrateAllAngularPanels =
forceMigration ||
!config.angularSupportEnabled ||
config.featureToggles.autoMigrateOldPanels ||
isUrlFeatureFlagEnabled('autoMigrateOldPanels') ||
isUrlFeatureFlagEnabled('disableAngular');
// Graph needs special logic as it can be migrated to multiple panels
if (
panel.type === 'graph' &&
(shouldMigrateAllAngularPanels ||
config.featureToggles.autoMigrateGraphPanel ||
isUrlFeatureFlagEnabled('autoMigrateGraphPanel'))
) {
if (panel.xaxis?.mode === 'series') {
return 'barchart';
}
if (panel.xaxis?.mode === 'histogram') {
return 'histogram';
}
return 'timeseries';
}
if (shouldMigrateAllAngularPanels) {
return autoMigrateAngular[panel.type];
}
if (
panel.type === 'table-old' &&
(config.featureToggles.autoMigrateTablePanel || isUrlFeatureFlagEnabled('autoMigrateTablePanel'))
) {
return 'table';
}
if (
panel.type === 'grafana-piechart-panel' &&
(config.featureToggles.autoMigratePiechartPanel || isUrlFeatureFlagEnabled('autoMigratePiechartPanel'))
) {
return 'piechart';
}
if (
panel.type === 'grafana-worldmap-panel' &&
(config.featureToggles.autoMigrateWorldmapPanel || isUrlFeatureFlagEnabled('autoMigrateWorldmapPanel'))
) {
return 'geomap';
}
if (
((panel.type === 'singlestat' || panel.type === 'grafana-singlestat-panel') &&
config.featureToggles.autoMigrateStatPanel) ||
isUrlFeatureFlagEnabled('autoMigrateStatPanel')
) {
return 'stat';
}
return undefined;
}