diff --git a/web/app/components/workflow/nodes/human-input/components/user-action.tsx b/web/app/components/workflow/nodes/human-input/components/user-action.tsx index 9b8684c976..7dcce2dce7 100644 --- a/web/app/components/workflow/nodes/human-input/components/user-action.tsx +++ b/web/app/components/workflow/nodes/human-input/components/user-action.tsx @@ -8,6 +8,7 @@ import type { UserAction } from '../types' import Input from '@/app/components/base/input' import Button from '@/app/components/base/button' import ButtonStyleDropdown from './button-style-dropdown' +import { genActionId } from '../utils' const i18nPrefix = 'workflow.nodes.humanInput' @@ -23,6 +24,21 @@ const UserActionItem: FC = ({ onDelete, }) => { const { t } = useTranslation() + + const handleIDChange = (e: React.ChangeEvent) => { + if (!e.target.value.trim()) + onChange({ ...data, id: genActionId() }) + else + onChange({ ...data, id: e.target.value }) + } + + const handleTextChange = (e: React.ChangeEvent) => { + if (!e.target.value.trim()) + onChange({ ...data, title: 'Button Text' }) + else + onChange({ ...data, title: e.target.value }) + } + return (
@@ -30,14 +46,14 @@ const UserActionItem: FC = ({ wrapperClassName='w-[120px]' value={data.id} placeholder={t(`${i18nPrefix}.userActions.actionNamePlaceholder`)} - onChange={e => onChange({ ...data, id: e.target.value })} + onChange={handleIDChange} />
onChange({ ...data, title: e.target.value })} + onChange={handleTextChange} />
> = ({ { handleUserActionAdd({ - id: 'Action', + id: genActionId(), title: 'Button Text', button_style: UserActionButtonType.Default, }) @@ -99,11 +100,11 @@ const Panel: FC> = ({ )} {inputs.user_actions.length > 0 && (
- {inputs.user_actions.map(action => ( + {inputs.user_actions.map((action, index) => ( handleUserActionChange(index, data)} onDelete={handleUserActionDelete} /> ))} diff --git a/web/app/components/workflow/nodes/human-input/use-config.ts b/web/app/components/workflow/nodes/human-input/use-config.ts index d132c0015f..8dd6ee1e8b 100644 --- a/web/app/components/workflow/nodes/human-input/use-config.ts +++ b/web/app/components/workflow/nodes/human-input/use-config.ts @@ -24,10 +24,9 @@ const useConfig = (id: string, payload: HumanInputNodeType) => { }) } - const handleUserActionChange = (updatedAction: UserAction) => { + const handleUserActionChange = (index: number, updatedAction: UserAction) => { const newActions = produce(inputs.user_actions, (draft) => { - const index = draft.findIndex(a => a.id === updatedAction.id) - if (index !== -1) + if (draft[index]) draft[index] = updatedAction }) setInputs({ diff --git a/web/app/components/workflow/nodes/human-input/utils.ts b/web/app/components/workflow/nodes/human-input/utils.ts new file mode 100644 index 0000000000..7e2f06c6a9 --- /dev/null +++ b/web/app/components/workflow/nodes/human-input/utils.ts @@ -0,0 +1,3 @@ +export const genActionId = () => { + return `a${Date.now().toString(36)}${Math.floor(Math.random() * 36).toString(36)}` +}