fix(connection): open edit dialog with saved profile

This commit is contained in:
t8y2
2026-05-19 10:33:03 +08:00
parent da4703cc01
commit 38f9fce779
4 changed files with 40 additions and 3 deletions
@@ -241,6 +241,7 @@ const driverProfiles: Record<
function profileForConfig(config: ConnectionConfig) {
if (config.driver_profile && driverProfiles[config.driver_profile]) return config.driver_profile;
if (config.db_type === "dameng") return "dm";
return config.db_type;
}
@@ -336,6 +337,7 @@ watch(
}
resetTestState();
},
{ immediate: true },
);
const isEditing = ref(false);
@@ -70,6 +70,7 @@ const editConfig = computed(() => {
if (!id) return undefined;
return connectionStore.getConfig(id);
});
const shouldShowConnectionDialog = computed(() => props.showConnectionDialog || !!editConfig.value);
watch(editConfig, (v) => {
if (v) emit("update:showConnectionDialog", true);
@@ -95,8 +96,8 @@ watch(
<template>
<ConnectionDialog
v-if="showConnectionDialog || editConfig"
:open="showConnectionDialog"
v-if="shouldShowConnectionDialog"
:open="shouldShowConnectionDialog"
:edit-config="editConfig"
@update:open="emit('update:showConnectionDialog', $event)"
@connect-started="emit('connectStarted', $event)"
@@ -0,0 +1,30 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const appDialogsSource = readFileSync(
new URL("../../apps/desktop/src/components/layout/AppDialogs.vue", import.meta.url),
"utf8",
);
test("connection dialog opens when editing connection config is available", () => {
assert.match(
appDialogsSource,
/const shouldShowConnectionDialog = computed\(\(\) => props\.showConnectionDialog \|\| !!editConfig\.value\)/,
);
assert.match(appDialogsSource, /:open="shouldShowConnectionDialog"/);
assert.match(appDialogsSource, /v-if="shouldShowConnectionDialog"/);
});
const connectionDialogSource = readFileSync(
new URL("../../apps/desktop/src/components/connection/ConnectionDialog.vue", import.meta.url),
"utf8",
);
test("connection dialog initializes edit form on first mount", () => {
assert.match(connectionDialogSource, /watch\(\s*\(\) => props\.editConfig,[\s\S]*?\{\s*immediate: true\s*\},\s*\)/);
});
test("connection dialog maps legacy Dameng configs to the DM profile", () => {
assert.match(connectionDialogSource, /if \(config\.db_type === "dameng"\) return "dm";/);
});
@@ -24,7 +24,11 @@ test("app dialogs keep non-primary dialogs out of the startup chunk", () => {
});
test("app dialogs only render async dialogs when their open state needs them", () => {
assert.match(appDialogsSource, /<ConnectionDialog\s+v-if="showConnectionDialog \|\| editConfig"/);
assert.match(
appDialogsSource,
/const shouldShowConnectionDialog = computed\(\(\) => props\.showConnectionDialog \|\| !!editConfig\.value\)/,
);
assert.match(appDialogsSource, /<ConnectionDialog\s+v-if="shouldShowConnectionDialog"/);
assert.match(appDialogsSource, /<EditorSettingsDialog\s+v-if="showSettingsDialog"/);
assert.match(appDialogsSource, /<DangerConfirmDialog\s+v-if="showDangerDialog"/);
assert.match(appDialogsSource, /<DataTransferDialog\s+v-if="dialogs\.showTransferDialog\.value"/);