Scenes: Fix angular migrations that are using the targets property on the old panel model (#96626)

Fix angular migrations using target
This commit is contained in:
Oscar Kilhed 2024-11-20 09:52:52 +01:00 committed by GitHub
parent be59a6113b
commit 5986b03a8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
import { defaults } from 'lodash';
import { defaults, cloneDeep } from 'lodash';
import { PanelModel as PanelModelFromData, PanelPlugin } from '@grafana/data';
import { autoMigrateAngular, PanelModel } from 'app/features/dashboard/state/PanelModel';
@ -12,6 +12,17 @@ export function getAngularPanelMigrationHandler(oldModel: PanelModel) {
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) {