mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
only call onPanelMigration when the version actually changes (#16186)
* set the plugin version if there is a migration handler * only call panel migration if the version changes * set the version after change also * avoid NPE... check that we have options * destroy is based on the previous panel type, not the next one * Panels: Minor refactoring on panel plugin version code, #16186
This commit is contained in:
committed by
Torkel Ödegaard
parent
a8c50ed6ba
commit
e5c8375ec2
@@ -28,6 +28,7 @@ describe('PanelModel', () => {
|
||||
},
|
||||
};
|
||||
model = new PanelModel(modelJson);
|
||||
model.pluginLoaded(getPanelPlugin({ id: 'table', exports: { PanelCtrl: {} as any } }));
|
||||
});
|
||||
|
||||
it('should apply defaults', () => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { getNextRefIdChar } from 'app/core/utils/query';
|
||||
// Types
|
||||
import { DataQuery, TimeSeries, Threshold, ScopedVars, TableData } from '@grafana/ui';
|
||||
import { PanelPlugin } from 'app/types';
|
||||
import config from 'app/core/config';
|
||||
|
||||
export interface GridPos {
|
||||
x: number;
|
||||
@@ -244,14 +245,22 @@ export class PanelModel {
|
||||
});
|
||||
}
|
||||
|
||||
private getPluginVersion(plugin: PanelPlugin): string {
|
||||
return this.plugin && this.plugin.info.version ? this.plugin.info.version : config.buildInfo.version;
|
||||
}
|
||||
|
||||
pluginLoaded(plugin: PanelPlugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
const { reactPanel } = plugin.exports;
|
||||
|
||||
// Call PanelMigration Handler if the version has changed
|
||||
if (reactPanel && reactPanel.onPanelMigration) {
|
||||
this.options = reactPanel.onPanelMigration(this);
|
||||
this.pluginVersion = plugin.info ? plugin.info.version : '1.0.0';
|
||||
const version = this.getPluginVersion(plugin);
|
||||
if (version !== this.pluginVersion) {
|
||||
this.options = reactPanel.onPanelMigration(this);
|
||||
this.pluginVersion = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +271,7 @@ export class PanelModel {
|
||||
const reactPanel = newPlugin.exports.reactPanel;
|
||||
|
||||
// for angular panels we must remove all events and let angular panels do some cleanup
|
||||
if (!reactPanel) {
|
||||
if (this.plugin.exports.PanelCtrl) {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
@@ -283,11 +292,15 @@ export class PanelModel {
|
||||
this.plugin = newPlugin;
|
||||
|
||||
// Let panel plugins inspect options from previous panel and keep any that it can use
|
||||
const onPanelTypeChanged = reactPanel ? reactPanel.onPanelTypeChanged : null;
|
||||
if (onPanelTypeChanged) {
|
||||
this.options = this.options || {};
|
||||
const old = oldOptions ? oldOptions.options : {};
|
||||
Object.assign(this.options, onPanelTypeChanged(this.options, oldPluginId, old));
|
||||
if (reactPanel) {
|
||||
if (reactPanel.onPanelTypeChanged) {
|
||||
this.options = this.options || {};
|
||||
const old = oldOptions && oldOptions.options ? oldOptions.options : {};
|
||||
Object.assign(this.options, reactPanel.onPanelTypeChanged(this.options, oldPluginId, old));
|
||||
}
|
||||
if (reactPanel.onPanelMigration) {
|
||||
this.pluginVersion = this.getPluginVersion(newPlugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user