Skip to content

Commit f7b4701

Browse files
committed
Fix inability to delete edges
1 parent 1862972 commit f7b4701

File tree

2 files changed

+68
-32
lines changed

2 files changed

+68
-32
lines changed
Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { Edge } from "@xyflow/react";
22

33
import type { NodeManager } from "@/nodeManager";
4-
import type { ComponentSpec, GraphImplementation } from "@/utils/componentSpec";
4+
import {
5+
type ComponentSpec,
6+
isGraphImplementation,
7+
} from "@/utils/componentSpec";
58
import { outputIdToOutputName } from "@/utils/nodes/conversions";
69

710
import { setGraphOutputValue } from "./setGraphOutputValue";
@@ -12,34 +15,67 @@ export const removeEdge = (
1215
componentSpec: ComponentSpec,
1316
nodeManager: NodeManager,
1417
) => {
15-
const graphSpec = (componentSpec.implementation as GraphImplementation)
16-
?.graph;
17-
18-
const inputName = edge.targetHandle?.replace(/^input_/, "");
19-
20-
const updatedComponentSpec = {
21-
...componentSpec,
22-
};
23-
24-
const taskId = nodeManager.getTaskId(edge.target);
25-
if (!taskId) return componentSpec;
26-
27-
if (inputName !== undefined && graphSpec) {
28-
const newGraphSpec = setTaskArgument(graphSpec, taskId, inputName);
29-
updatedComponentSpec.implementation = {
30-
...updatedComponentSpec.implementation,
31-
graph: newGraphSpec,
32-
};
33-
34-
return updatedComponentSpec;
35-
} else {
36-
const outputName = outputIdToOutputName(taskId);
37-
const newGraphSpec = setGraphOutputValue(graphSpec, outputName);
38-
updatedComponentSpec.implementation = {
39-
...updatedComponentSpec.implementation,
40-
graph: newGraphSpec,
41-
};
42-
43-
return updatedComponentSpec;
18+
if (!isGraphImplementation(componentSpec.implementation)) {
19+
return componentSpec;
4420
}
21+
22+
const graphSpec = componentSpec.implementation.graph;
23+
const updatedComponentSpec = { ...componentSpec };
24+
25+
const targetNodeId = edge.target;
26+
const targetTaskId = nodeManager.getTaskId(targetNodeId);
27+
const targetNodeType = nodeManager.getNodeType(targetNodeId);
28+
29+
if (!targetTaskId || !targetNodeType) {
30+
console.error("Could not resolve target node information:", {
31+
targetNodeId,
32+
targetTaskId,
33+
targetNodeType,
34+
});
35+
return componentSpec;
36+
}
37+
38+
switch (targetNodeType) {
39+
case "task": {
40+
if (!edge.targetHandle) {
41+
console.error("No target handle found for task connection");
42+
return componentSpec;
43+
}
44+
45+
const targetHandleInfo = nodeManager.getHandleInfo(edge.targetHandle);
46+
if (!targetHandleInfo) {
47+
console.error("Could not resolve target handle info");
48+
return componentSpec;
49+
}
50+
51+
const inputName = targetHandleInfo.handleName;
52+
const newGraphSpec = setTaskArgument(graphSpec, targetTaskId, inputName);
53+
54+
updatedComponentSpec.implementation = {
55+
...updatedComponentSpec.implementation,
56+
graph: newGraphSpec,
57+
};
58+
break;
59+
}
60+
61+
case "output": {
62+
const outputName = outputIdToOutputName(targetTaskId);
63+
const newGraphSpec = setGraphOutputValue(graphSpec, outputName);
64+
65+
updatedComponentSpec.implementation = {
66+
...updatedComponentSpec.implementation,
67+
graph: newGraphSpec,
68+
};
69+
break;
70+
}
71+
72+
default:
73+
console.error(
74+
"Unsupported target node type for edge removal:",
75+
targetNodeType,
76+
);
77+
return componentSpec;
78+
}
79+
80+
return updatedComponentSpec;
4581
};

src/providers/TaskNodeProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ export const TaskNodeProvider = ({
7171
}: TaskNodeProviderProps) => {
7272
const notify = useToastNotification();
7373
const reactFlowInstance = useReactFlow();
74-
const { getStableNodeId } = useNodeManager();
74+
const { getTaskNodeId } = useNodeManager();
7575

7676
const taskSpec = data.taskSpec ?? ({} as TaskSpec);
7777
const taskId = data.taskId as string;
78-
const nodeId = getStableNodeId(taskId, "task");
78+
const nodeId = getTaskNodeId(taskId);
7979

8080
const inputs = taskSpec.componentRef.spec?.inputs || [];
8181
const outputs = taskSpec.componentRef.spec?.outputs || [];

0 commit comments

Comments
 (0)