From 22683fba3f1b3e11b63fed251dc028a58ca08b3d Mon Sep 17 00:00:00 2001 From: JzoNg Date: Fri, 5 Sep 2025 16:14:48 +0800 Subject: [PATCH] single run form of human input --- .../workflow-panel/last-run/use-last-run.ts | 3 +- .../delivery-method/test-email-sender.tsx | 5 +- .../human-input/use-single-run-form-params.ts | 60 +++++++++++++++++++ .../workflow/nodes/human-input/utils.ts | 4 ++ web/i18n/en-US/workflow.ts | 3 + web/i18n/zh-Hans/workflow.ts | 3 + 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 web/app/components/workflow/nodes/human-input/use-single-run-form-params.ts diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts index c32c4d8444..804fc9f220 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts @@ -19,6 +19,7 @@ import useLoopSingleRunFormParams from '@/app/components/workflow/nodes/loop/use import useIfElseSingleRunFormParams from '@/app/components/workflow/nodes/if-else/use-single-run-form-params' import useVariableAggregatorSingleRunFormParams from '@/app/components/workflow/nodes/variable-assigner/use-single-run-form-params' import useVariableAssignerSingleRunFormParams from '@/app/components/workflow/nodes/assigner/use-single-run-form-params' +import useHumanInputSingleRunFormParams from '@/app/components/workflow/nodes/human-input/use-single-run-form-params' import useToolGetDataForCheckMore from '@/app/components/workflow/nodes/tool/use-get-data-for-check-more' import { VALUE_SELECTOR_DELIMITER as DELIMITER } from '@/config' @@ -57,7 +58,7 @@ const singleRunFormParamsHooks: Record = { [BlockEnum.IterationStart]: undefined, [BlockEnum.LoopStart]: undefined, [BlockEnum.LoopEnd]: undefined, - [BlockEnum.HumanInput]: undefined, + [BlockEnum.HumanInput]: useHumanInputSingleRunFormParams, } const useSingleRunFormParamsHooks = (nodeType: BlockEnum) => { diff --git a/web/app/components/workflow/nodes/human-input/components/delivery-method/test-email-sender.tsx b/web/app/components/workflow/nodes/human-input/components/delivery-method/test-email-sender.tsx index 75aa1c5953..e7e22ee35b 100644 --- a/web/app/components/workflow/nodes/human-input/components/delivery-method/test-email-sender.tsx +++ b/web/app/components/workflow/nodes/human-input/components/delivery-method/test-email-sender.tsx @@ -23,6 +23,7 @@ import type { import { InputVarType, VarType } from '@/app/components/workflow/types' import { fetchMembers } from '@/service/common' import { noop, unionBy } from 'lodash-es' +import { isOutput } from '../../utils' import cn from '@/utils/classnames' const i18nPrefix = 'workflow.nodes.humanInput' @@ -36,10 +37,6 @@ type EmailConfigureModalProps = { availableNodes?: Node[] } -const isOutput = (valueSelector: string[]) => { - return valueSelector[0] === '$output' -} - const getOriginVar = (valueSelector: string[], list: NodeOutPutVar[]) => { const targetVar = list.find(item => item.nodeId === valueSelector[0]) if (!targetVar) diff --git a/web/app/components/workflow/nodes/human-input/use-single-run-form-params.ts b/web/app/components/workflow/nodes/human-input/use-single-run-form-params.ts new file mode 100644 index 0000000000..94cd664dd9 --- /dev/null +++ b/web/app/components/workflow/nodes/human-input/use-single-run-form-params.ts @@ -0,0 +1,60 @@ +import { useTranslation } from 'react-i18next' +import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' +import type { InputVar } from '@/app/components/workflow/types' +import type { HumanInputNodeType } from './types' +import useNodeCrud from '../_base/hooks/use-node-crud' +import { useMemo } from 'react' +import { isOutput } from './utils' + +const i18nPrefix = 'workflow.nodes.humanInput' + +type Params = { + id: string, + payload: HumanInputNodeType, + runInputData: Record + getInputVars: (textList: string[]) => InputVar[] + setRunInputData: (data: Record) => void +} +const useSingleRunFormParams = ({ + id, + payload, + runInputData, + getInputVars, + setRunInputData, +}: Params) => { + const { t } = useTranslation() + const { inputs } = useNodeCrud(id, payload) + + const generatedInputs = useMemo(() => { + if (!inputs.form_content) + return [] + return getInputVars([inputs.form_content]).filter(item => !isOutput(item.value_selector || [])) + }, [inputs.form_content]) + + const forms = useMemo(() => { + const forms: FormProps[] = [{ + label: t(`${i18nPrefix}.singleRun.label`)!, + inputs: generatedInputs, + values: runInputData, + onChange: setRunInputData, + }] + return forms + }, [runInputData, setRunInputData, generatedInputs]) + + const getDependentVars = () => { + return generatedInputs.map((item) => { + // Guard against null/undefined variable to prevent app crash + if (!item.variable || typeof item.variable !== 'string') + return [] + + return item.variable.slice(1, -1).split('.') + }).filter(arr => arr.length > 0) + } + + return { + forms, + getDependentVars, + } +} + +export default useSingleRunFormParams diff --git a/web/app/components/workflow/nodes/human-input/utils.ts b/web/app/components/workflow/nodes/human-input/utils.ts index 7e2f06c6a9..b51c7104df 100644 --- a/web/app/components/workflow/nodes/human-input/utils.ts +++ b/web/app/components/workflow/nodes/human-input/utils.ts @@ -1,3 +1,7 @@ export const genActionId = () => { return `a${Date.now().toString(36)}${Math.floor(Math.random() * 36).toString(36)}` } + +export const isOutput = (valueSelector: string[]) => { + return valueSelector[0] === '$output' +} diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index 365d49eceb..4c66478241 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -1027,6 +1027,9 @@ const translation = { reasonContent: 'Human input required to proceed', inputURL: 'Input URL:', }, + singleRun: { + label: 'Form variables', + }, }, }, tracing: { diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index 369c197f92..fba9eaf063 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -1027,6 +1027,9 @@ const translation = { reasonContent: '需要人类输入才能继续', inputURL: '输入 URL :', }, + singleRun: { + label: '表单变量', + }, }, }, tracing: {