PanelPlugin: Add shouldMigrate callback to setMigrationHandler() (#103710)

This commit is contained in:
Leon Sorokin
2025-04-09 11:52:34 -05:00
committed by GitHub
parent 2f60d54648
commit 081d7dc3b2
+10 -1
View File
@@ -113,6 +113,7 @@ export class PanelPlugin<
panel: ComponentType<PanelProps<TOptions>> | null;
editor?: ComponentClass<PanelEditorProps<TOptions>>;
onPanelMigration?: PanelMigrationHandler<TOptions>;
shouldMigrate?: (panel: ComponentType<PanelProps<TOptions>> | null) => boolean;
onPanelTypeChanged?: PanelTypeChangedHandler<TOptions>;
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<TOptions>) {
setMigrationHandler(
handler: PanelMigrationHandler<TOptions>,
shouldMigrate?: (panel: ComponentType<PanelProps<TOptions>> | null) => boolean
) {
this.onPanelMigration = handler;
this.shouldMigrate = shouldMigrate;
return this;
}