From fda19d3f0ed24134c5411d381bce885cba9430b0 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 25 Aug 2025 16:29:29 +0800 Subject: [PATCH] feat: in placeholder choose var --- .../plugins/hitl-input-block/input-field.tsx | 4 + .../plugins/hitl-input-block/pre-populate.tsx | 25 +- .../variable/var-reference-picker.tsx | 293 +++++++++--------- 3 files changed, 171 insertions(+), 151 deletions(-) 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 13d9d7ca04..29ecb69b34 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 @@ -37,6 +37,10 @@ const InputField: React.FC = ({ if (!draft.placeholder) draft.placeholder = { type: 'const', selector: [], value: '' } draft.placeholder[key] = value + if(key === 'selector') + draft.placeholder.type = 'variable' + else if(key === 'value') + draft.placeholder.type = 'const' }) setTempPayload(nextValue) } 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 index 818522cefc..0e67385be4 100644 --- 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 @@ -22,9 +22,11 @@ type Props = { const i18nPrefix = 'workflow.nodes.humanInput.insertInputField' type PlaceholderProps = { + varPickerProps: any onTypeClick: (isVariable: boolean) => void } const Placeholder = ({ + varPickerProps, onTypeClick, }: PlaceholderProps) => { const { t } = useTranslation() @@ -35,7 +37,12 @@ const Placeholder = ({ i18nKey={`${i18nPrefix}.prePopulateFieldPlaceholder`} components={{ staticContent: onTypeClick(false)}>{t(`${i18nPrefix}.staticContent`)}, - variable: onTypeClick(true)}>{t(`${i18nPrefix}.variable`)}, + variable: {t(`${i18nPrefix}.variable`)} + } + />, }} /> @@ -60,19 +67,23 @@ const PrePopulate: FC = ({ const [isFocus, setIsFocus] = useState(false) + const varPickerProps = { + nodeId, + value: valueSelector || [], + onChange: onValueSelectorChange!, + readonly: false, + zIndex: 1000, + } + const isShowPlaceholder = !onPlaceholderClicked && (isVariable ? (!valueSelector || valueSelector.length === 0) : !value) if (isShowPlaceholder) - return + return if (isVariable) { return (
diff --git a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx index 21eb9b8655..288cc218bb 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx +++ b/web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx @@ -61,6 +61,7 @@ type Props = { filterVar?: (payload: Var, valueSelector: ValueSelector) => boolean availableNodes?: Node[] availableVars?: NodeOutPutVar[] + trigger?: React.ReactNode isAddBtnTrigger?: boolean schema?: Partial valueTypePlaceHolder?: string @@ -92,6 +93,7 @@ const VarReferencePicker: FC = ({ filterVar = () => true, availableNodes: passedInAvailableNodes, availableVars: passedInAvailableVars, + trigger, isAddBtnTrigger, schema, valueTypePlaceHolder, @@ -392,156 +394,159 @@ const VarReferencePicker: FC = ({ onOpenChange={setOpen} placement={isAddBtnTrigger ? 'bottom-end' : 'bottom-start'} > - { - if (readonly) - return - !isConstant ? setOpen(!open) : setControlFocus(Date.now()) - }} className='group/picker-trigger-wrap relative !flex'> - <> - {isAddBtnTrigger - ? ( -
- -
- ) - : (
- {isSupportConstantValue - ?
{ - e.stopPropagation() - setOpen(false) - setControlFocus(Date.now()) - }} className='mr-1 flex h-full items-center space-x-1'> - -
{varKindTypes.find(item => item.value === varKindType)?.label}
- -
- } - popupClassName='top-8' - readonly={readonly} - value={varKindType} - options={varKindTypes} - onChange={handleVarKindTypeChange} - showChecked - /> + {trigger && setOpen(!open)}>{trigger}} + {!trigger && ( + { + if (readonly) + return + !isConstant ? setOpen(!open) : setControlFocus(Date.now()) + }} className='group/picker-trigger-wrap relative !flex'> + <> + {isAddBtnTrigger + ? ( +
+
- : (!hasValue &&
- -
)} - {isConstant - ? ( - void)} - schema={schemaWithDynamicSelect as CredentialFormSchema} - readonly={readonly} - isLoading={isLoading} - /> - ) - : ( - { - if (readonly) - return - !isConstant ? setOpen(!open) : setControlFocus(Date.now()) - }} - className='h-full grow' - > -
- -
- {hasValue - ? ( - <> - {isShowNodeName && !isEnv && !isChatVar && ( -
{ - if (e.metaKey || e.ctrlKey) { - e.stopPropagation() - handleVariableJump(outputVarNode?.id) - } - }}> -
- {outputVarNode?.type && } -
-
{outputVarNode?.title}
- -
- )} - {isShowAPart && ( -
- - -
- )} -
- {isLoading && } - -
{varName}
-
-
{type}
- {!isValidVar && } - - ) - :
- {isLoading ? ( -
- - {placeholder ?? t('workflow.common.setVarValuePlaceholder')} -
- ) : ( - placeholder ?? t('workflow.common.setVarValuePlaceholder') - )} -
} + ) + : (
+ {isSupportConstantValue + ?
{ + e.stopPropagation() + setOpen(false) + setControlFocus(Date.now()) + }} className='mr-1 flex h-full items-center space-x-1'> + +
{varKindTypes.find(item => item.value === varKindType)?.label}
+
- -
+ } + popupClassName='top-8' + readonly={readonly} + value={varKindType} + options={varKindTypes} + onChange={handleVarKindTypeChange} + showChecked + /> +
+ : (!hasValue &&
+ +
)} + {isConstant + ? ( + void)} + schema={schemaWithDynamicSelect as CredentialFormSchema} + readonly={readonly} + isLoading={isLoading} + /> + ) + : ( + { + if (readonly) + return + !isConstant ? setOpen(!open) : setControlFocus(Date.now()) + }} + className='h-full grow' + > +
+ +
+ {hasValue + ? ( + <> + {isShowNodeName && !isEnv && !isChatVar && ( +
{ + if (e.metaKey || e.ctrlKey) { + e.stopPropagation() + handleVariableJump(outputVarNode?.id) + } + }}> +
+ {outputVarNode?.type && } +
+
{outputVarNode?.title}
+ +
+ )} + {isShowAPart && ( +
+ + +
+ )} +
+ {isLoading && } + +
{varName}
+
+
{type}
+ {!isValidVar && } + + ) + :
+ {isLoading ? ( +
+ + {placeholder ?? t('workflow.common.setVarValuePlaceholder')} +
+ ) : ( + placeholder ?? t('workflow.common.setVarValuePlaceholder') + )} +
} +
+
+
-
+ + )} + {(hasValue && !readonly && !isInTable) && (
+ +
)} + {!hasValue && valueTypePlaceHolder && ( + )} - {(hasValue && !readonly && !isInTable) && (
-
)} - {!hasValue && valueTypePlaceHolder && ( - - )} -
)} - {!readonly && isInTable && ( - onRemove?.()} - /> - )} + {!readonly && isInTable && ( + onRemove?.()} + /> + )} - {!hasValue && typePlaceHolder && ( - - )} - -
+ {!hasValue && typePlaceHolder && ( + + )} + + + )}