Skip to content

Commit 7a8cb63

Browse files
committed
Fix Node Replacement Issues on IO Rename
1 parent a8814d2 commit 7a8cb63

File tree

6 files changed

+19
-76
lines changed

6 files changed

+19
-76
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: () => ({
@@ -48,9 +48,12 @@ vi.mock("@/providers/ContextPanelProvider", () => ({
4848
}),
4949
}));
5050

51-
vi.mock("@/hooks/useNodeSelectionTransfer", () => ({
52-
useNodeSelectionTransfer: () => ({
53-
transferSelection: mockTransferSelection,
51+
vi.mock("@/hooks/useNodeManager", () => ({
52+
useNodeManager: () => ({
53+
updateRefId: mockUpdateRefId,
54+
getNodeId: vi.fn(),
55+
getHandleNodeId: vi.fn(),
56+
nodeManager: {},
5457
}),
5558
}));
5659

@@ -122,7 +125,7 @@ describe("InputValueEditor", () => {
122125

123126
// Verify that the component spec was updated and selection was transferred
124127
expect(mockSetComponentSpec).toHaveBeenCalled();
125-
expect(mockTransferSelection).toHaveBeenCalledWith("TestInput", "NewName");
128+
expect(mockUpdateRefId).toHaveBeenCalledWith("TestInput", "NewName");
126129
});
127130

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

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

Lines changed: 3 additions & 6 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";
@@ -31,10 +30,9 @@ export const InputValueEditor = ({
3130
input,
3231
disabled = false,
3332
}: InputValueEditorProps) => {
34-
const { getInputNodeId } = useNodeManager();
33+
const { updateRefId } = useNodeManager();
3534

3635
const notify = useToastNotification();
37-
const { transferSelection } = useNodeSelectionTransfer(getInputNodeId);
3836
const {
3937
componentSpec,
4038
setComponentSpec,
@@ -110,11 +108,11 @@ export const InputValueEditor = ({
110108
newName,
111109
);
112110

113-
transferSelection(oldName, newName);
111+
updateRefId(oldName, newName);
114112

115113
return updatedComponentSpec;
116114
},
117-
[currentSubgraphSpec, transferSelection],
115+
[currentSubgraphSpec, updateRefId],
118116
);
119117

120118
const handleValueChange = useCallback((value: string) => {
@@ -292,7 +290,6 @@ export const InputValueEditor = ({
292290
onBlur={handleBlur}
293291
error={validationError}
294292
disabled={disabled}
295-
autoFocus={!disabled}
296293
/>
297294

298295
<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";
@@ -30,8 +29,7 @@ export const OutputNameEditor = ({
3029
disabled,
3130
connectedDetails,
3231
}: OutputNameEditorProps) => {
33-
const { getOutputNodeId } = useNodeManager();
34-
const { transferSelection } = useNodeSelectionTransfer(getOutputNodeId);
32+
const { updateRefId } = useNodeManager();
3533
const {
3634
setComponentSpec,
3735
componentSpec,
@@ -62,11 +60,11 @@ export const OutputNameEditor = ({
6260
newName,
6361
);
6462

65-
transferSelection(oldName, newName);
63+
updateRefId(oldName, newName);
6664

6765
return updatedComponentSpec;
6866
},
69-
[currentSubgraphSpec, transferSelection],
67+
[currentSubgraphSpec, updateRefId],
7068
);
7169

7270
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
@@ -57,13 +57,7 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
5757
useEffect(() => {
5858
if (selected) {
5959
if (input && isInput) {
60-
setContent(
61-
<InputValueEditor
62-
input={input}
63-
key={input.name}
64-
disabled={readOnly}
65-
/>,
66-
);
60+
setContent(<InputValueEditor input={input} disabled={readOnly} />);
6761
}
6862

6963
if (output && !isInput) {
@@ -75,19 +69,18 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
7569
<OutputNameEditor
7670
output={output}
7771
connectedDetails={outputConnectedDetails}
78-
key={output.name}
7972
disabled={readOnly}
8073
/>,
8174
);
8275
}
8376
}
77+
}, [selected, readOnly, input, output, isInput, currentGraphSpec]);
8478

79+
useEffect(() => {
8580
return () => {
86-
if (selected) {
87-
clearContent();
88-
}
81+
clearContent();
8982
};
90-
}, [input, output, selected, readOnly]);
83+
}, []);
9184

9285
const connectedOutput = getOutputConnectedDetails(
9386
currentGraphSpec,

src/hooks/useNodeSelectionTransfer.ts

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

0 commit comments

Comments
 (0)