[v11.0.x] DashboardScene: Fixes react panels with old angular options (#86411)
This commit is contained in:
@@ -2418,6 +2418,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();
|
||||
|
||||
Reference in New Issue
Block a user