diff --git a/packages/grafana-ui/src/types/panel.ts b/packages/grafana-ui/src/types/panel.ts index 6f008f31bcb..d6f3879d358 100644 --- a/packages/grafana-ui/src/types/panel.ts +++ b/packages/grafana-ui/src/types/panel.ts @@ -21,10 +21,16 @@ export interface PanelEditorProps { onOptionsChange: (options: T) => void; } +export interface PanelModel { + 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 = (exiting: any, oldVersion?: string) => Partial; +export type PanelMigrationHandler = (panel: PanelModel) => Partial; /** * Called before a panel is initalized diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index dc6b502f447..7e67e280241 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -250,7 +250,7 @@ export class PanelModel { const { reactPanel } = plugin.exports; 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'; } } diff --git a/public/app/plugins/panel/singlestat2/module.tsx b/public/app/plugins/panel/singlestat2/module.tsx index 55e777abfe0..d9a92727e5a 100644 --- a/public/app/plugins/panel/singlestat2/module.tsx +++ b/public/app/plugins/panel/singlestat2/module.tsx @@ -1,4 +1,4 @@ -import { ReactPanelPlugin, getStatsCalculators } from '@grafana/ui'; +import { ReactPanelPlugin, getStatsCalculators, PanelModel } from '@grafana/ui'; import { SingleStatOptions, defaults, SingleStatBaseOptions } from './types'; import { SingleStatPanel } from './SingleStatPanel'; import cloneDeep from 'lodash/cloneDeep'; @@ -21,12 +21,11 @@ export const singleStatBaseOptionsCheck = ( return options; }; -export const singleStatMigrationCheck = (exiting: any, oldVersion?: string) => { - const options = exiting as Partial; +export const singleStatMigrationCheck = (panel: PanelModel) => { + const options = panel.options; if (options.valueOptions) { // 6.1 renamed some stats, This makes sure they are up to date // avg -> mean, current -> last, total -> sum - const { valueOptions } = options; if (valueOptions && valueOptions.stat) { valueOptions.stat = getStatsCalculators([valueOptions.stat]).map(s => s.id)[0];