Skip to content

Commit 45bdeb7

Browse files
YIXIAO0iamjoel
authored andcommitted
feat: ifelse condition variable editable after selection (#11431)
1 parent af9060e commit 45bdeb7

File tree

5 files changed

+81
-6
lines changed

5 files changed

+81
-6
lines changed

web/app/components/workflow/nodes/_base/components/variable-tag.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const VariableTag = ({
7272
{isEnv && <Env className='shrink-0 mr-0.5 w-3.5 h-3.5 text-util-colors-violet-violet-600' />}
7373
{isChatVar && <BubbleX className='w-3.5 h-3.5 text-util-colors-teal-teal-700' />}
7474
<div
75-
className={cn('truncate text-text-accent font-medium', (isEnv || isChatVar) && 'text-text-secondary')}
75+
className={cn('truncate ml-0.5 text-text-accent font-medium', (isEnv || isChatVar) && 'text-text-secondary')}
7676
title={variableName}
7777
>
7878
{variableName}

web/app/components/workflow/nodes/_base/components/variable/var-reference-vars.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const VarReferenceVars: FC<Props> = ({
274274
{
275275
!hideSearch && (
276276
<>
277-
<div className={cn('mb-2 mx-1', searchBoxClassName)} onClick={e => e.stopPropagation()}>
277+
<div className={cn('mb-1 mx-2 mt-2', searchBoxClassName)} onClick={e => e.stopPropagation()}>
278278
<Input
279279
showLeftIcon
280280
showClearIcon

web/app/components/workflow/nodes/if-else/components/condition-list/condition-item.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import { FILE_TYPE_OPTIONS, SUB_VARIABLES, TRANSFER_METHOD } from '../../default
2525
import ConditionWrap from '../condition-wrap'
2626
import ConditionOperator from './condition-operator'
2727
import ConditionInput from './condition-input'
28-
import VariableTag from '@/app/components/workflow/nodes/_base/components/variable-tag'
28+
29+
import ConditionVarSelector from './condition-var-selector'
2930
import type {
3031
Node,
3132
NodeOutPutVar,
33+
ValueSelector,
3234
Var,
3335
} from '@/app/components/workflow/types'
3436
import { VarType } from '@/app/components/workflow/types'
@@ -82,6 +84,7 @@ const ConditionItem = ({
8284
const { t } = useTranslation()
8385

8486
const [isHovered, setIsHovered] = useState(false)
87+
const [open, setOpen] = useState(false)
8588

8689
const doUpdateCondition = useCallback((newCondition: Condition) => {
8790
if (isSubVariableKey)
@@ -190,6 +193,17 @@ const ConditionItem = ({
190193
onRemoveCondition?.(caseId, condition.id)
191194
}, [caseId, condition, conditionId, isSubVariableKey, onRemoveCondition, onRemoveSubVariableCondition])
192195

196+
const handleVarChange = useCallback((valueSelector: ValueSelector, varItem: Var) => {
197+
const newCondition = produce(condition, (draft) => {
198+
draft.variable_selector = valueSelector
199+
draft.varType = varItem.type
200+
draft.value = ''
201+
draft.comparison_operator = getOperators(varItem.type)[0]
202+
})
203+
doUpdateCondition(newCondition)
204+
setOpen(false)
205+
}, [condition, doUpdateCondition])
206+
193207
return (
194208
<div className={cn('flex mb-1 last-of-type:mb-0', className)}>
195209
<div className={cn(
@@ -221,11 +235,14 @@ const ConditionItem = ({
221235
/>
222236
)
223237
: (
224-
<VariableTag
238+
<ConditionVarSelector
239+
open={open}
240+
onOpenChange={setOpen}
225241
valueSelector={condition.variable_selector || []}
226242
varType={condition.varType}
227243
availableNodes={availableNodes}
228-
isShort
244+
nodesOutputVars={nodesOutputVars}
245+
onChange={handleVarChange}
229246
/>
230247
)}
231248

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '@/app/components/base/portal-to-follow-elem'
2+
import VariableTag from '@/app/components/workflow/nodes/_base/components/variable-tag'
3+
import VarReferenceVars from '@/app/components/workflow/nodes/_base/components/variable/var-reference-vars'
4+
import type { Node, NodeOutPutVar, ValueSelector, Var, VarType } from '@/app/components/workflow/types'
5+
6+
type ConditionVarSelectorProps = {
7+
open: boolean
8+
onOpenChange: (open: boolean) => void
9+
valueSelector: ValueSelector
10+
varType: VarType
11+
availableNodes: Node[]
12+
nodesOutputVars: NodeOutPutVar[]
13+
onChange: (valueSelector: ValueSelector, varItem: Var) => void
14+
}
15+
16+
const ConditionVarSelector = ({
17+
open,
18+
onOpenChange,
19+
valueSelector,
20+
varType,
21+
availableNodes,
22+
nodesOutputVars,
23+
onChange,
24+
}: ConditionVarSelectorProps) => {
25+
return (
26+
<PortalToFollowElem
27+
open={open}
28+
onOpenChange={onOpenChange}
29+
placement='bottom-start'
30+
offset={{
31+
mainAxis: 4,
32+
crossAxis: 0,
33+
}}
34+
>
35+
<PortalToFollowElemTrigger onClick={() => onOpenChange(!open)}>
36+
<div className="cursor-pointer">
37+
<VariableTag
38+
valueSelector={valueSelector}
39+
varType={varType}
40+
availableNodes={availableNodes}
41+
isShort
42+
/>
43+
</div>
44+
</PortalToFollowElemTrigger>
45+
<PortalToFollowElemContent className='z-[1000]'>
46+
<div className='w-[296px] bg-components-panel-bg-blur rounded-lg border-[0.5px] border-components-panel-border shadow-lg'>
47+
<VarReferenceVars
48+
vars={nodesOutputVars}
49+
isSupportFileVar
50+
onChange={onChange}
51+
/>
52+
</div>
53+
</PortalToFollowElemContent>
54+
</PortalToFollowElem>
55+
)
56+
}
57+
58+
export default ConditionVarSelector

web/app/components/workflow/nodes/if-else/components/condition-value.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const ConditionValue = ({
7373

7474
<div
7575
className={cn(
76-
'shrink-0 truncate text-xs font-medium text-text-accent',
76+
'shrink-0 ml-0.5 truncate text-xs font-medium text-text-accent',
7777
!notHasValue && 'max-w-[70px]',
7878
)}
7979
title={variableName}

0 commit comments

Comments
 (0)