Skip to content

Commit 4f27090

Browse files
authored
Fix: Unable to reconnect after deleting the connection between begin and parser #13868 (#13869)
### What problem does this PR solve? Fix: Unable to reconnect after deleting the connection between begin and parser #13868 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
1 parent db5ab7b commit 4f27090

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

web/src/pages/agent/canvas/node/handle.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ export function CommonHandle({
1818
const { visible, hideModal, showModal } = useSetModalState();
1919
const { canShowDropdown, setActiveDropdown, clearActiveDropdown } =
2020
useDropdownManager();
21-
const { hasChildNode } = useGraphStore((state) => state);
21+
const { hasDownstreamNode, hasUpstreamNode } = useGraphStore(
22+
(state) => state,
23+
);
2224
const isPipeline = useIsPipeline();
2325

24-
const isConnectable = !(isPipeline && hasChildNode(nodeId)); // Using useMemo will cause isConnectable to not be updated when the subsequent connection line is deleted
26+
let isConnectable = true;
27+
28+
if (isPipeline) {
29+
if (props.type === 'source') {
30+
isConnectable = !hasDownstreamNode(nodeId);
31+
} else if (props.type === 'target') {
32+
isConnectable = !hasUpstreamNode(nodeId);
33+
}
34+
}
2535

2636
const value = useMemo(
2737
() => ({

web/src/pages/agent/constant/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ export const RestrictedUpstreamMap = {
692692
[Operator.Loop]: [Operator.Begin],
693693
[Operator.LoopStart]: [Operator.Begin],
694694
[Operator.ExitLoop]: [Operator.Begin],
695+
[Operator.PDFGenerator]: [Operator.Begin],
695696
};
696697

697698
export const NodeMap = {

web/src/pages/agent/store.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export type RFState = {
115115
) => void; // Deleting a condition of a classification operator will delete the related edge
116116
findAgentToolNodeById: (id: string | null) => string | undefined;
117117
selectNodeIds: (nodeIds: string[]) => void;
118-
hasChildNode: (nodeId: string) => boolean;
118+
hasDownstreamNode: (nodeId: string) => boolean;
119+
hasUpstreamNode: (nodeId: string) => boolean;
119120
};
120121

121122
// this is our useStore hook that we can use in our components to get parts of the store and call actions
@@ -469,7 +470,7 @@ const useGraphStore = create<RFState>()(
469470
const { updateNodeForm, edges, getOperatorTypeFromId } = get();
470471
if (sourceHandle) {
471472
// A handle will connect to multiple downstream nodes
472-
let currentHandleTargets = edges
473+
const currentHandleTargets = edges
473474
.filter(
474475
(x) =>
475476
x.source === source &&
@@ -647,10 +648,14 @@ const useGraphStore = create<RFState>()(
647648
})),
648649
);
649650
},
650-
hasChildNode: (nodeId) => {
651+
hasDownstreamNode: (nodeId) => {
651652
const { edges } = get();
652653
return edges.some((edge) => edge.source === nodeId);
653654
},
655+
hasUpstreamNode: (nodeId) => {
656+
const { edges } = get();
657+
return edges.some((edge) => edge.target === nodeId);
658+
},
654659
})),
655660
{ name: 'graph', trace: true },
656661
),

0 commit comments

Comments
 (0)