Skip to content

Commit 83e04a1

Browse files
committed
Fix Node Replacement Issues on IO Rename
1 parent a3cceee commit 83e04a1

File tree

5 files changed

+19
-81
lines changed

5 files changed

+19
-81
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: 5 additions & 15 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,19 +30,9 @@ export const InputValueEditor = ({
3130
input,
3231
disabled = false,
3332
}: 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-
);
33+
const { updateRefId } = useNodeManager();
4334

4435
const notify = useToastNotification();
45-
46-
const { transferSelection } = useNodeSelectionTransfer(inputNameToNodeId);
4736
const { componentSpec, setComponentSpec } = useComponentSpec();
4837
const { clearContent } = useContextPanel();
4938
const {
@@ -111,11 +100,13 @@ export const InputValueEditor = ({
111100
newName,
112101
);
113102

114-
transferSelection(oldName, newName);
103+
const oldInputId = inputNameToInputId(oldName);
104+
const newInputId = inputNameToInputId(newName);
105+
updateRefId(oldInputId, newInputId);
115106

116107
return updatedComponentSpec;
117108
},
118-
[componentSpec, transferSelection],
109+
[componentSpec, updateRefId],
119110
);
120111

121112
const handleValueChange = useCallback((value: string) => {
@@ -267,7 +258,6 @@ export const InputValueEditor = ({
267258
onBlur={handleBlur}
268259
error={validationError}
269260
disabled={disabled}
270-
autoFocus={!disabled}
271261
/>
272262

273263
<TextField

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ 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";
14+
import { outputNameToOutputId } from "@/utils/nodes/conversions";
1515

1616
import { type OutputConnectedDetails } from "../../utils/getOutputConnectedDetails";
1717
import { updateOutputNameOnComponentSpec } from "../../utils/updateOutputNameOnComponentSpec";
@@ -29,17 +29,8 @@ export const OutputNameEditor = ({
2929
disabled,
3030
connectedDetails,
3131
}: OutputNameEditorProps) => {
32-
const { getOutputNodeId } = useNodeManager();
32+
const { updateRefId } = useNodeManager();
3333

34-
const outputNameToNodeId = useCallback(
35-
(outputName: string): string => {
36-
const outputId = outputNameToNodeId(outputName);
37-
return getOutputNodeId(outputId);
38-
},
39-
[getOutputNodeId],
40-
);
41-
42-
const { transferSelection } = useNodeSelectionTransfer(outputNameToNodeId);
4334
const { setComponentSpec, componentSpec } = useComponentSpec();
4435
const { clearContent } = useContextPanel();
4536
const {
@@ -65,11 +56,13 @@ export const OutputNameEditor = ({
6556
newName,
6657
);
6758

68-
transferSelection(oldName, newName);
59+
const oldInputId = outputNameToOutputId(oldName);
60+
const newInputId = outputNameToOutputId(newName);
61+
updateRefId(oldInputId, newInputId);
6962

7063
return updatedComponentSpec;
7164
},
72-
[componentSpec, setComponentSpec],
65+
[componentSpec, updateRefId],
7366
);
7467

7568
const saveChanges = useCallback(() => {

src/hooks/useNodeSelectionTransfer.ts

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

0 commit comments

Comments
 (0)