Skip to content

Commit 48d97de

Browse files
committed
Move IO Node Handles into Node Manager
1 parent 825db4b commit 48d97de

File tree

3 files changed

+58
-14
lines changed

3 files changed

+58
-14
lines changed

src/components/shared/ReactFlow/FlowCanvas/IONode/IONode.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface IONodeProps {
2727
}
2828

2929
const IONode = ({ type, data, selected = false }: IONodeProps) => {
30-
const { getInputNodeId, getOutputNodeId } = useNodeManager();
30+
const { getNodeId, getHandleNodeId } = useNodeManager();
3131
const { graphSpec, componentSpec } = useComponentSpec();
3232
const { setContent, clearContent } = useContextPanel();
3333

@@ -58,21 +58,24 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
5858
[componentSpec.outputs, spec.name],
5959
);
6060

61-
const nodeId = isInput
62-
? getInputNodeId(inputNameToInputId(spec.name))
63-
: getOutputNodeId(outputNameToOutputId(spec.name));
61+
const inputId = inputNameToInputId(spec.name);
62+
const outputId = outputNameToOutputId(spec.name);
63+
const id = isInput ? inputId : outputId;
6464

65-
const nodeHandleId = `${nodeId}_handle`;
65+
const nodeId = getNodeId(id, type);
66+
67+
const handleNodeType = isInput ? "outputHandle" : "inputHandle";
68+
const nodeHandleId = getHandleNodeId(id, "handle", handleNodeType);
6669

6770
const handleHandleClick = useCallback(() => {
6871
if (ENABLE_DEBUG_MODE) {
69-
console.log(`${isInput ? "Input" : "Output"} Node Handle clicked:`, {
70-
name: isInput ? input?.name : output?.name,
72+
console.log(`${type} Node Handle clicked:`, {
73+
name: spec.name,
7174
nodeId,
7275
handleId: nodeHandleId,
7376
});
7477
}
75-
}, [isInput, input, output, nodeId, nodeHandleId]);
78+
}, [spec, nodeId, nodeHandleId]);
7679

7780
useEffect(() => {
7881
if (selected) {

src/hooks/useNodeManager.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ export const useNodeManager = () => {
77
const { nodeManager } = useComponentSpec();
88

99
// Get node ID utilities
10+
const getNodeId = useCallback(
11+
(name: string, type: "input" | "output" | "task"): string => {
12+
return nodeManager.getNodeId(name, type);
13+
},
14+
[nodeManager],
15+
);
16+
17+
const getHandleNodeId = useCallback(
18+
(
19+
taskId: string,
20+
handleName: string,
21+
handleType: "inputHandle" | "outputHandle",
22+
): string => {
23+
return nodeManager.getHandleNodeId(taskId, handleName, handleType);
24+
},
25+
[nodeManager],
26+
);
27+
1028
const getTaskNodeId = useCallback(
1129
(taskId: string): string => {
1230
return nodeManager.getNodeId(taskId, "task");
@@ -91,6 +109,8 @@ export const useNodeManager = () => {
91109
return useMemo(
92110
() => ({
93111
// Core operations
112+
getNodeId,
113+
getHandleNodeId,
94114
getTaskId,
95115
updateTaskId,
96116
removeNode,
@@ -109,6 +129,8 @@ export const useNodeManager = () => {
109129
nodeManager,
110130
}),
111131
[
132+
getNodeId,
133+
getHandleNodeId,
112134
getTaskId,
113135
updateTaskId,
114136
removeNode,

src/nodeManager.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import {
44
type ComponentSpec,
55
isGraphImplementation,
66
} from "./utils/componentSpec";
7+
import {
8+
inputNameToInputId,
9+
outputNameToOutputId,
10+
} from "./utils/nodes/conversions";
711

812
export type NodeType =
913
| "task"
@@ -248,12 +252,27 @@ export class NodeManager {
248252
}
249253

250254
// Graph-level inputs and outputs
251-
componentSpec.inputs?.forEach((input) =>
252-
currentTasks.get("input")?.add(input.name),
253-
);
254-
componentSpec.outputs?.forEach((output) =>
255-
currentTasks.get("output")?.add(output.name),
256-
);
255+
componentSpec.inputs?.forEach((input) => {
256+
const inputId = inputNameToInputId(input.name);
257+
currentTasks.get("input")?.add(input.name);
258+
259+
// Add to currentTaskHandles like a regular task
260+
if (!currentTaskHandles.has(inputId)) {
261+
currentTaskHandles.set(inputId, new Set());
262+
}
263+
currentTaskHandles.get(inputId)!.add("outputHandle:output");
264+
});
265+
266+
componentSpec.outputs?.forEach((output) => {
267+
const outputId = outputNameToOutputId(output.name);
268+
currentTasks.get("output")?.add(output.name);
269+
270+
// Add to currentTaskHandles like a regular task
271+
if (!currentTaskHandles.has(outputId)) {
272+
currentTaskHandles.set(outputId, new Set());
273+
}
274+
currentTaskHandles.get(outputId)!.add("inputHandle:input");
275+
});
257276

258277
// Remove mappings for deleted tasks by type
259278
for (const [nodeType, taskMap] of this.taskToNodeMap) {

0 commit comments

Comments
 (0)