From 9a5edae219667f44af7ff5a7e1eefda580a75ef8 Mon Sep 17 00:00:00 2001 From: zipg Date: Thu, 23 Jul 2026 22:48:38 +0800 Subject: [PATCH] fix(connection): improve connection picker interactions --- .../connection/ConnectionDialog.vue | 64 +++++++++++++++---- .../connectionDialogAccessibility.spec.ts | 20 ++++++ .../connection/connectionDialogRadius.spec.ts | 11 ++++ .../connectionPickerViewPreference.spec.ts | 35 ++++++++++ .../connectionPickerViewPreference.ts | 17 +++++ 5 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 apps/desktop/src/lib/__tests__/connection/connectionDialogAccessibility.spec.ts create mode 100644 apps/desktop/src/lib/__tests__/connection/connectionDialogRadius.spec.ts create mode 100644 apps/desktop/src/lib/__tests__/connection/connectionPickerViewPreference.spec.ts create mode 100644 apps/desktop/src/lib/connection/connectionPickerViewPreference.ts diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue index 39317fc73f..35e7bb6de4 100644 --- a/apps/desktop/src/components/connection/ConnectionDialog.vue +++ b/apps/desktop/src/components/connection/ConnectionDialog.vue @@ -48,6 +48,7 @@ import { appendConnectionErrorHints, isJdbcMissingRuntimeDependencyError } from import { postgresTlsModeForForm } from "@/lib/connection/postgresTlsMode"; import { buildMqKafkaConnectionExtra, mqKafkaConnectionTarget, resolveMqKafkaConnectionSource, type MqKafkaConnectionSource } from "@/lib/connection/mqKafkaConnection"; import { assertCompleteDatabaseCategories, databaseSelectionForCategory } from "@/lib/connection/databaseCategoryOptions"; +import { loadConnectionPickerView, saveConnectionPickerView, type DbPickerView } from "@/lib/connection/connectionPickerViewPreference"; import { normalizeRocketmqNamesrvAddr } from "@/lib/connection/rocketmqNamesrv"; import { normalizeRabbitmqAddresses } from "@/lib/connection/rabbitmqAddresses"; import { detectMqUiAuthKind, isMqAuthKindAllowedForSystem, type MqUiAuthKind } from "@/lib/connection/mqAuth"; @@ -98,7 +99,6 @@ type DbOption = { value: string; label: string }; type DbCategoryKey = "sql" | "analytics" | "domestic" | "lightweight" | "document" | "graph_ai" | "timeseries" | "mq" | "registry_config"; type DbCategory = { key: DbCategoryKey; title: string; options: DbOption[] }; type DialogStep = "select" | "config"; -type DbPickerView = "icon" | "list"; export type ConfigTab = "connection" | "advanced" | "tls" | "transport"; type ProductionScope = "connection" | "databases"; type MqTokenSigningMode = "none" | "hs256" | "rs256"; @@ -508,7 +508,7 @@ const hiveJaasConfigPath = ref(""); const hiveUseSubjectCredsOnlyFalse = ref(false); const hiveExtraJavaOptions = ref(""); const dialogStep = ref("select"); -const dbPickerView = ref("icon"); +const dbPickerView = ref(loadConnectionPickerView()); const dbSearchQuery = ref(""); const selectedDbCategory = ref("sql"); const configTab = ref("connection"); @@ -2367,6 +2367,11 @@ function selectDbCategory(category: DbCategoryKey) { if (nextSelection && nextSelection !== selectedType.value) onDbTypeChange(nextSelection); } +function selectDbPickerView(view: DbPickerView) { + dbPickerView.value = view; + saveConnectionPickerView(view); +} + function dbCategoryForOption(value: string): DbCategoryKey | undefined { return dbCategories.value.find((category) => category.options.some((option) => option.value === value))?.key; } @@ -2725,6 +2730,18 @@ function backToDatabasePicker() { resetTestState(); } +function handleDialogOpenAutoFocus(event: Event) { + event.preventDefault(); + if (!(event.currentTarget instanceof HTMLElement)) return; + event.currentTarget.querySelector("[data-connection-dialog-title]")?.focus({ preventScroll: true }); +} + +function handleDialogEscape(event: KeyboardEvent) { + if (dialogStep.value !== "config" || editingId.value) return; + event.preventDefault(); + backToDatabasePicker(); +} + watch(customDriverName, (value) => { if (isCustomCompatibleProfile()) { form.value.driver_label = value.trim() || selectedProfile().label; @@ -3758,7 +3775,6 @@ function resetForm() { connectionUrlInput.value = ""; appliedConnectionUrlInput.value = ""; dialogStep.value = "select"; - dbPickerView.value = "icon"; dbSearchQuery.value = ""; selectedDbCategory.value = "sql"; configTab.value = "connection"; @@ -4445,9 +4461,9 @@ function openExternalUrl(url: string) {