Commit 6da2f132 by ryan

keep plugin versions

parent 82be27a4
...@@ -24,7 +24,7 @@ export interface PanelEditorProps<T = any> { ...@@ -24,7 +24,7 @@ export interface PanelEditorProps<T = any> {
/** /**
* Called when a panel is first loaded with existing options * Called when a panel is first loaded with existing options
*/ */
export type PanelMigrationHook<TOptions = any> = (options: any) => Partial<TOptions>; export type PanelMigrationHook<TOptions = any> = (exiting: any, oldVersion?: string) => Partial<TOptions>;
/** /**
* Called before a panel is initalized * Called before a panel is initalized
...@@ -40,7 +40,18 @@ export class ReactPanelPlugin<TOptions = any> { ...@@ -40,7 +40,18 @@ export class ReactPanelPlugin<TOptions = any> {
editor?: ComponentClass<PanelEditorProps<TOptions>>; editor?: ComponentClass<PanelEditorProps<TOptions>>;
defaults?: TOptions; defaults?: TOptions;
/**
* This function is called before the panel first loads if
* the current version is different than the version that was saved.
*
* This is a good place to support any changes to the options model
*/
onPanelMigration?: PanelMigrationHook<TOptions>; onPanelMigration?: PanelMigrationHook<TOptions>;
/**
* This function is called when the visualization was changed. This
* passes in the options that were used in the previous visualization
*/
onPanelTypeChanged?: PanelTypeChangedHook<TOptions>; onPanelTypeChanged?: PanelTypeChangedHook<TOptions>;
constructor(panel: ComponentClass<PanelProps<TOptions>>, defaults?: TOptions) { constructor(panel: ComponentClass<PanelProps<TOptions>>, defaults?: TOptions) {
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import config from 'app/core/config'; import config from 'app/core/config';
import classNames from 'classnames'; import classNames from 'classnames';
import get from 'lodash/get';
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
import { importPluginModule } from 'app/features/plugins/plugin_loader'; import { importPluginModule } from 'app/features/plugins/plugin_loader';
...@@ -99,12 +100,13 @@ export class DashboardPanel extends PureComponent<Props, State> { ...@@ -99,12 +100,13 @@ export class DashboardPanel extends PureComponent<Props, State> {
panel.changeType(pluginId, hook); panel.changeType(pluginId, hook);
} }
} else if (plugin.exports && plugin.exports.reactPanel && panel.options) { } else if (plugin.exports && plugin.exports.reactPanel && panel.options) {
const pluginVersion = get(plugin, 'info.version') || config.buildInfo.version;
const hook = plugin.exports.reactPanel.onPanelMigration; const hook = plugin.exports.reactPanel.onPanelMigration;
if (hook) { if (hook && panel.pluginVersion !== pluginVersion) {
panel.options = hook(panel.options); panel.options = hook(panel.options, panel.pluginVersion);
panel.pluginVersion = pluginVersion;
} }
} }
this.setState({ plugin, angularPanel: null }); this.setState({ plugin, angularPanel: null });
} }
} }
......
...@@ -58,6 +58,7 @@ const mustKeepProps: { [str: string]: boolean } = { ...@@ -58,6 +58,7 @@ const mustKeepProps: { [str: string]: boolean } = {
cacheTimeout: true, cacheTimeout: true,
cachedPluginOptions: true, cachedPluginOptions: true,
transparent: true, transparent: true,
pluginVersion: true,
}; };
const defaults: any = { const defaults: any = {
...@@ -87,6 +88,7 @@ export class PanelModel { ...@@ -87,6 +88,7 @@ export class PanelModel {
targets: DataQuery[]; targets: DataQuery[];
datasource: string; datasource: string;
thresholds?: any; thresholds?: any;
pluginVersion?: string;
snapshotData?: TimeSeries[] | [TableData]; snapshotData?: TimeSeries[] | [TableData];
timeFrom?: any; timeFrom?: any;
......
...@@ -21,12 +21,16 @@ export const singleStatBaseOptionsCheck = ( ...@@ -21,12 +21,16 @@ export const singleStatBaseOptionsCheck = (
return options; return options;
}; };
export const singleStatMigrationCheck = (options: Partial<SingleStatBaseOptions>) => { export const singleStatMigrationCheck = (exiting: any, oldVersion?: string) => {
// 6.1 renamed some stats, This makes sure they are up to date const options = exiting as Partial<SingleStatOptions>;
// avg -> mean, current -> last, total -> sum if (options.valueOptions) {
const { valueOptions } = options; // 6.1 renamed some stats, This makes sure they are up to date
if (valueOptions && valueOptions.stat) { // avg -> mean, current -> last, total -> sum
valueOptions.stat = getStatsCalculators([valueOptions.stat]).map(s => s.id)[0];
const { valueOptions } = options;
if (valueOptions && valueOptions.stat) {
valueOptions.stat = getStatsCalculators([valueOptions.stat]).map(s => s.id)[0];
}
} }
return options; return options;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment