AngularMigration: Clear old angular panel props when auto migrating (#66719)
* AngularMigration: Clear old angular panel props when auto migrating * Update test name
This commit is contained in:
+3
-1
@@ -2592,7 +2592,9 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
|
||||
],
|
||||
"public/app/features/dashboard/state/PanelModel.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
|
||||
@@ -352,6 +352,44 @@ describe('PanelModel', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when autoMigrateFrom angular to react', () => {
|
||||
const onPanelTypeChanged = (panel: PanelModel, prevPluginId: string, prevOptions: Record<string, any>) => {
|
||||
panel.fieldConfig = { defaults: { unit: 'bytes' }, overrides: [] };
|
||||
return { name: prevOptions.angular.oldName };
|
||||
};
|
||||
|
||||
const reactPlugin = getPanelPlugin({ id: 'timeseries' })
|
||||
.setPanelChangeHandler(onPanelTypeChanged as any)
|
||||
.useFieldConfig({
|
||||
disableStandardOptions: [FieldConfigProperty.Thresholds],
|
||||
})
|
||||
.setPanelOptions((builder) => {
|
||||
builder.addTextInput({
|
||||
name: 'Name',
|
||||
path: 'name',
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
model = new PanelModel({
|
||||
autoMigrateFrom: 'graph',
|
||||
oldName: 'old name',
|
||||
type: 'timeseries',
|
||||
});
|
||||
|
||||
model.pluginLoaded(reactPlugin);
|
||||
});
|
||||
|
||||
it('should run panel changed handler and remove old model props', () => {
|
||||
expect(model.options).toEqual({ name: 'old name' });
|
||||
expect(model.fieldConfig).toEqual({ defaults: { unit: 'bytes' }, overrides: [] });
|
||||
expect(model.autoMigrateFrom).toBe(undefined);
|
||||
expect(model.oldName).toBe(undefined);
|
||||
expect(model.plugin).toBe(reactPlugin);
|
||||
expect(model.type).toBe('timeseries');
|
||||
});
|
||||
});
|
||||
|
||||
describe('variables interpolation', () => {
|
||||
let panelQueryRunner: any;
|
||||
|
||||
|
||||
@@ -416,18 +416,22 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
|
||||
pluginLoaded(plugin: PanelPlugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
const version = getPluginVersion(plugin);
|
||||
|
||||
if (this.autoMigrateFrom) {
|
||||
const wasAngular = autoMigrateAngular[this.autoMigrateFrom] != null;
|
||||
this.callPanelTypeChangeHandler(
|
||||
plugin,
|
||||
this.autoMigrateFrom,
|
||||
this.getOptionsToRemember(), // old options
|
||||
wasAngular
|
||||
);
|
||||
const oldOptions = this.getOptionsToRemember();
|
||||
const prevPluginId = this.autoMigrateFrom;
|
||||
const newPluginId = this.type;
|
||||
|
||||
delete this.autoMigrateFrom;
|
||||
this.clearPropertiesBeforePluginChange();
|
||||
|
||||
// Need to set these again as they get cleared by the above function
|
||||
this.type = newPluginId;
|
||||
this.plugin = plugin;
|
||||
|
||||
this.callPanelTypeChangeHandler(plugin, prevPluginId, oldOptions, wasAngular);
|
||||
}
|
||||
|
||||
if (plugin.onPanelMigration) {
|
||||
|
||||
Reference in New Issue
Block a user