Extensions: Simplify the configure() function (#64958)

refactor: stop passing the extension to the `configure()` function
This commit is contained in:
Levente Balogh
2023-03-20 10:41:15 +01:00
committed by GitHub
parent 46cba5f993
commit 788e4a7f19
9 changed files with 33 additions and 70 deletions

View File

@@ -74,7 +74,7 @@ export type AppPluginExtensionLinkConfig<C extends object = object> = {
description: string;
placement: string;
path: string;
configure?: (extension: AppPluginExtensionLink, context?: C) => Partial<AppPluginExtensionLink> | undefined;
configure?: (context?: C) => Partial<AppPluginExtensionLink> | undefined;
};
export type AppPluginExtensionCommandConfig<C extends object = object> = {
@@ -82,7 +82,7 @@ export type AppPluginExtensionCommandConfig<C extends object = object> = {
description: string;
placement: string;
handler: (context?: C, helpers?: AppPluginExtensionCommandHelpers) => void;
configure?: (extension: AppPluginExtensionCommand, context?: C) => Partial<AppPluginExtensionCommand> | undefined;
configure?: (context?: C) => Partial<AppPluginExtensionCommand> | undefined;
};
export class AppPlugin<T extends KeyValue = KeyValue> extends GrafanaPlugin<AppPluginMeta<T>> {

View File

@@ -20,9 +20,12 @@ export function getPluginExtensions<T extends object = {}>(
const extensions = configureFuncs.reduce<PluginExtension[]>((result, configure) => {
const extension = configure(context);
// If the configure() function returns `undefined`, the extension is not displayed
if (extension) {
result.push(extension);
}
return result;
}, []);