diff --git a/web/app/components/base/prompt-editor/plugins/hitl-input-block/component-ui.tsx b/web/app/components/base/prompt-editor/plugins/hitl-input-block/component-ui.tsx index cacda2acfe..139b75c581 100644 --- a/web/app/components/base/prompt-editor/plugins/hitl-input-block/component-ui.tsx +++ b/web/app/components/base/prompt-editor/plugins/hitl-input-block/component-ui.tsx @@ -35,7 +35,7 @@ const ComponentUI: FC = ({ selector: [], value: '', }, - }, + } as FormInputItem, onChange, onRename, onRemove, diff --git a/web/app/components/base/prompt-editor/plugins/hitl-input-block/input-field.tsx b/web/app/components/base/prompt-editor/plugins/hitl-input-block/input-field.tsx index 608b9fc786..5d032b06d9 100644 --- a/web/app/components/base/prompt-editor/plugins/hitl-input-block/input-field.tsx +++ b/web/app/components/base/prompt-editor/plugins/hitl-input-block/input-field.tsx @@ -5,17 +5,21 @@ import Input from '@/app/components/base/input' import Button from '../../../button' import { useTranslation } from 'react-i18next' import { getKeyboardKeyNameBySystem } from '@/app/components/workflow/utils' -import type { FormInputItem } from '@/app/components/workflow/nodes/human-input/types' +import type { FormInputItem, FormInputItemPlaceholder } from '@/app/components/workflow/nodes/human-input/types' +import PrePopulate from './pre-populate' +import produce from 'immer' const i18nPrefix = 'workflow.nodes.humanInput.insertInputField' type Props = { + nodeId: string isEdit: boolean payload: FormInputItem onChange: (newPayload: FormInputItem) => void onCancel: () => void } const InputField: React.FC = ({ + nodeId, isEdit, payload, onChange, @@ -26,6 +30,17 @@ const InputField: React.FC = ({ const handleSave = useCallback(() => { onChange(tempPayload) }, [tempPayload]) + const placeholderConfig = payload.placeholder + const handlePlaceholderChange = useCallback((key: keyof FormInputItemPlaceholder) => { + return (value: any) => { + const nextValue = produce(tempPayload, (draft) => { + if (!draft.placeholder) + draft.placeholder = { type: 'const', selector: [], value: '' } + draft.placeholder[key] = value + }) + setTempPayload(nextValue) + } + }, []) return (
{t(`${i18nPrefix}.title`)}
@@ -46,32 +61,23 @@ const InputField: React.FC = ({
{t(`${i18nPrefix}.prePopulateField`)}
- {/* -
- {t(`${i18nPrefix}.add`)} - - {t(`${i18nPrefix}.or`)} - - {t(`${i18nPrefix}.users`)} -
-
{t(`${i18nPrefix}.prePopulateFieldPlaceholderEnd`)}
-
- } - onChange={ - (newValue) => { - setTempPayload(prev => ({ ...prev, prePopulateField: newValue })) - } - } - /> */} - { setTempPayload(prev => ({ ...prev, placeholder: { ...(prev.placeholder || {}), value: e.target.value } } as any)) }} + /> */} + { + handlePlaceholderChange('type')(isVariable ? 'variable' : 'const') + }} + nodeId={nodeId} + valueSelector={placeholderConfig?.selector} + onValueSelectorChange={handlePlaceholderChange('selector')} + value={placeholderConfig?.value} + onValueChange={handlePlaceholderChange('value')} />
diff --git a/web/app/components/base/prompt-editor/plugins/hitl-input-block/pre-populate.tsx b/web/app/components/base/prompt-editor/plugins/hitl-input-block/pre-populate.tsx new file mode 100644 index 0000000000..7090909841 --- /dev/null +++ b/web/app/components/base/prompt-editor/plugins/hitl-input-block/pre-populate.tsx @@ -0,0 +1,82 @@ +'use client' +import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker' +import type { ValueSelector } from '@/app/components/workflow/types' +import type { FC } from 'react' +import React from 'react' +import { useTranslation } from 'react-i18next' +import Textarea from '../../../textarea' +import TagLabel from './tag-label' +import cn from '@/utils/classnames' +import { Variable02 } from '../../../icons/src/vender/solid/development' + +type Props = { + isVariable?: boolean + onIsVariableChange?: (isVariable: boolean) => void + nodeId: string + valueSelector?: ValueSelector + onValueSelectorChange?: (valueSelector: ValueSelector | string) => void + value?: string + onValueChange?: (value: string) => void +} + +const i18nPrefix = 'workflow.nodes.humanInput.insertInputField' + +const Placeholder = () => { + const { t } = useTranslation() + return ( +
+
+ {t(`${i18nPrefix}.add`)} + + {t(`${i18nPrefix}.or`)} + + {t(`${i18nPrefix}.users`)} +
+
{t(`${i18nPrefix}.prePopulateFieldPlaceholderEnd`)}
+
+ ) +} + +const PrePopulate: FC = ({ + isVariable = false, + onIsVariableChange, + nodeId, + valueSelector, + onValueSelectorChange, + value, + onValueChange, +}) => { + const { t } = useTranslation() + + const main = (() => { + const isShowPlaceholder = isVariable ? (!valueSelector || valueSelector.length === 0) : !value + if (isShowPlaceholder) + return + if (isVariable) { + return ( + + ) + } + return ( +