From 081d7dc3b26d06c3f38a04f8450fb577680dac3f Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Wed, 9 Apr 2025 11:52:34 -0500 Subject: [PATCH] PanelPlugin: Add shouldMigrate callback to setMigrationHandler() (#103710) --- packages/grafana-data/src/panel/PanelPlugin.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; }