mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
fix: variable-assigner node connect (#3288)
This commit is contained in:
parent
89a853212b
commit
240c793e7a
|
@ -43,7 +43,10 @@ export const useNodesInteractions = () => {
|
||||||
const workflowStore = useWorkflowStore()
|
const workflowStore = useWorkflowStore()
|
||||||
const nodesExtraData = useNodesExtraData()
|
const nodesExtraData = useNodesExtraData()
|
||||||
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
|
||||||
const { getAfterNodesInSameBranch } = useWorkflow()
|
const {
|
||||||
|
getAfterNodesInSameBranch,
|
||||||
|
getTreeLeafNodes,
|
||||||
|
} = useWorkflow()
|
||||||
const { getNodesReadOnly } = useNodesReadOnly()
|
const { getNodesReadOnly } = useNodesReadOnly()
|
||||||
const dragNodeStartPosition = useRef({ x: 0, y: 0 } as { x: number; y: number })
|
const dragNodeStartPosition = useRef({ x: 0, y: 0 } as { x: number; y: number })
|
||||||
const connectingNodeRef = useRef<{ nodeId: string; handleType: HandleType } | null>(null)
|
const connectingNodeRef = useRef<{ nodeId: string; handleType: HandleType } | null>(null)
|
||||||
|
@ -313,6 +316,13 @@ export const useNodesInteractions = () => {
|
||||||
setEdges,
|
setEdges,
|
||||||
} = store.getState()
|
} = store.getState()
|
||||||
const nodes = getNodes()
|
const nodes = getNodes()
|
||||||
|
const targetNode = nodes.find(node => node.id === target!)
|
||||||
|
if (targetNode && targetNode?.data.type === BlockEnum.VariableAssigner) {
|
||||||
|
const treeNodes = getTreeLeafNodes(target!)
|
||||||
|
|
||||||
|
if (!treeNodes.find(treeNode => treeNode.id === source))
|
||||||
|
return
|
||||||
|
}
|
||||||
const needDeleteEdges = edges.filter((edge) => {
|
const needDeleteEdges = edges.filter((edge) => {
|
||||||
if (edge.source === source) {
|
if (edge.source === source) {
|
||||||
if (edge.sourceHandle)
|
if (edge.sourceHandle)
|
||||||
|
@ -368,7 +378,7 @@ export const useNodesInteractions = () => {
|
||||||
})
|
})
|
||||||
setEdges(newEdges)
|
setEdges(newEdges)
|
||||||
handleSyncWorkflowDraft()
|
handleSyncWorkflowDraft()
|
||||||
}, [store, handleSyncWorkflowDraft, getNodesReadOnly])
|
}, [store, handleSyncWorkflowDraft, getNodesReadOnly, getTreeLeafNodes])
|
||||||
|
|
||||||
const handleNodeConnectStart = useCallback<OnConnectStart>((_, { nodeId, handleType }) => {
|
const handleNodeConnectStart = useCallback<OnConnectStart>((_, { nodeId, handleType }) => {
|
||||||
if (nodeId && handleType) {
|
if (nodeId && handleType) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import produce from 'immer'
|
||||||
import RemoveButton from '../../../_base/components/remove-button'
|
import RemoveButton from '../../../_base/components/remove-button'
|
||||||
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
|
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
|
||||||
import type { ValueSelector, Var } from '@/app/components/workflow/types'
|
import type { ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
|
import { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
readonly: boolean
|
readonly: boolean
|
||||||
|
@ -71,6 +72,7 @@ const VarList: FC<Props> = ({
|
||||||
onOpen={handleOpen(index)}
|
onOpen={handleOpen(index)}
|
||||||
onlyLeafNodeVar={onlyLeafNodeVar}
|
onlyLeafNodeVar={onlyLeafNodeVar}
|
||||||
filterVar={filterVar}
|
filterVar={filterVar}
|
||||||
|
defaultVarKindType={VarKindType.variable}
|
||||||
/>
|
/>
|
||||||
{!readonly && (
|
{!readonly && (
|
||||||
<RemoveButton
|
<RemoveButton
|
||||||
|
|
|
@ -59,7 +59,7 @@ const getCycleEdges = (nodes: Node[], edges: Edge[]) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const edge of edges)
|
for (const edge of edges)
|
||||||
adjaList[edge.source].push(edge.target)
|
adjaList[edge.source]?.push(edge.target)
|
||||||
|
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
if (color[nodes[i].id] === WHITE)
|
if (color[nodes[i].id] === WHITE)
|
||||||
|
@ -143,14 +143,14 @@ export const initialEdges = (edges: Edge[], nodes: Node[]) => {
|
||||||
if (!edge.targetHandle)
|
if (!edge.targetHandle)
|
||||||
edge.targetHandle = 'target'
|
edge.targetHandle = 'target'
|
||||||
|
|
||||||
if (!edge.data?.sourceType) {
|
if (!edge.data?.sourceType && edge.source) {
|
||||||
edge.data = {
|
edge.data = {
|
||||||
...edge.data,
|
...edge.data,
|
||||||
sourceType: nodesMap[edge.source].data.type!,
|
sourceType: nodesMap[edge.source].data.type!,
|
||||||
} as any
|
} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!edge.data?.targetType) {
|
if (!edge.data?.targetType && edge.target) {
|
||||||
edge.data = {
|
edge.data = {
|
||||||
...edge.data,
|
...edge.data,
|
||||||
targetType: nodesMap[edge.target].data.type!,
|
targetType: nodesMap[edge.target].data.type!,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user