diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/AddNodeContext.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/AddNodeContext.tsx index 798fbbc300..2b534da98c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/AddNodeContext.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/AddNodeContext.tsx @@ -45,15 +45,10 @@ export function AddButton(props: AddButtonProps) { const instructionList = Array.from(engine.instructions.getValues()) as Instruction[]; const { styles } = useStyles(); const { onCreate, creating } = useAddNodeContext(); + const groupOptions = engine.useInstructionGroupOptions(); const groups = useMemo(() => { - const result = [ - { key: 'control', label: `{{t("Control", { ns: "${NAMESPACE}" })}}` }, - { key: 'calculation', label: `{{t("Calculation", { ns: "${NAMESPACE}" })}}` }, - { key: 'collection', label: `{{t("Collection operations", { ns: "${NAMESPACE}" })}}` }, - { key: 'manual', label: `{{t("Manual", { ns: "${NAMESPACE}" })}}` }, - { key: 'extended', label: `{{t("Extended types", { ns: "${NAMESPACE}" })}}` }, - ] + return groupOptions .map((group) => { const groupInstructions = instructionList.filter( (item) => @@ -68,15 +63,13 @@ export function AddButton(props: AddButtonProps) { role: 'button', 'aria-label': item.type, key: item.type, - label: item.title, + label: compile(item.title), icon: item.icon, })), }; }) .filter((group) => group.children.length); - - return compile(result); - }, [branchIndex, compile, engine, instructionList, upstream, workflow]); + }, [branchIndex, compile, engine, groupOptions, instructionList, upstream, workflow]); const onClick = useCallback( async ({ keyPath }) => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx index 688e4ba489..ea65088a94 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx @@ -39,9 +39,15 @@ const workflowConfigSettings = { Component: BindWorkflowConfig, }; +type InstructionGroup = { + key?: string; + label: string; +}; + export default class PluginWorkflowClient extends Plugin { triggers = new Registry(); instructions = new Registry(); + instructionGroups = new Registry(); systemVariables = new Registry(); taskTypes = new Registry(); @@ -58,6 +64,16 @@ export default class PluginWorkflowClient extends Plugin { .sort((a, b) => a.label.localeCompare(b.label)); }; + useInstructionGroupOptions = () => { + const compile = useCompile(); + return Array.from(this.instructionGroups.getEntities()) + .map(([key, { label }]) => ({ + key, + label: compile(label), + })) + .sort((a, b) => a.label.localeCompare(b.label)); + }; + isWorkflowSync(workflow) { return this.triggers.get(workflow.type)?.sync ?? workflow.sync; } @@ -82,6 +98,10 @@ export default class PluginWorkflowClient extends Plugin { } } + registerInstructionGroup(key: string, group: InstructionGroup) { + this.instructionGroups.register(key, group); + } + registerSystemVariable(option: VariableOption) { this.systemVariables.register(option.key, option); } @@ -128,6 +148,21 @@ export default class PluginWorkflowClient extends Plugin { this.app.schemaSettingsManager.addItem('actionSettings:delete', 'workflowConfig', workflowConfigSettings); this.app.schemaSettingsManager.addItem('actionSettings:bulkEditSubmit', 'workflowConfig', workflowConfigSettings); + this.registerInstructionGroup('control', { key: 'control', label: `{{t("Control", { ns: "${NAMESPACE}" })}}` }); + this.registerInstructionGroup('calculation', { + key: 'calculation', + label: `{{t("Calculation", { ns: "${NAMESPACE}" })}}`, + }); + this.registerInstructionGroup('collection', { + key: 'collection', + label: `{{t("Collection operations", { ns: "${NAMESPACE}" })}}`, + }); + this.registerInstructionGroup('manual', { key: 'manual', label: `{{t("Manual", { ns: "${NAMESPACE}" })}}` }); + this.registerInstructionGroup('extended', { + key: 'extended', + label: `{{t("Extended types", { ns: "${NAMESPACE}" })}}`, + }); + this.registerTrigger('collection', CollectionTrigger); this.registerTrigger('schedule', ScheduleTrigger);