mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 21:45:56 +08:00
fix(workflow): fix var-selector not update when edges change (#8259)
Co-authored-by: Chen(MAC) <chenchen404@outlook.com>
This commit is contained in:
parent
49cee773c5
commit
a9c1f1a041
@ -8,6 +8,7 @@ import {
|
|||||||
} from '@remixicon/react'
|
} from '@remixicon/react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import { useStoreApi } from 'reactflow'
|
import { useStoreApi } from 'reactflow'
|
||||||
|
import useAvailableVarList from '../../hooks/use-available-var-list'
|
||||||
import VarReferencePopup from './var-reference-popup'
|
import VarReferencePopup from './var-reference-popup'
|
||||||
import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './utils'
|
import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './utils'
|
||||||
import ConstantField from './constant-field'
|
import ConstantField from './constant-field'
|
||||||
@ -26,7 +27,6 @@ import {
|
|||||||
} from '@/app/components/base/portal-to-follow-elem'
|
} from '@/app/components/base/portal-to-follow-elem'
|
||||||
import {
|
import {
|
||||||
useIsChatMode,
|
useIsChatMode,
|
||||||
useWorkflow,
|
|
||||||
useWorkflowVariables,
|
useWorkflowVariables,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
import { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
|
import { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
|
||||||
@ -67,7 +67,7 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
onlyLeafNodeVar,
|
onlyLeafNodeVar,
|
||||||
filterVar = () => true,
|
filterVar = () => true,
|
||||||
availableNodes: passedInAvailableNodes,
|
availableNodes: passedInAvailableNodes,
|
||||||
availableVars,
|
availableVars: passedInAvailableVars,
|
||||||
isAddBtnTrigger,
|
isAddBtnTrigger,
|
||||||
schema,
|
schema,
|
||||||
valueTypePlaceHolder,
|
valueTypePlaceHolder,
|
||||||
@ -79,11 +79,12 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
} = store.getState()
|
} = store.getState()
|
||||||
const isChatMode = useIsChatMode()
|
const isChatMode = useIsChatMode()
|
||||||
|
|
||||||
const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow()
|
const { getCurrentVariableType } = useWorkflowVariables()
|
||||||
const { getCurrentVariableType, getNodeAvailableVars } = useWorkflowVariables()
|
const { availableNodes, availableVars } = useAvailableVarList(nodeId, {
|
||||||
const availableNodes = useMemo(() => {
|
onlyLeafNodeVar,
|
||||||
return passedInAvailableNodes || (onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId))
|
passedInAvailableNodes,
|
||||||
}, [getBeforeNodesInSameBranch, getTreeLeafNodes, nodeId, onlyLeafNodeVar, passedInAvailableNodes])
|
filterVar,
|
||||||
|
})
|
||||||
const startNode = availableNodes.find((node: any) => {
|
const startNode = availableNodes.find((node: any) => {
|
||||||
return node.data.type === BlockEnum.Start
|
return node.data.type === BlockEnum.Start
|
||||||
})
|
})
|
||||||
@ -102,19 +103,8 @@ const VarReferencePicker: FC<Props> = ({
|
|||||||
|
|
||||||
const [varKindType, setVarKindType] = useState<VarKindType>(defaultVarKindType)
|
const [varKindType, setVarKindType] = useState<VarKindType>(defaultVarKindType)
|
||||||
const isConstant = isSupportConstantValue && varKindType === VarKindType.constant
|
const isConstant = isSupportConstantValue && varKindType === VarKindType.constant
|
||||||
const outputVars = useMemo(() => {
|
|
||||||
if (availableVars)
|
|
||||||
return availableVars
|
|
||||||
|
|
||||||
const vars = getNodeAvailableVars({
|
const outputVars = useMemo(() => (passedInAvailableVars || availableVars), [passedInAvailableVars, availableVars])
|
||||||
parentNode: iterationNode,
|
|
||||||
beforeNodes: availableNodes,
|
|
||||||
isChatMode,
|
|
||||||
filterVar,
|
|
||||||
})
|
|
||||||
|
|
||||||
return vars
|
|
||||||
}, [iterationNode, availableNodes, isChatMode, filterVar, availableVars, getNodeAvailableVars])
|
|
||||||
|
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -4,12 +4,13 @@ import {
|
|||||||
useWorkflow,
|
useWorkflow,
|
||||||
useWorkflowVariables,
|
useWorkflowVariables,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
import type { ValueSelector, Var } from '@/app/components/workflow/types'
|
import type { Node, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
type Params = {
|
type Params = {
|
||||||
onlyLeafNodeVar?: boolean
|
onlyLeafNodeVar?: boolean
|
||||||
hideEnv?: boolean
|
hideEnv?: boolean
|
||||||
hideChatVar?: boolean
|
hideChatVar?: boolean
|
||||||
filterVar: (payload: Var, selector: ValueSelector) => boolean
|
filterVar: (payload: Var, selector: ValueSelector) => boolean
|
||||||
|
passedInAvailableNodes?: Node[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const useAvailableVarList = (nodeId: string, {
|
const useAvailableVarList = (nodeId: string, {
|
||||||
@ -17,6 +18,7 @@ const useAvailableVarList = (nodeId: string, {
|
|||||||
filterVar,
|
filterVar,
|
||||||
hideEnv,
|
hideEnv,
|
||||||
hideChatVar,
|
hideChatVar,
|
||||||
|
passedInAvailableNodes,
|
||||||
}: Params = {
|
}: Params = {
|
||||||
onlyLeafNodeVar: false,
|
onlyLeafNodeVar: false,
|
||||||
filterVar: () => true,
|
filterVar: () => true,
|
||||||
@ -25,7 +27,7 @@ const useAvailableVarList = (nodeId: string, {
|
|||||||
const { getNodeAvailableVars } = useWorkflowVariables()
|
const { getNodeAvailableVars } = useWorkflowVariables()
|
||||||
const isChatMode = useIsChatMode()
|
const isChatMode = useIsChatMode()
|
||||||
|
|
||||||
const availableNodes = onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId)
|
const availableNodes = passedInAvailableNodes || (onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId))
|
||||||
|
|
||||||
const {
|
const {
|
||||||
parentNode: iterationNode,
|
parentNode: iterationNode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user