DashboardScene: Fixes react panels with old angular options (#86256)

* DashboardScene: Fixes react panels with old angular options

* Update
This commit is contained in:
Torkel Ödegaard
2024-04-17 08:05:23 +02:00
committed by GitHub
parent 5837def850
commit 989e7c2c11
3 changed files with 29 additions and 0 deletions
+3
View File
@@ -2520,6 +2520,9 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"]
],
"public/app/features/dashboard-scene/serialization/angularMigration.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"public/app/features/dashboard-scene/serialization/transformSaveModelToScene.test.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
@@ -33,4 +33,24 @@ describe('getAngularPanelMigrationHandler', () => {
expect(mutatedModel.fieldConfig).toEqual({ defaults: { unit: 'bytes' }, overrides: [] });
});
});
describe('Given a react panel with old angular properties', () => {
it('Should pass panel model with old angular properties', () => {
const reactPlugin = getPanelPlugin({ id: 'dashlist' });
const oldModel = new PanelModel({
angularProp: 'old name',
type: 'dashlist',
});
const mutatedModel: any = {
type: 'dashlist',
options: {},
};
getAngularPanelMigrationHandler(oldModel)(mutatedModel, reactPlugin);
expect(mutatedModel.angularProp).toEqual('old name');
});
});
});
@@ -1,3 +1,5 @@
import { defaults } from 'lodash';
import { PanelModel as PanelModelFromData, PanelPlugin } from '@grafana/data';
import { autoMigrateAngular, PanelModel } from 'app/features/dashboard/state/PanelModel';
@@ -8,6 +10,10 @@ export function getAngularPanelMigrationHandler(oldModel: PanelModel) {
return;
}
if (!oldModel.options || Object.keys(oldModel.options).length === 0) {
defaults(panel, oldModel.getOptionsToRemember());
}
if (oldModel.autoMigrateFrom) {
const wasAngular = autoMigrateAngular[oldModel.autoMigrateFrom] != null;
const oldOptions = oldModel.getOptionsToRemember();