The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard-scene/serialization/angularMigration.ts

38 lines
1.6 KiB

import { defaults, cloneDeep } from 'lodash';
import { PanelModel as PanelModelFromData, PanelPlugin } from '@grafana/data';
import { autoMigrateAngular, PanelModel } from 'app/features/dashboard/state/PanelModel';
export function getAngularPanelMigrationHandler(oldModel: PanelModel) {
return function handleAngularPanelMigrations(panel: PanelModelFromData, plugin: PanelPlugin) {
if (plugin.angularPanelCtrl) {
panel.options = { angularOptions: oldModel.getOptionsToRemember() };
return;
}
if (!oldModel.options || Object.keys(oldModel.options).length === 0) {
defaults(panel, oldModel.getOptionsToRemember());
// Some plugins rely on being able to access targets to set up the fieldConfig when migrating from angular.
const targetClone = cloneDeep(oldModel.targets);
Object.defineProperty(panel, 'targets', {
get: function () {
console.warn(
'Accessing the targets property when migrating a panel plugin is deprecated. Changes to this property will be ignored.'
);
return targetClone;
},
});
}
if (oldModel.autoMigrateFrom) {
const wasAngular = autoMigrateAngular[oldModel.autoMigrateFrom] != null;
const oldOptions = oldModel.getOptionsToRemember();
const prevPluginId = oldModel.autoMigrateFrom;
if (plugin.onPanelTypeChanged) {
const prevOptions = wasAngular ? { angular: oldOptions } : oldOptions.options;
Object.assign(panel.options, plugin.onPanelTypeChanged(panel, prevPluginId, prevOptions, panel.fieldConfig));
}
}
};
}