| {isEnv && <Env className='shrink-0 mr-0.5 w-3.5 h-3.5 text-util-colors-violet-violet-600' />} | {isEnv && <Env className='shrink-0 mr-0.5 w-3.5 h-3.5 text-util-colors-violet-violet-600' />} | ||||
| {isChatVar && <BubbleX className='w-3.5 h-3.5 text-util-colors-teal-teal-700' />} | {isChatVar && <BubbleX className='w-3.5 h-3.5 text-util-colors-teal-teal-700' />} | ||||
| <div | <div | ||||
| className={cn('truncate text-text-accent font-medium', (isEnv || isChatVar) && 'text-text-secondary')} | |||||
| className={cn('truncate ml-0.5 text-text-accent font-medium', (isEnv || isChatVar) && 'text-text-secondary')} | |||||
| title={variableName} | title={variableName} | ||||
| > | > | ||||
| {variableName} | {variableName} |
| { | { | ||||
| !hideSearch && ( | !hideSearch && ( | ||||
| <> | <> | ||||
| <div className={cn('mb-2 mx-1', searchBoxClassName)} onClick={e => e.stopPropagation()}> | |||||
| <div className={cn('mb-1 mx-2 mt-2', searchBoxClassName)} onClick={e => e.stopPropagation()}> | |||||
| <Input | <Input | ||||
| showLeftIcon | showLeftIcon | ||||
| showClearIcon | showClearIcon |
| import ConditionWrap from '../condition-wrap' | import ConditionWrap from '../condition-wrap' | ||||
| import ConditionOperator from './condition-operator' | import ConditionOperator from './condition-operator' | ||||
| import ConditionInput from './condition-input' | import ConditionInput from './condition-input' | ||||
| import VariableTag from '@/app/components/workflow/nodes/_base/components/variable-tag' | |||||
| import ConditionVarSelector from './condition-var-selector' | |||||
| import type { | import type { | ||||
| Node, | Node, | ||||
| NodeOutPutVar, | NodeOutPutVar, | ||||
| ValueSelector, | |||||
| Var, | Var, | ||||
| } from '@/app/components/workflow/types' | } from '@/app/components/workflow/types' | ||||
| import { VarType } from '@/app/components/workflow/types' | import { VarType } from '@/app/components/workflow/types' | ||||
| const { t } = useTranslation() | const { t } = useTranslation() | ||||
| const [isHovered, setIsHovered] = useState(false) | const [isHovered, setIsHovered] = useState(false) | ||||
| const [open, setOpen] = useState(false) | |||||
| const doUpdateCondition = useCallback((newCondition: Condition) => { | const doUpdateCondition = useCallback((newCondition: Condition) => { | ||||
| if (isSubVariableKey) | if (isSubVariableKey) | ||||
| onRemoveCondition?.(caseId, condition.id) | onRemoveCondition?.(caseId, condition.id) | ||||
| }, [caseId, condition, conditionId, isSubVariableKey, onRemoveCondition, onRemoveSubVariableCondition]) | }, [caseId, condition, conditionId, isSubVariableKey, onRemoveCondition, onRemoveSubVariableCondition]) | ||||
| const handleVarChange = useCallback((valueSelector: ValueSelector, varItem: Var) => { | |||||
| const newCondition = produce(condition, (draft) => { | |||||
| draft.variable_selector = valueSelector | |||||
| draft.varType = varItem.type | |||||
| draft.value = '' | |||||
| draft.comparison_operator = getOperators(varItem.type)[0] | |||||
| }) | |||||
| doUpdateCondition(newCondition) | |||||
| setOpen(false) | |||||
| }, [condition, doUpdateCondition]) | |||||
| return ( | return ( | ||||
| <div className={cn('flex mb-1 last-of-type:mb-0', className)}> | <div className={cn('flex mb-1 last-of-type:mb-0', className)}> | ||||
| <div className={cn( | <div className={cn( | ||||
| /> | /> | ||||
| ) | ) | ||||
| : ( | : ( | ||||
| <VariableTag | |||||
| <ConditionVarSelector | |||||
| open={open} | |||||
| onOpenChange={setOpen} | |||||
| valueSelector={condition.variable_selector || []} | valueSelector={condition.variable_selector || []} | ||||
| varType={condition.varType} | varType={condition.varType} | ||||
| availableNodes={availableNodes} | availableNodes={availableNodes} | ||||
| isShort | |||||
| nodesOutputVars={nodesOutputVars} | |||||
| onChange={handleVarChange} | |||||
| /> | /> | ||||
| )} | )} | ||||
| import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger } from '@/app/components/base/portal-to-follow-elem' | |||||
| import VariableTag from '@/app/components/workflow/nodes/_base/components/variable-tag' | |||||
| import VarReferenceVars from '@/app/components/workflow/nodes/_base/components/variable/var-reference-vars' | |||||
| import type { Node, NodeOutPutVar, ValueSelector, Var, VarType } from '@/app/components/workflow/types' | |||||
| type ConditionVarSelectorProps = { | |||||
| open: boolean | |||||
| onOpenChange: (open: boolean) => void | |||||
| valueSelector: ValueSelector | |||||
| varType: VarType | |||||
| availableNodes: Node[] | |||||
| nodesOutputVars: NodeOutPutVar[] | |||||
| onChange: (valueSelector: ValueSelector, varItem: Var) => void | |||||
| } | |||||
| const ConditionVarSelector = ({ | |||||
| open, | |||||
| onOpenChange, | |||||
| valueSelector, | |||||
| varType, | |||||
| availableNodes, | |||||
| nodesOutputVars, | |||||
| onChange, | |||||
| }: ConditionVarSelectorProps) => { | |||||
| return ( | |||||
| <PortalToFollowElem | |||||
| open={open} | |||||
| onOpenChange={onOpenChange} | |||||
| placement='bottom-start' | |||||
| offset={{ | |||||
| mainAxis: 4, | |||||
| crossAxis: 0, | |||||
| }} | |||||
| > | |||||
| <PortalToFollowElemTrigger onClick={() => onOpenChange(!open)}> | |||||
| <div className="cursor-pointer"> | |||||
| <VariableTag | |||||
| valueSelector={valueSelector} | |||||
| varType={varType} | |||||
| availableNodes={availableNodes} | |||||
| isShort | |||||
| /> | |||||
| </div> | |||||
| </PortalToFollowElemTrigger> | |||||
| <PortalToFollowElemContent className='z-[1000]'> | |||||
| <div className='w-[296px] bg-components-panel-bg-blur rounded-lg border-[0.5px] border-components-panel-border shadow-lg'> | |||||
| <VarReferenceVars | |||||
| vars={nodesOutputVars} | |||||
| isSupportFileVar | |||||
| onChange={onChange} | |||||
| /> | |||||
| </div> | |||||
| </PortalToFollowElemContent> | |||||
| </PortalToFollowElem> | |||||
| ) | |||||
| } | |||||
| export default ConditionVarSelector |
| <div | <div | ||||
| className={cn( | className={cn( | ||||
| 'shrink-0 truncate text-xs font-medium text-text-accent', | |||||
| 'shrink-0 ml-0.5 truncate text-xs font-medium text-text-accent', | |||||
| !notHasValue && 'max-w-[70px]', | !notHasValue && 'max-w-[70px]', | ||||
| )} | )} | ||||
| title={variableName} | title={variableName} |