Skip to content

Commit 10473ce

Browse files
committed
Migrate Legacy NodeId Utilities to NodeManager
1 parent 50cbbc2 commit 10473ce

23 files changed

+518
-395
lines changed

src/components/Editor/IOEditor/InputValueEditor/InputValueEditor.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import { Icon } from "@/components/ui/icon";
99
import { BlockStack } from "@/components/ui/layout";
1010
import { Heading, Paragraph } from "@/components/ui/typography";
1111
import useConfirmationDialog from "@/hooks/useConfirmationDialog";
12+
import { useNodeManager } from "@/hooks/useNodeManager";
1213
import { useNodeSelectionTransfer } from "@/hooks/useNodeSelectionTransfer";
1314
import useToastNotification from "@/hooks/useToastNotification";
1415
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
1516
import { useContextPanel } from "@/providers/ContextPanelProvider";
1617
import { type InputSpec } from "@/utils/componentSpec";
1718
import { checkInputConnectionToRequiredFields } from "@/utils/inputConnectionUtils";
18-
import { inputNameToNodeId } from "@/utils/nodes/nodeIdUtils";
19+
import { inputNameToInputId } from "@/utils/nodes/conversions";
1920

2021
import { NameField, TextField, TypeField } from "./FormFields/FormFields";
2122
import { checkNameCollision } from "./FormFields/utils";
@@ -30,6 +31,16 @@ export const InputValueEditor = ({
3031
input,
3132
disabled = false,
3233
}: InputValueEditorProps) => {
34+
const { getInputNodeId } = useNodeManager();
35+
36+
const inputNameToNodeId = useCallback(
37+
(inputName: string): string => {
38+
const inputId = inputNameToInputId(inputName);
39+
return getInputNodeId(inputId);
40+
},
41+
[getInputNodeId],
42+
);
43+
3344
const notify = useToastNotification();
3445
const { transferSelection } = useNodeSelectionTransfer(inputNameToNodeId);
3546
const { componentSpec, setComponentSpec } = useComponentSpec();

src/components/Editor/IOEditor/OutputNameEditor/OutputNameEditor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { Icon } from "@/components/ui/icon";
77
import { BlockStack, InlineStack } from "@/components/ui/layout";
88
import { Heading, Paragraph } from "@/components/ui/typography";
99
import useConfirmationDialog from "@/hooks/useConfirmationDialog";
10+
import { useNodeManager } from "@/hooks/useNodeManager";
1011
import { useNodeSelectionTransfer } from "@/hooks/useNodeSelectionTransfer";
1112
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
1213
import { useContextPanel } from "@/providers/ContextPanelProvider";
1314
import { type OutputSpec } from "@/utils/componentSpec";
14-
import { outputNameToNodeId } from "@/utils/nodes/nodeIdUtils";
1515

1616
import { type OutputConnectedDetails } from "../../utils/getOutputConnectedDetails";
1717
import { updateOutputNameOnComponentSpec } from "../../utils/updateOutputNameOnComponentSpec";
@@ -29,6 +29,16 @@ export const OutputNameEditor = ({
2929
disabled,
3030
connectedDetails,
3131
}: OutputNameEditorProps) => {
32+
const { getOutputNodeId } = useNodeManager();
33+
34+
const outputNameToNodeId = useCallback(
35+
(outputName: string): string => {
36+
const outputId = outputNameToNodeId(outputName);
37+
return getOutputNodeId(outputId);
38+
},
39+
[getOutputNodeId],
40+
);
41+
3242
const { transferSelection } = useNodeSelectionTransfer(outputNameToNodeId);
3343
const { setComponentSpec, componentSpec } = useComponentSpec();
3444
const { clearContent } = useContextPanel();

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,23 @@ const FlowCanvas = ({
303303
let updatedComponentSpec = { ...componentSpec };
304304

305305
for (const edge of params.edges) {
306-
updatedComponentSpec = removeEdge(edge, updatedComponentSpec);
306+
updatedComponentSpec = removeEdge(
307+
edge,
308+
updatedComponentSpec,
309+
nodeManager,
310+
);
307311
}
308312
for (const node of params.nodes) {
309-
updatedComponentSpec = removeNode(node, updatedComponentSpec);
313+
updatedComponentSpec = removeNode(
314+
node,
315+
updatedComponentSpec,
316+
nodeManager,
317+
);
310318
}
311319

312320
setComponentSpec(updatedComponentSpec);
313321
},
314-
[componentSpec, setComponentSpec],
322+
[componentSpec, nodeManager, setComponentSpec],
315323
);
316324

317325
const nodeCallbacks = useNodeCallbacks({
@@ -334,7 +342,11 @@ const FlowCanvas = ({
334342
(connection: Connection) => {
335343
if (connection.source === connection.target) return;
336344

337-
const updatedGraphSpec = handleConnection(graphSpec, connection);
345+
const updatedGraphSpec = handleConnection(
346+
graphSpec,
347+
connection,
348+
nodeManager,
349+
);
338350
updateGraphSpec(updatedGraphSpec);
339351
},
340352
[graphSpec, handleConnection, updateGraphSpec],
@@ -374,19 +386,30 @@ const FlowCanvas = ({
374386
);
375387

376388
if (existingInputEdge) {
377-
newComponentSpec = removeEdge(existingInputEdge, newComponentSpec);
389+
newComponentSpec = removeEdge(
390+
existingInputEdge,
391+
newComponentSpec,
392+
nodeManager,
393+
);
378394
}
379395

380396
const updatedComponentSpec = addAndConnectNode({
381397
componentRef,
382398
fromHandle,
383399
position,
384400
componentSpec: newComponentSpec,
401+
nodeManager,
385402
});
386403

387404
setComponentSpec(updatedComponentSpec);
388405
},
389-
[reactFlowInstance, componentSpec, setComponentSpec, updateOrAddNodes],
406+
[
407+
reactFlowInstance,
408+
componentSpec,
409+
nodeManager,
410+
setComponentSpec,
411+
updateOrAddNodes,
412+
],
390413
);
391414

392415
useEffect(() => {
@@ -633,14 +656,15 @@ const FlowCanvas = ({
633656
const updatedComponentSpec = updateNodePositions(
634657
updatedNodes,
635658
componentSpec,
659+
nodeManager,
636660
);
637661
setComponentSpec(updatedComponentSpec);
638662
}
639663
}
640664

641665
onNodesChange(changes);
642666
},
643-
[nodes, componentSpec, setComponentSpec, onNodesChange],
667+
[nodes, componentSpec, nodeManager, setComponentSpec, onNodesChange],
644668
);
645669

646670
const handleBeforeDelete = async (params: NodesAndEdges) => {

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskNodeCard/Handles.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import {
1111
TooltipContent,
1212
TooltipTrigger,
1313
} from "@/components/ui/tooltip";
14+
import { useNodeManager } from "@/hooks/useNodeManager";
1415
import { cn } from "@/lib/utils";
1516
import { useTaskNode } from "@/providers/TaskNodeProvider";
1617
import type { InputSpec, OutputSpec } from "@/utils/componentSpec";
18+
import {
19+
inputNameToInputId,
20+
outputNameToOutputId,
21+
} from "@/utils/nodes/conversions";
1722

1823
type InputHandleProps = {
1924
input: InputSpec;
@@ -32,6 +37,7 @@ export const InputHandle = ({
3237
onLabelClick,
3338
onHandleSelectionChange,
3439
}: InputHandleProps) => {
40+
const { getInputNodeId } = useNodeManager();
3541
const { nodeId, state } = useTaskNode();
3642

3743
const fromHandle = useConnection((connection) => connection.fromHandle?.id);
@@ -44,7 +50,7 @@ export const InputHandle = ({
4450
const [selected, setSelected] = useState(false);
4551
const [active, setActive] = useState(false);
4652

47-
const handleId = getInputHandleId(input.name);
53+
const handleId = getInputNodeId(inputNameToInputId(input.name));
4854

4955
const missing = invalid ? "bg-red-700!" : "bg-gray-500!";
5056
const hasValue = value !== undefined && value !== null;
@@ -218,6 +224,7 @@ export const OutputHandle = ({
218224
onLabelClick,
219225
onHandleSelectionChange,
220226
}: OutputHandleProps) => {
227+
const { getOutputNodeId } = useNodeManager();
221228
const { nodeId, state } = useTaskNode();
222229

223230
const fromHandle = useConnection((connection) => connection.fromHandle?.id);
@@ -230,7 +237,7 @@ export const OutputHandle = ({
230237
const [selected, setSelected] = useState(false);
231238
const [active, setActive] = useState(false);
232239

233-
const handleId = getOutputHandleId(output.name);
240+
const handleId = getOutputNodeId(outputNameToOutputId(output.name));
234241
const hasValue = value !== undefined && value !== "" && value !== null;
235242

236243
const handleHandleClick = useCallback(
@@ -355,14 +362,6 @@ export const OutputHandle = ({
355362
);
356363
};
357364

358-
const getOutputHandleId = (outputName: string) => {
359-
return `output_${outputName}`;
360-
};
361-
362-
const getInputHandleId = (inputName: string) => {
363-
return `input_${inputName}`;
364-
};
365-
366365
const skipHandleDeselect = (e: MouseEvent) => {
367366
let el = e.target as HTMLElement | null;
368367
while (el) {

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskNodeCard/TaskNodeInputs.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useConnection } from "@xyflow/react";
22
import { AlertCircle } from "lucide-react";
33
import { type MouseEvent, useCallback, useEffect, useState } from "react";
44

5+
import { useNodeManager } from "@/hooks/useNodeManager";
56
import { cn } from "@/lib/utils";
67
import { useForcedSearchContext } from "@/providers/ComponentLibraryProvider/ForcedSearchProvider";
78
import { isValidFilterRequest } from "@/providers/ComponentLibraryProvider/types";
@@ -10,7 +11,7 @@ import { useTaskNode } from "@/providers/TaskNodeProvider";
1011
import { inputsWithInvalidArguments } from "@/services/componentService";
1112
import type { InputSpec } from "@/utils/componentSpec";
1213
import { ComponentSearchFilter } from "@/utils/constants";
13-
import { inputNameToNodeId } from "@/utils/nodes/nodeIdUtils";
14+
import { inputNameToInputId } from "@/utils/nodes/conversions";
1415
import { checkArtifactMatchesSearchFilters } from "@/utils/searchUtils";
1516

1617
import { InputHandle } from "./Handles";
@@ -27,6 +28,7 @@ export function TaskNodeInputs({
2728
expanded,
2829
onBackgroundClick,
2930
}: TaskNodeInputsProps) {
31+
const { getInputNodeId } = useNodeManager();
3032
const { inputs, taskSpec, state, select } = useTaskNode();
3133
const { graphSpec } = useComponentSpec();
3234
const {
@@ -145,7 +147,7 @@ export function TaskNodeInputs({
145147
}
146148

147149
const input = inputs.find(
148-
(i) => inputNameToNodeId(i.name) === fromHandle?.id,
150+
(i) => getInputNodeId(inputNameToInputId(i.name)) === fromHandle?.id,
149151
);
150152

151153
if (!input) return;

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskNodeCard/TaskNodeOutputs.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useConnection, useEdges } from "@xyflow/react";
22
import { type MouseEvent, useCallback, useEffect, useState } from "react";
33

4+
import { useNodeManager } from "@/hooks/useNodeManager";
45
import { cn } from "@/lib/utils";
56
import { useForcedSearchContext } from "@/providers/ComponentLibraryProvider/ForcedSearchProvider";
67
import { isValidFilterRequest } from "@/providers/ComponentLibraryProvider/types";
78
import { useTaskNode } from "@/providers/TaskNodeProvider";
89
import type { OutputSpec } from "@/utils/componentSpec";
910
import { ComponentSearchFilter } from "@/utils/constants";
10-
import { outputNameToNodeId } from "@/utils/nodes/nodeIdUtils";
11+
import { outputNameToOutputId } from "@/utils/nodes/conversions";
1112
import { checkArtifactMatchesSearchFilters } from "@/utils/searchUtils";
1213

1314
import { OutputHandle } from "./Handles";
@@ -23,6 +24,7 @@ export function TaskNodeOutputs({
2324
expanded,
2425
onBackgroundClick,
2526
}: TaskNodeOutputsProps) {
27+
const { getOutputNodeId } = useNodeManager();
2628
const { nodeId, outputs, state, select } = useTaskNode();
2729
const {
2830
highlightSearchFilter,
@@ -40,7 +42,8 @@ export function TaskNodeOutputs({
4042
edges.some(
4143
(edge) =>
4244
edge.source === nodeId &&
43-
edge.sourceHandle === outputNameToNodeId(output.name),
45+
edge.sourceHandle ===
46+
getOutputNodeId(outputNameToOutputId(output.name)),
4447
),
4548
);
4649

@@ -138,7 +141,7 @@ export function TaskNodeOutputs({
138141
}
139142

140143
const output = outputs.find(
141-
(o) => outputNameToNodeId(o.name) === fromHandle?.id,
144+
(o) => getOutputNodeId(outputNameToOutputId(o.name)) === fromHandle?.id,
142145
);
143146

144147
if (!output) return;

0 commit comments

Comments
 (0)