Skip to content

Commit a2c9556

Browse files
itsmeakhilclaude
andcommitted
feat(data-explorer): infer Mongo dialect instead of asking for it
The source dropdown already says "MongoDB", so the form's second mongodb/documentdb/cosmosdb/ferretdb picker read as a duplicate question. Removed it and derived dbType from the connection string. dbType stays load-bearing: normalizeConnectionString appends retryWrites=false for DocumentDB and Cosmos, which reject the driver's default and would otherwise fail writes silently. Both are identifiable by their managed hostnames, which is what detectDbType matches (already covered by lib/__tests__/nosql-dialects.test.ts). When detection cannot tell, the connection's saved dbType is kept, so an explicit FerretDB choice from an older build survives an edit. The connection-string placeholder still follows the inferred dialect. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e65ae98 commit a2c9556

1 file changed

Lines changed: 18 additions & 24 deletions

File tree

  • apps/desktop-ui/src/components/data-explorer/adapters

apps/desktop-ui/src/components/data-explorer/adapters/mongodb.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
} from "@/lib/nosql-error-sanitizer";
5151
import {
5252
DB_DIALECTS,
53-
DB_TYPE_ORDER,
53+
detectDbType,
5454
normalizeConnectionString,
5555
type DbType,
5656
} from "@/lib/nosql-dialects";
@@ -137,7 +137,23 @@ function MongoConnectionForm({
137137
const [color, setColor] = useState<string | null>(initial.color ?? null);
138138
const [readOnly, setReadOnly] = useState(initial.readOnly ?? false);
139139
const [connectionString, setConnectionString] = useState(initial.config.connectionString);
140-
const [dbType, setDbType] = useState<DbType>(initial.config.dbType);
140+
141+
/**
142+
* Inferred from the connection string, not picked by the user — the source
143+
* dropdown already said "MongoDB" and asking again read as a duplicate.
144+
*
145+
* `dbType` is still load-bearing: `normalizeConnectionString` appends
146+
* `retryWrites=false` for DocumentDB and Cosmos, which reject the driver's
147+
* default and would otherwise fail writes silently. Both are identifiable
148+
* by their managed hostnames, which is exactly what `detectDbType` matches.
149+
* It falls back to "mongodb" when it cannot tell, so keep whatever the
150+
* connection was saved with in that case — an explicit FerretDB choice from
151+
* an older build then survives an edit.
152+
*/
153+
const dbType = useMemo<DbType>(() => {
154+
const detected = detectDbType(connectionString);
155+
return detected === "mongodb" ? initial.config.dbType : detected;
156+
}, [connectionString, initial.config.dbType]);
141157

142158
function handleSubmit(e: React.FormEvent) {
143159
e.preventDefault();
@@ -168,28 +184,6 @@ function MongoConnectionForm({
168184
/>
169185
</div>
170186

171-
<div className="space-y-2">
172-
<Label>{t("dbType")}</Label>
173-
<div className="grid grid-cols-2 gap-2">
174-
{DB_TYPE_ORDER.map((type) => (
175-
<button
176-
key={type}
177-
type="button"
178-
onClick={() => setDbType(type)}
179-
disabled={saving}
180-
className={cn(
181-
"rounded-lg border px-3 py-2 text-left text-sm font-medium transition-colors",
182-
dbType === type
183-
? "border-primary bg-primary/5 ring-1 ring-primary/20"
184-
: "border-border bg-background/50 hover:border-primary/30"
185-
)}
186-
>
187-
{DB_DIALECTS[type].label}
188-
</button>
189-
))}
190-
</div>
191-
</div>
192-
193187
<div className="space-y-2">
194188
<Label htmlFor="mongo-connection-string">{t("connectionString")}</Label>
195189
<Input

0 commit comments

Comments
 (0)