Skip to content

Commit 4ba5633

Browse files
committed
Fix Node Replacement Issues on IO Rename
1 parent 705d37e commit 4ba5633

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) => {
@@ -265,7 +262,6 @@ export const InputValueEditor = ({
265262
onBlur={handleBlur}
266263
error={validationError}
267264
disabled={disabled}
268-
autoFocus={!disabled}
269265
/>
270266

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

6862
if (output && !isInput) {
@@ -74,19 +68,18 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
7468
<OutputNameEditor
7569
output={output}
7670
connectedDetails={outputConnectedDetails}
77-
key={output.name}
7871
disabled={readOnly}
7972
/>,
8073
);
8174
}
8275
}
76+
}, [selected, readOnly, input, output, isInput, graphSpec]);
8377

78+
useEffect(() => {
8479
return () => {
85-
if (selected) {
86-
clearContent();
87-
}
80+
clearContent();
8881
};
89-
}, [input, output, selected, readOnly]);
82+
}, []);
9083

9184
const connectedOutput = getOutputConnectedDetails(graphSpec, spec.name);
9285
const outputConnectedValue = connectedOutput.outputName;

src/hooks/useNodeSelectionTransfer.ts

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

0 commit comments

Comments
 (0)