Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ const NameField = ({
onBlur,
error,
disabled,
autoFocus = false,
}: {
inputName: string;
onNameChange: (value: string) => void;
onBlur?: () => void;
error?: string | null;
disabled?: boolean;
autoFocus?: boolean;
}) => (
<FormField label="Name" id={`input-name-${inputName}`}>
<Input
Expand All @@ -88,7 +86,6 @@ const NameField = ({
className={cn("text-sm", {
"border-red-500 focus:border-red-500": !!error,
})}
autoFocus={autoFocus}
/>
<Activity mode={error ? "visible" : "hidden"}>
<div className="text-xs text-red-500 mt-1">{error}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { InputValueEditor } from "./InputValueEditor";

// Mock all the dependencies
const mockSetComponentSpec = vi.fn();
const mockTransferSelection = vi.fn();
const mockNotify = vi.fn();
const mockClearContent = vi.fn();
const mockUpdateRefId = vi.fn();

vi.mock("@/providers/ComponentSpecProvider", () => ({
useComponentSpec: () => ({
Expand Down Expand Up @@ -48,9 +48,12 @@ vi.mock("@/providers/ContextPanelProvider", () => ({
}),
}));

vi.mock("@/hooks/useNodeSelectionTransfer", () => ({
useNodeSelectionTransfer: () => ({
transferSelection: mockTransferSelection,
vi.mock("@/hooks/useNodeManager", () => ({
useNodeManager: () => ({
updateRefId: mockUpdateRefId,
getNodeId: vi.fn(),
getHandleNodeId: vi.fn(),
nodeManager: {},
}),
}));

Expand Down Expand Up @@ -122,7 +125,7 @@ describe("InputValueEditor", () => {

// Verify that the component spec was updated and selection was transferred
expect(mockSetComponentSpec).toHaveBeenCalled();
expect(mockTransferSelection).toHaveBeenCalledWith("TestInput", "NewName");
expect(mockUpdateRefId).toHaveBeenCalledWith("TestInput", "NewName");
});

it("shows validation error when renaming to existing input name", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { BlockStack } from "@/components/ui/layout";
import { Heading, Paragraph } from "@/components/ui/typography";
import useConfirmationDialog from "@/hooks/useConfirmationDialog";
import { useNodeManager } from "@/hooks/useNodeManager";
import { useNodeSelectionTransfer } from "@/hooks/useNodeSelectionTransfer";
import useToastNotification from "@/hooks/useToastNotification";
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
import { useContextPanel } from "@/providers/ContextPanelProvider";
Expand All @@ -31,10 +30,9 @@ export const InputValueEditor = ({
input,
disabled = false,
}: InputValueEditorProps) => {
const { getInputNodeId } = useNodeManager();
const { updateRefId } = useNodeManager();

const notify = useToastNotification();
const { transferSelection } = useNodeSelectionTransfer(getInputNodeId);
const {
componentSpec,
setComponentSpec,
Expand Down Expand Up @@ -110,11 +108,11 @@ export const InputValueEditor = ({
newName,
);

transferSelection(oldName, newName);
updateRefId(oldName, newName);

return updatedComponentSpec;
},
[currentSubgraphSpec, transferSelection],
[currentSubgraphSpec, updateRefId],
);

const handleValueChange = useCallback((value: string) => {
Expand Down Expand Up @@ -292,7 +290,6 @@ export const InputValueEditor = ({
onBlur={handleBlur}
error={validationError}
disabled={disabled}
autoFocus={!disabled}
/>

<TextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { BlockStack, InlineStack } from "@/components/ui/layout";
import { Heading, Paragraph } from "@/components/ui/typography";
import useConfirmationDialog from "@/hooks/useConfirmationDialog";
import { useNodeManager } from "@/hooks/useNodeManager";
import { useNodeSelectionTransfer } from "@/hooks/useNodeSelectionTransfer";
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
import { useContextPanel } from "@/providers/ContextPanelProvider";
import { type OutputSpec } from "@/utils/componentSpec";
Expand All @@ -30,8 +29,7 @@ export const OutputNameEditor = ({
disabled,
connectedDetails,
}: OutputNameEditorProps) => {
const { getOutputNodeId } = useNodeManager();
const { transferSelection } = useNodeSelectionTransfer(getOutputNodeId);
const { updateRefId } = useNodeManager();
const {
setComponentSpec,
componentSpec,
Expand Down Expand Up @@ -62,11 +60,11 @@ export const OutputNameEditor = ({
newName,
);

transferSelection(oldName, newName);
updateRefId(oldName, newName);

return updatedComponentSpec;
},
[currentSubgraphSpec, transferSelection],
[currentSubgraphSpec, updateRefId],
);

const saveChanges = useCallback(() => {
Expand Down
17 changes: 5 additions & 12 deletions src/components/shared/ReactFlow/FlowCanvas/IONode/IONode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
useEffect(() => {
if (selected) {
if (input && isInput) {
setContent(
<InputValueEditor
input={input}
key={input.name}
disabled={readOnly}
/>,
);
setContent(<InputValueEditor input={input} disabled={readOnly} />);
}

if (output && !isInput) {
Expand All @@ -75,19 +69,18 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
<OutputNameEditor
output={output}
connectedDetails={outputConnectedDetails}
key={output.name}
disabled={readOnly}
/>,
);
}
}
}, [selected, readOnly, input, output, isInput, currentGraphSpec]);

useEffect(() => {
return () => {
if (selected) {
clearContent();
}
clearContent();
};
}, [input, output, selected, readOnly]);
}, []);

const connectedOutput = getOutputConnectedDetails(
currentGraphSpec,
Expand Down
45 changes: 0 additions & 45 deletions src/hooks/useNodeSelectionTransfer.ts

This file was deleted.