From f4c0fac2e33cba285330f77746db211e0eb87d79 Mon Sep 17 00:00:00 2001 From: ayushdwivedi-stack Date: Fri, 16 Oct 2026 03:03:57 +0530 Subject: [PATCH 1/2] fix(frontend): revert endpoint type when cfg is removed from host Typing a host containing 'cfg' in the Add Connection modal auto-switches the endpoint type to Discovery, but deleting or removing 'cfg' left the form stuck in Discovery mode. - Track auto-switch to Discovery using a ref and revert to Node mode when 'cfg' is removed from the host while still in Discovery mode. - Clear the auto-switch ref on manual endpoint type selection to preserve explicit user choices. - Add unit tests verifying auto-switch reversion and preservation of explicit Discovery selection. Fixes #442 Signed-off-by: ayushdwivedi-stack --- .../components/ui/connection-form.test.tsx | 51 +++++++++++++++++++ .../src/components/ui/connection-modal.tsx | 21 ++++++-- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/apps/frontend/src/components/ui/connection-form.test.tsx b/apps/frontend/src/components/ui/connection-form.test.tsx index 3f22edc9..8a89f20f 100644 --- a/apps/frontend/src/components/ui/connection-form.test.tsx +++ b/apps/frontend/src/components/ui/connection-form.test.tsx @@ -53,4 +53,55 @@ describe("ConnectionForm", () => { connectionId: buildConnectionId("localhost", "6380", 0), }) }) + + it("does not get stuck in Discovery mode when 'cfg' is removed from host", async () => { + renderForm() + + expect(screen.getByLabelText("Node")).toBeChecked() + fireEvent.change(screen.getByLabelText("Database"), { target: { value: "7" } }) + + const hostInput = screen.getByLabelText("Host") + fireEvent.change(hostInput, { target: { value: "clustercfg.example.com" } }) + expect(screen.getByLabelText("Discovery")).toBeChecked() + + // Remove 'cfg' + fireEvent.change(hostInput, { target: { value: "cluster.example.com" } }) + + expect(screen.getByLabelText("Node")).toBeChecked() + expect(screen.getByLabelText("Discovery")).not.toBeChecked() + + fireEvent.click(screen.getByRole("button", { name: "Connect" })) + await screen.findByRole("button", { name: /Connect/ }) + + const connectPendingAction = dispatched.find((a) => a.type.endsWith("connectPending")) + const discoveryPendingAction = dispatched.find((a) => a.type.endsWith("discoveryEndpointPending")) + + expect(discoveryPendingAction).toBeUndefined() + expect(connectPendingAction).toBeDefined() + expect(connectPendingAction?.payload).toMatchObject({ + connectionId: buildConnectionId("cluster.example.com", "6379", 7), + connectionDetails: expect.objectContaining({ + endpointType: "node", + db: 7, + }), + }) + }) + + it("preserves explicit Discovery selection when 'cfg' is added and removed from host", () => { + renderForm() + + // Explicitly click Discovery + fireEvent.click(screen.getByLabelText("Discovery")) + expect(screen.getByLabelText("Discovery")).toBeChecked() + + // Type a host containing 'cfg' + const hostInput = screen.getByLabelText("Host") + fireEvent.change(hostInput, { target: { value: "clustercfg.example.com" } }) + expect(screen.getByLabelText("Discovery")).toBeChecked() + + // Delete 'cfg' + fireEvent.change(hostInput, { target: { value: "cluster.example.com" } }) + expect(screen.getByLabelText("Discovery")).toBeChecked() + expect(screen.getByLabelText("Node")).not.toBeChecked() + }) }) diff --git a/apps/frontend/src/components/ui/connection-modal.tsx b/apps/frontend/src/components/ui/connection-modal.tsx index 1046a7e8..55eb97f0 100644 --- a/apps/frontend/src/components/ui/connection-modal.tsx +++ b/apps/frontend/src/components/ui/connection-modal.tsx @@ -1,5 +1,5 @@ import { AlertTriangle, Loader2, X } from "lucide-react" -import { type FormEvent } from "react" +import { type FormEvent, useRef } from "react" import * as Dialog from "@radix-ui/react-dialog" import { MAX_CONNECTIONS } from "@common/src/constants.ts" import { Alert, AlertDescription } from "./alert.tsx" @@ -48,6 +48,7 @@ export function ConnectionModal({ dbError, dbHint, }: ConnectionModalProps) { + const autoSwitchedRef = useRef(false) return ( @@ -92,9 +93,10 @@ export function ConnectionModal({ + onValueChange={(value) => { + autoSwitchedRef.current = false onConnectionDetailsChange({ ...connectionDetails, endpointType: value as ConnectionDetails["endpointType"] }) - } + }} value={connectionDetails.endpointType} >
@@ -131,10 +133,21 @@ export function ConnectionModal({ id="host" onChange={(e) => { const host = e.target.value + const hasCfg = host.includes("cfg") + let nextEndpointType = connectionDetails.endpointType + + if (hasCfg && connectionDetails.endpointType !== "cluster-endpoint") { + autoSwitchedRef.current = true + nextEndpointType = "cluster-endpoint" + } else if (!hasCfg && autoSwitchedRef.current && connectionDetails.endpointType === "cluster-endpoint") { + autoSwitchedRef.current = false + nextEndpointType = "node" + } + onConnectionDetailsChange({ ...connectionDetails, host, - endpointType: host.includes("cfg") ? "cluster-endpoint" : connectionDetails.endpointType, + endpointType: nextEndpointType, }) }} placeholder="localhost" From c4ccaa631a41d2232e7b48e54bc226f46b228135 Mon Sep 17 00:00:00 2001 From: ayushdwivedi-stack Date: Fri, 16 Oct 2026 14:18:15 +0530 Subject: [PATCH 2/2] fix(frontend): only auto-switch endpoint on transition to cfg When a user manually selects Node while the host already contains 'cfg', subsequent edits to the host field should not flip the endpoint type back to Discovery unless transitioning from a non-cfg host. - Check !prevHasCfg before auto-switching to cluster-endpoint. - Add test verifying explicit Node selection is preserved when editing a host that already contains 'cfg'. Signed-off-by: ayushdwivedi-stack --- .../src/components/ui/connection-form.test.tsx | 17 +++++++++++++++++ .../src/components/ui/connection-modal.tsx | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/frontend/src/components/ui/connection-form.test.tsx b/apps/frontend/src/components/ui/connection-form.test.tsx index 8a89f20f..39e13e05 100644 --- a/apps/frontend/src/components/ui/connection-form.test.tsx +++ b/apps/frontend/src/components/ui/connection-form.test.tsx @@ -104,4 +104,21 @@ describe("ConnectionForm", () => { expect(screen.getByLabelText("Discovery")).toBeChecked() expect(screen.getByLabelText("Node")).not.toBeChecked() }) + + it("preserves explicit Node selection when editing a host that already contains 'cfg'", () => { + renderForm() + + const hostInput = screen.getByLabelText("Host") + fireEvent.change(hostInput, { target: { value: "clustercfg.example.com" } }) + expect(screen.getByLabelText("Discovery")).toBeChecked() + + // Manually select Node + fireEvent.click(screen.getByLabelText("Node")) + expect(screen.getByLabelText("Node")).toBeChecked() + + // Edit host to another host that also contains 'cfg' + fireEvent.change(hostInput, { target: { value: "clustercfg.example.org" } }) + expect(screen.getByLabelText("Node")).toBeChecked() + expect(screen.getByLabelText("Discovery")).not.toBeChecked() + }) }) diff --git a/apps/frontend/src/components/ui/connection-modal.tsx b/apps/frontend/src/components/ui/connection-modal.tsx index 55eb97f0..99614255 100644 --- a/apps/frontend/src/components/ui/connection-modal.tsx +++ b/apps/frontend/src/components/ui/connection-modal.tsx @@ -134,9 +134,10 @@ export function ConnectionModal({ onChange={(e) => { const host = e.target.value const hasCfg = host.includes("cfg") + const prevHasCfg = connectionDetails.host.includes("cfg") let nextEndpointType = connectionDetails.endpointType - if (hasCfg && connectionDetails.endpointType !== "cluster-endpoint") { + if (hasCfg && !prevHasCfg && connectionDetails.endpointType !== "cluster-endpoint") { autoSwitchedRef.current = true nextEndpointType = "cluster-endpoint" } else if (!hasCfg && autoSwitchedRef.current && connectionDetails.endpointType === "cluster-endpoint") {