Commit e03c7bf1 by Torkel Ödegaard

Panels: Support angular -> react migration via PanelMigrationHandler

parent 20fec4d2
...@@ -21,10 +21,16 @@ export interface PanelEditorProps<T = any> { ...@@ -21,10 +21,16 @@ export interface PanelEditorProps<T = any> {
onOptionsChange: (options: T) => void; onOptionsChange: (options: T) => void;
} }
export interface PanelModel<TOptions = any> {
id: number;
options: TOptions;
pluginVersion?: string;
}
/** /**
* Called when a panel is first loaded with existing options * Called when a panel is first loaded with current panel model
*/ */
export type PanelMigrationHandler<TOptions = any> = (exiting: any, oldVersion?: string) => Partial<TOptions>; export type PanelMigrationHandler<TOptions = any> = (panel: PanelModel<TOptions>) => Partial<TOptions>;
/** /**
* Called before a panel is initalized * Called before a panel is initalized
......
...@@ -250,7 +250,7 @@ export class PanelModel { ...@@ -250,7 +250,7 @@ export class PanelModel {
const { reactPanel } = plugin.exports; const { reactPanel } = plugin.exports;
if (reactPanel && reactPanel.onPanelMigration) { if (reactPanel && reactPanel.onPanelMigration) {
this.options = reactPanel.onPanelMigration(this.options, this.pluginVersion); this.options = reactPanel.onPanelMigration(this);
this.pluginVersion = plugin.info ? plugin.info.version : '1.0.0'; this.pluginVersion = plugin.info ? plugin.info.version : '1.0.0';
} }
} }
......
import { ReactPanelPlugin, getStatsCalculators } from '@grafana/ui'; import { ReactPanelPlugin, getStatsCalculators, PanelModel } from '@grafana/ui';
import { SingleStatOptions, defaults, SingleStatBaseOptions } from './types'; import { SingleStatOptions, defaults, SingleStatBaseOptions } from './types';
import { SingleStatPanel } from './SingleStatPanel'; import { SingleStatPanel } from './SingleStatPanel';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
...@@ -21,12 +21,11 @@ export const singleStatBaseOptionsCheck = ( ...@@ -21,12 +21,11 @@ export const singleStatBaseOptionsCheck = (
return options; return options;
}; };
export const singleStatMigrationCheck = (exiting: any, oldVersion?: string) => { export const singleStatMigrationCheck = (panel: PanelModel<SingleStatOptions>) => {
const options = exiting as Partial<SingleStatOptions>; const options = panel.options;
if (options.valueOptions) { if (options.valueOptions) {
// 6.1 renamed some stats, This makes sure they are up to date // 6.1 renamed some stats, This makes sure they are up to date
// avg -> mean, current -> last, total -> sum // avg -> mean, current -> last, total -> sum
const { valueOptions } = options; const { valueOptions } = options;
if (valueOptions && valueOptions.stat) { if (valueOptions && valueOptions.stat) {
valueOptions.stat = getStatsCalculators([valueOptions.stat]).map(s => s.id)[0]; valueOptions.stat = getStatsCalculators([valueOptions.stat]).map(s => s.id)[0];
......
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