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 7285804a25..d4d0a3388b 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 @@ -26,9 +26,10 @@ import TypeSelector from '@/app/components/workflow/nodes/_base/components/selec import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows' import { XClose } from '@/app/components/base/icons/src/vender/line/general' +const TRIGGER_DEFAULT_WIDTH = 227 + type Props = { className?: string - width?: number nodeId: string isShowNodeName: boolean readonly: boolean @@ -49,7 +50,6 @@ const getNodeInfoById = (nodes: any, id: string) => { const VarReferencePicker: FC = ({ nodeId, - width, readonly, className, isShowNodeName, @@ -62,6 +62,13 @@ const VarReferencePicker: FC = ({ filterVar = () => true, }) => { const { t } = useTranslation() + const triggerRef = useRef(null) + const [triggerWidth, setTriggerWidth] = useState(TRIGGER_DEFAULT_WIDTH) + useEffect(() => { + if (triggerRef.current) + setTriggerWidth(triggerRef.current.clientWidth) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [triggerRef.current]) const isChatMode = useIsChatMode() const [varKindType, setVarKindType] = useState(defaultVarKindType) @@ -176,8 +183,19 @@ const VarReferencePicker: FC = ({ onChange([], varKindType) }, [onChange, varKindType]) + const type = getVarType() + // 8(left/right-padding) + 14(icon) + 4 + 14 + 2 = 42 + 5 buff + const availableWidth = triggerWidth - 47 + const [maxNodeNameWidth, maxVarNameWidth, maxTypeWidth] = (() => { + const totalTextLength = ((outputVarNode?.title) + (varName) + type).length + const maxNodeNameWidth = Math.ceil(outputVarNode?.title.length / totalTextLength * availableWidth) + const maxVarNameWidth = Math.ceil(varName.length / totalTextLength * availableWidth) + const maxTypeWidth = Math.ceil(type.length / totalTextLength * availableWidth) + return [maxNodeNameWidth, maxVarNameWidth, maxTypeWidth] + })() + return ( -
+
= ({ return !isConstant ? setOpen(!open) : setControlFocus(Date.now()) }} className='!flex'> -
+
{isSupportConstantValue ?
{ e.stopPropagation() @@ -234,15 +252,21 @@ const VarReferencePicker: FC = ({ type={outputVarNode?.type || BlockEnum.Start} />
-
{outputVarNode?.title}
+
{outputVarNode?.title}
)}
{!hasValue && } -
{varName}
+
{varName}
-
{getVarType()}
+
{type}
) :
{t('workflow.common.setVarValuePlaceholder')}
} @@ -258,13 +282,12 @@ const VarReferencePicker: FC = ({ {!isConstant && ( )} diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/panel.tsx b/web/app/components/workflow/nodes/knowledge-retrieval/panel.tsx index eda02a025e..79bb04702a 100644 --- a/web/app/components/workflow/nodes/knowledge-retrieval/panel.tsx +++ b/web/app/components/workflow/nodes/knowledge-retrieval/panel.tsx @@ -57,7 +57,6 @@ const Panel: FC> = ({ value={inputs.query_variable_selector} onChange={handleQueryVarChange} filterVar={filterVar} - width={370} /> diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index 5079038c04..6f4a066ffb 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -157,7 +157,6 @@ const Panel: FC> = ({ value={inputs.context?.variable_selector || []} onChange={handleContextVarChange} filterVar={filterVar} - width={370} /> diff --git a/web/app/components/workflow/nodes/question-classifier/panel.tsx b/web/app/components/workflow/nodes/question-classifier/panel.tsx index b5c6b5e6eb..857f142c92 100644 --- a/web/app/components/workflow/nodes/question-classifier/panel.tsx +++ b/web/app/components/workflow/nodes/question-classifier/panel.tsx @@ -56,7 +56,6 @@ const Panel: FC> = ({ value={inputs.query_variable_selector} onChange={handleQueryVarChange} filterVar={filterVar} - width={387} /> = ({ = ({ onOpen={handleOpen(index)} onlyLeafNodeVar={onlyLeafNodeVar} filterVar={filterVar} - width={350} /> {!readonly && (