single run form of human input

This commit is contained in:
JzoNg 2025-09-05 16:14:48 +08:00
parent ed16265eee
commit 22683fba3f
6 changed files with 73 additions and 5 deletions

View File

@ -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, any> = {
[BlockEnum.IterationStart]: undefined,
[BlockEnum.LoopStart]: undefined,
[BlockEnum.LoopEnd]: undefined,
[BlockEnum.HumanInput]: undefined,
[BlockEnum.HumanInput]: useHumanInputSingleRunFormParams,
}
const useSingleRunFormParamsHooks = (nodeType: BlockEnum) => {

View File

@ -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)

View File

@ -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<string, any>
getInputVars: (textList: string[]) => InputVar[]
setRunInputData: (data: Record<string, any>) => void
}
const useSingleRunFormParams = ({
id,
payload,
runInputData,
getInputVars,
setRunInputData,
}: Params) => {
const { t } = useTranslation()
const { inputs } = useNodeCrud<HumanInputNodeType>(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

View File

@ -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'
}

View File

@ -1027,6 +1027,9 @@ const translation = {
reasonContent: 'Human input required to proceed',
inputURL: 'Input URL:',
},
singleRun: {
label: 'Form variables',
},
},
},
tracing: {

View File

@ -1027,6 +1027,9 @@ const translation = {
reasonContent: '需要人类输入才能继续',
inputURL: '输入 URL ',
},
singleRun: {
label: '表单变量',
},
},
},
tracing: {