diff --git a/app/actions/index.ts b/app/actions/index.ts index 6985dc934..b13eaa99b 100644 --- a/app/actions/index.ts +++ b/app/actions/index.ts @@ -10,6 +10,10 @@ import { MenuItemWithChildren, } from "~/types"; +function resolve(value: any, context: ActionContext): T { + return typeof value === "function" ? value(context) : value; +} + export function createAction(definition: Optional): Action { return { ...definition, @@ -21,18 +25,10 @@ export function actionToMenuItem( action: Action, context: ActionContext ): MenuItemButton | MenuItemWithChildren { - function resolve(value: any): T { - if (typeof value === "function") { - return value(context); - } - - return value; - } - - const resolvedIcon = resolve>(action.icon); - const resolvedChildren = resolve(action.children); + const resolvedIcon = resolve>(action.icon, context); + const resolvedChildren = resolve(action.children, context); const visible = action.visible ? action.visible(context) : true; - const title = resolve(action.name); + const title = resolve(action.name, context); const icon = resolvedIcon && action.iconInContextMenu !== false ? React.cloneElement(resolvedIcon, { @@ -69,23 +65,15 @@ export function actionToKBar( action: Action, context: ActionContext ): CommandBarAction[] { - function resolve(value: any): T { - if (typeof value === "function") { - return value(context); - } - - return value; - } - if (typeof action.visible === "function" && !action.visible(context)) { return []; } - const resolvedIcon = resolve>(action.icon); - const resolvedChildren = resolve(action.children); - const resolvedSection = resolve(action.section); - const resolvedName = resolve(action.name); - const resolvedPlaceholder = resolve(action.placeholder); + const resolvedIcon = resolve>(action.icon, context); + const resolvedChildren = resolve(action.children, context); + const resolvedSection = resolve(action.section, context); + const resolvedName = resolve(action.name, context); + const resolvedPlaceholder = resolve(action.placeholder, context); const children = resolvedChildren ? flattenDeep(resolvedChildren.map((a) => actionToKBar(a, context))).filter( (a) => !!a