diff --git a/packages/grafana-data/src/panel/PanelPlugin.ts b/packages/grafana-data/src/panel/PanelPlugin.ts index cb0325ac65c..b879066b469 100644 --- a/packages/grafana-data/src/panel/PanelPlugin.ts +++ b/packages/grafana-data/src/panel/PanelPlugin.ts @@ -113,6 +113,7 @@ export class PanelPlugin< panel: ComponentType> | null; editor?: ComponentClass>; onPanelMigration?: PanelMigrationHandler; + shouldMigrate?: (panel: ComponentType> | null) => boolean; onPanelTypeChanged?: PanelTypeChangedHandler; noPadding?: boolean; dataSupport: PanelPluginDataSupport = { @@ -201,10 +202,18 @@ export class PanelPlugin< * This function is called before the panel first loads if * the current version is different than the version that was saved. * + * If shouldMigrate is provided, it will be called regardless of whether + * the version has changed, and can explicitly opt into running the + * migration handler + * * This is a good place to support any changes to the options model */ - setMigrationHandler(handler: PanelMigrationHandler) { + setMigrationHandler( + handler: PanelMigrationHandler, + shouldMigrate?: (panel: ComponentType> | null) => boolean + ) { this.onPanelMigration = handler; + this.shouldMigrate = shouldMigrate; return this; }