From ab9457c7fcf30b273ac1930c8234c03a00abced8 Mon Sep 17 00:00:00 2001 From: Junyi Date: Mon, 23 Oct 2023 21:15:55 +0800 Subject: [PATCH] refactor(plugin-workflow): add isAvailable check for adding node (#2898) --- .../@nocobase/plugin-workflow/src/client/AddButton.tsx | 6 +++++- .../plugins/@nocobase/plugin-workflow/src/client/index.tsx | 2 +- .../@nocobase/plugin-workflow/src/client/nodes/index.tsx | 7 ++++--- .../@nocobase/plugin-workflow/src/client/nodes/sql.tsx | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/AddButton.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/AddButton.tsx index f1adda24b..b3f2f0d0b 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/AddButton.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/AddButton.tsx @@ -28,7 +28,11 @@ export function AddButton({ upstream, branchIndex = null }: AddButtonProps) { ] .filter((group) => instructionList.filter((item) => item.group === group.key).length) .map((group) => { - const groupInstructions = instructionList.filter((item) => item.group === group.key); + const groupInstructions = instructionList.filter( + (item) => + item.group === group.key && + (item.isAvailable ? item.isAvailable({ workflow, upstream, branchIndex }) : true), + ); return { ...group, diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx index 7db5655b5..5b69499a3 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx @@ -3,7 +3,7 @@ export * from './Branch'; export * from './FlowContext'; export * from './nodes'; export { triggers, useTrigger, getTriggersOptions } from './triggers'; -export { useWorkflowVariableOptions } from './variable'; +export { useWorkflowVariableOptions, getCollectionFieldOptions } from './variable'; import { Plugin } from '@nocobase/client'; import React from 'react'; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx index 15a3e98a5..3115bbd66 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx @@ -13,14 +13,15 @@ import { useResourceActionContext, } from '@nocobase/client'; import { Registry, parse, str2moment } from '@nocobase/utils/client'; -import { Alert, App, Button, Dropdown, Input, Tag, message } from 'antd'; +import { App, Button, Dropdown, Input, Tag, message } from 'antd'; import React, { useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { AddButton } from '../AddButton'; import { useFlowContext } from '../FlowContext'; import { DrawerDescription } from '../components/DrawerDescription'; +import { StatusButton } from '../components/StatusButton'; import { JobStatusOptionsMap } from '../constants'; -import { NAMESPACE, lang } from '../locale'; +import { lang } from '../locale'; import useStyles from '../style'; import { VariableOption, VariableOptions } from '../variable'; import aggregate from './aggregate'; @@ -36,7 +37,6 @@ import query from './query'; import request from './request'; import sql from './sql'; import update from './update'; -import { StatusButton } from '../components/StatusButton'; export interface Instruction { title: string; @@ -54,6 +54,7 @@ export interface Instruction { useScopeVariables?(node, options?): VariableOptions; useInitializers?(node): SchemaInitializerItemOptions | null; initializers?: { [key: string]: any }; + isAvailable?(ctx: object): boolean; } export const instructions = new Registry(); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/sql.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/sql.tsx index 729a74c47..a9feed6a0 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/sql.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/sql.tsx @@ -8,7 +8,7 @@ import { useWorkflowVariableOptions } from '../variable'; export default { title: `{{t("SQL action", { ns: "${NAMESPACE}" })}}`, type: 'sql', - group: 'extended', + group: 'collection', description: `{{t("Execute a SQL statement in database.", { ns: "${NAMESPACE}" })}}`, fieldset: { sql: {