Skip to content

Commit

Permalink
Merge branch 'feat/ifelse-variable-editable-after-selection' into dep…
Browse files Browse the repository at this point in the history
…loy/dev
  • Loading branch information
YIXIAO0 committed Dec 6, 2024
2 parents 7f46240 + ac89f7e commit ba77fa4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion api/core/app/apps/base_app_generate_response_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_simple_metadata(cls, metadata: dict[str, Any]):
for resource in metadata["retriever_resources"]:
updated_resources.append(
{
"segment_id": resource["segment_id"],
"segment_id": resource.get("segment_id", ""),
"position": resource["position"],
"document_name": resource["document_name"],
"score": resource["score"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ const VarReferenceVars: FC<Props> = ({
{
!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
showLeftIcon
showClearIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ import { comparisonOperatorNotRequireValue, getOperators } from '../../utils'
import ConditionNumberInput from '../condition-number-input'
import { FILE_TYPE_OPTIONS, SUB_VARIABLES, TRANSFER_METHOD } from '../../default'
import ConditionWrap from '../condition-wrap'
import VarReferenceVars from '../../../_base/components/variable/var-reference-vars'
import ConditionOperator from './condition-operator'
import ConditionInput from './condition-input'
import VariableTag from '@/app/components/workflow/nodes/_base/components/variable-tag'
import {
PortalToFollowElem,
PortalToFollowElemContent,
PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem'

import type {
Node,
NodeOutPutVar,
ValueSelector,
Var,
} from '@/app/components/workflow/types'
import { VarType } from '@/app/components/workflow/types'
Expand Down Expand Up @@ -82,6 +90,7 @@ const ConditionItem = ({
const { t } = useTranslation()

const [isHovered, setIsHovered] = useState(false)
const [open, setOpen] = useState(false)

const doUpdateCondition = useCallback((newCondition: Condition) => {
if (isSubVariableKey)
Expand Down Expand Up @@ -190,6 +199,17 @@ const ConditionItem = ({
onRemoveCondition?.(caseId, condition.id)
}, [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 (
<div className={cn('flex mb-1 last-of-type:mb-0', className)}>
<div className={cn(
Expand Down Expand Up @@ -221,12 +241,35 @@ const ConditionItem = ({
/>
)
: (
<VariableTag
valueSelector={condition.variable_selector || []}
varType={condition.varType}
availableNodes={availableNodes}
isShort
/>
<PortalToFollowElem
open={open}
onOpenChange={setOpen}
placement='bottom-start'
offset={{
mainAxis: 4,
crossAxis: 0,
}}
>
<PortalToFollowElemTrigger onClick={() => setOpen(!open)}>
<div className="cursor-pointer">
<VariableTag
valueSelector={condition.variable_selector || []}
varType={condition.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={handleVarChange}
/>
</div>
</PortalToFollowElemContent>
</PortalToFollowElem>
)}

</div>
Expand Down

0 comments on commit ba77fa4

Please sign in to comment.