Skip to content

Commit 349bbc8

Browse files
committed
Fix Node Replacement Issues on IO Rename
1 parent b0d1e49 commit 349bbc8

File tree

6 files changed

+19
-77
lines changed

6 files changed

+19
-77
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ const NameField = ({
6868
onBlur,
6969
error,
7070
disabled,
71-
autoFocus = false,
7271
}: {
7372
inputName: string;
7473
onNameChange: (value: string) => void;
7574
onBlur?: () => void;
7675
error?: string | null;
7776
disabled?: boolean;
78-
autoFocus?: boolean;
7977
}) => (
8078
<FormField label="Name" id={`input-name-${inputName}`}>
8179
<Input
@@ -88,7 +86,6 @@ const NameField = ({
8886
className={cn("text-sm", {
8987
"border-red-500 focus:border-red-500": !!error,
9088
})}
91-
autoFocus={autoFocus}
9289
/>
9390
<Activity mode={error ? "visible" : "hidden"}>
9491
<div className="text-xs text-red-500 mt-1">{error}</div>

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { InputValueEditor } from "./InputValueEditor";
77

88
// Mock all the dependencies
99
const mockSetComponentSpec = vi.fn();
10-
const mockTransferSelection = vi.fn();
1110
const mockNotify = vi.fn();
1211
const mockClearContent = vi.fn();
12+
const mockUpdateRefId = vi.fn();
1313

1414
vi.mock("@/providers/ComponentSpecProvider", () => ({
1515
useComponentSpec: () => ({
@@ -36,9 +36,12 @@ vi.mock("@/providers/ContextPanelProvider", () => ({
3636
}),
3737
}));
3838

39-
vi.mock("@/hooks/useNodeSelectionTransfer", () => ({
40-
useNodeSelectionTransfer: () => ({
41-
transferSelection: mockTransferSelection,
39+
vi.mock("@/hooks/useNodeManager", () => ({
40+
useNodeManager: () => ({
41+
updateRefId: mockUpdateRefId,
42+
getNodeId: vi.fn(),
43+
getHandleNodeId: vi.fn(),
44+
nodeManager: {},
4245
}),
4346
}));
4447

@@ -110,7 +113,7 @@ describe("InputValueEditor", () => {
110113

111114
// Verify that the component spec was updated and selection was transferred
112115
expect(mockSetComponentSpec).toHaveBeenCalled();
113-
expect(mockTransferSelection).toHaveBeenCalledWith("TestInput", "NewName");
116+
expect(mockUpdateRefId).toHaveBeenCalledWith("TestInput", "NewName");
114117
});
115118

116119
it("shows validation error when renaming to existing input name", () => {

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { BlockStack } from "@/components/ui/layout";
1010
import { Heading, Paragraph } from "@/components/ui/typography";
1111
import useConfirmationDialog from "@/hooks/useConfirmationDialog";
1212
import { useNodeManager } from "@/hooks/useNodeManager";
13-
import { useNodeSelectionTransfer } from "@/hooks/useNodeSelectionTransfer";
1413
import useToastNotification from "@/hooks/useToastNotification";
1514
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
1615
import { useContextPanel } from "@/providers/ContextPanelProvider";
@@ -30,11 +29,9 @@ export const InputValueEditor = ({
3029
input,
3130
disabled = false,
3231
}: InputValueEditorProps) => {
33-
const { getInputNodeId } = useNodeManager();
32+
const { updateRefId } = useNodeManager();
3433

3534
const notify = useToastNotification();
36-
37-
const { transferSelection } = useNodeSelectionTransfer(getInputNodeId);
3835
const { componentSpec, setComponentSpec } = useComponentSpec();
3936
const { clearContent } = useContextPanel();
4037
const {
@@ -102,11 +99,11 @@ export const InputValueEditor = ({
10299
newName,
103100
);
104101

105-
transferSelection(oldName, newName);
102+
updateRefId(oldName, newName);
106103

107104
return updatedComponentSpec;
108105
},
109-
[componentSpec, transferSelection],
106+
[componentSpec, updateRefId],
110107
);
111108

112109
const handleValueChange = useCallback((value: string) => {
@@ -258,7 +255,6 @@ export const InputValueEditor = ({
258255
onBlur={handleBlur}
259256
error={validationError}
260257
disabled={disabled}
261-
autoFocus={!disabled}
262258
/>
263259

264260
<TextField

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { BlockStack, InlineStack } from "@/components/ui/layout";
88
import { Heading, Paragraph } from "@/components/ui/typography";
99
import useConfirmationDialog from "@/hooks/useConfirmationDialog";
1010
import { useNodeManager } from "@/hooks/useNodeManager";
11-
import { useNodeSelectionTransfer } from "@/hooks/useNodeSelectionTransfer";
1211
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
1312
import { useContextPanel } from "@/providers/ContextPanelProvider";
1413
import { type OutputSpec } from "@/utils/componentSpec";
@@ -29,9 +28,8 @@ export const OutputNameEditor = ({
2928
disabled,
3029
connectedDetails,
3130
}: OutputNameEditorProps) => {
32-
const { getOutputNodeId } = useNodeManager();
31+
const { updateRefId } = useNodeManager();
3332

34-
const { transferSelection } = useNodeSelectionTransfer(getOutputNodeId);
3533
const { setComponentSpec, componentSpec } = useComponentSpec();
3634
const { clearContent } = useContextPanel();
3735
const {
@@ -57,11 +55,11 @@ export const OutputNameEditor = ({
5755
newName,
5856
);
5957

60-
transferSelection(oldName, newName);
58+
updateRefId(oldName, newName);
6159

6260
return updatedComponentSpec;
6361
},
64-
[componentSpec, setComponentSpec],
62+
[componentSpec, updateRefId],
6563
);
6664

6765
const saveChanges = useCallback(() => {

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
6363
useEffect(() => {
6464
if (selected) {
6565
if (input && isInput) {
66-
setContent(
67-
<InputValueEditor
68-
input={input}
69-
key={input.name}
70-
disabled={readOnly}
71-
/>,
72-
);
66+
setContent(<InputValueEditor input={input} disabled={readOnly} />);
7367
}
7468

7569
if (output && !isInput) {
@@ -81,19 +75,18 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
8175
<OutputNameEditor
8276
output={output}
8377
connectedDetails={outputConnectedDetails}
84-
key={output.name}
8578
disabled={readOnly}
8679
/>,
8780
);
8881
}
8982
}
83+
}, [selected, readOnly, input, output, isInput, graphSpec]);
9084

85+
useEffect(() => {
9186
return () => {
92-
if (selected) {
93-
clearContent();
94-
}
87+
clearContent();
9588
};
96-
}, [input, output, selected, readOnly]);
89+
}, []);
9790

9891
const connectedOutput = getOutputConnectedDetails(graphSpec, spec.name);
9992
const outputConnectedValue = connectedOutput.outputName;

src/hooks/useNodeSelectionTransfer.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)