Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(sidebar): add connection list sorting

zhangyc4b2a6c971a90
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vue
index 38a9a5abb9..29b42687a8 100644
--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue
+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, computed, nextTick, watch, provide, onMounted, onUnmounted, type Component, type ComponentPublicInstance, type CSSProperties } from "vue";
import { useI18n } from "vue-i18n";
-import { Search, X, ListFilter, Crosshair, Server, Database, FolderTree, Table2, Eye, RotateCcw } from "@lucide/vue";
+import { Search, X, ListFilter, ListOrdered, ArrowDownAZ, ArrowUpZA, Crosshair, Server, Database, FolderTree, Table2, Eye, RotateCcw } from "@lucide/vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
import { useSettingsStore } from "@/stores/settingsStore";
@@ -37,6 +37,7 @@ import { createSidebarActionTarget, findSidebarActionTarget, type SidebarActionT
import type { SidebarDangerDialogRequest } from "@/lib/sidebar/sidebarDangerDialog";
import { resetSidebarTreeDialogState } from "./sidebarTreeDialogState";
import { SidebarDangerConfirmDialog, SidebarDdlViewDialog, SidebarObjectSourceDialog, SidebarProcedureExecutionDialog, SidebarVisibleDatabasesDialog, SidebarVisibleSchemasDialog } from "./sidebarAsyncDialogs";
+import { sortConnectionListForDisplay } from "@/lib/sidebar/connectionListSort";
const { t } = useI18n();
const store = useConnectionStore();
@@ -247,6 +248,20 @@ const searchScopeMenuItems = computed(() => [
: []),
]);
+const connectionListSortMenuItems = computed(() => [
+ { value: "manual", label: t("sidebar.sortConnectionsManual"), icon: ListOrdered },
+ { value: "asc", label: t("sidebar.sortConnectionsAscending"), icon: ArrowDownAZ },
+ { value: "desc", label: t("sidebar.sortConnectionsDescending"), icon: ArrowUpZA },
+]);
+
+const isConnectionListAlphabeticallySorted = computed(() => settingsStore.editorSettings.sidebarConnectionSortMode !== "manual");
+
+function updateConnectionListSortMode(mode: string) {
+ if (mode === "manual" || mode === "asc" || mode === "desc") {
+ settingsStore.updateEditorSettings({ sidebarConnectionSortMode: mode });
+ }
+}
+
const hasSearchScopeFilter = computed(() => selectedSearchScopes.value.length > 0);
const searchableNodeTypes = computed<Set<TreeNodeType> | undefined>(() => {
if (!hasSearchScopeFilter.value) return undefined;
@@ -321,8 +336,10 @@ function focusTableSearchInput(parentNodeId: string) {
});
}
+const displayedTreeNodes = computed(() => sortConnectionListForDisplay(store.treeNodes, settingsStore.editorSettings.sidebarConnectionSortMode));
+
const filteredNodes = computed(() => {
- let nodes = store.treeNodes;
+ let nodes = displayedTreeNodes.value;
const q = deferredSearchQuery.value;
nodes = filterSidebarTree(nodes, q, searchCollapsedIds.value, searchableNodeTypes.value);
@@ -1333,6 +1350,23 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });
<button class="shrink-0 h-6 w-6 flex items-center justify-center rounded border border-border text-muted-foreground hover:bg-accent hover:text-foreground" :title="t('sidebar.locateActiveTab')" @click="locateActiveTabInSidebar">
<Crosshair class="h-3.5 w-3.5" />
</button>
+ <LightDropdown
+ :model-value="settingsStore.editorSettings.sidebarConnectionSortMode"
+ :items="connectionListSortMenuItems"
+ :aria-label="t('sidebar.sortConnections')"
+ :label="t('sidebar.sortConnections')"
+ :trigger-title="t('sidebar.sortConnections')"
+ :trigger-class="['shrink-0 h-6 w-6 flex items-center justify-center rounded border border-border hover:bg-accent', isConnectionListAlphabeticallySorted ? 'text-primary bg-primary/10 border-primary/30' : 'text-muted-foreground'].join(' ')"
+ trigger-icon-class="h-3.5 w-3.5"
+ item-icon-class="h-3.5 w-3.5"
+ content-class="w-max min-w-0"
+ selected-item-class="bg-primary/10 text-primary"
+ selected-check-class="text-primary"
+ :show-trigger-label="false"
+ :show-chevron="false"
+ align="end"
+ @update:model-value="updateConnectionListSortMode"
+ />
<LightDropdown
v-if="searchScopeOptions.length > 0"
model-value=""
@@ -1376,7 +1410,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });
<TreeItem
:node="item.node"
:depth="item.depth"
- :drag-disabled="isFiltering"
+ :drag-disabled="isFiltering || isConnectionListAlphabeticallySorted"
:pending-rename="pendingRenameGroupId === item.node.id"
:highlighted="highlightedNodeId === item.node.id"
@context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"
@@ -1399,7 +1433,7 @@ defineExpose({ focusSearch, createNewGroup, collapseAllTreeNodes });
:key="item.id"
:node="item.node"
:depth="item.depth"
- :drag-disabled="isFiltering"
+ :drag-disabled="isFiltering || isConnectionListAlphabeticallySorted"
:pending-rename="pendingRenameGroupId === item.node.id"
:highlighted="highlightedNodeId === item.id"
@context-menu="(event, node) => openSidebarContextMenu(event, node, contextMenuSlot.onContextMenu)"
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 2fc6a432a2..f27e89748c 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -94,6 +94,10 @@ export default {
expand: "Expand sidebar",
showMore: "Show {count} more...",
filterByType: "Filter by type",
+ sortConnections: "Sort connections",
+ sortConnectionsManual: "Manual order",
+ sortConnectionsAscending: "Name: A–Z",
+ sortConnectionsDescending: "Name: Z–A",
searchScopeConnection: "Connection",
searchScopeDatabase: "Database",
searchScopeSchema: "Schema",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index cb76351dae..55f62dbb93 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -96,6 +96,10 @@ export default withEnglishFallback({
expand: "Expandir barra lateral",
showMore: "Mostrar {count} más...",
filterByType: "Filtrar por tipo",
+ sortConnections: "Ordenar conexiones",
+ sortConnectionsManual: "Orden manual",
+ sortConnectionsAscending: "Nombre: A–Z",
+ sortConnectionsDescending: "Nombre: Z–A",
searchScopeConnection: "Conexión",
searchScopeDatabase: "Base de datos",
searchScopeSchema: "Schema",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index b89e766122..71915b51c5 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -95,6 +95,10 @@ export default withEnglishFallback({
expand: "Espandi barra laterale",
showMore: "Mostra altri {count}...",
filterByType: "Filtra per tipo",
+ sortConnections: "Ordina connessioni",
+ sortConnectionsManual: "Ordine manuale",
+ sortConnectionsAscending: "Nome: A–Z",
+ sortConnectionsDescending: "Nome: Z–A",
searchScopeConnection: "Connessione",
searchScopeDatabase: "Database",
searchScopeSchema: "Schema",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 388a897d10..4979c2614a 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -96,6 +96,10 @@ export default withEnglishFallback({
expand: "サイドバーを展開",
showMore: "さらに{count}件表示...",
filterByType: "タイプでフィルター",
+ sortConnections: "接続を並べ替え",
+ sortConnectionsManual: "手動順",
+ sortConnectionsAscending: "名前: A–Z",
+ sortConnectionsDescending: "名前: Z–A",
searchScopeConnection: "接続",
searchScopeDatabase: "データベース",
searchScopeSchema: "スキーマ",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index 02a87fb766..ef6d6c62da 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -96,6 +96,10 @@ export default withEnglishFallback({
expand: "Expandir barra lateral",
showMore: "Mostrar mais {count}...",
filterByType: "Filtrar por tipo",
+ sortConnections: "Ordenar conexões",
+ sortConnectionsManual: "Ordem manual",
+ sortConnectionsAscending: "Nome: A–Z",
+ sortConnectionsDescending: "Nome: Z–A",
searchScopeConnection: "Conexão",
searchScopeDatabase: "Banco de dados",
searchScopeSchema: "Schema",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index aacb42fab2..2fa73dd610 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -96,6 +96,10 @@ export default withEnglishFallback({
expand: "展开侧边栏",
showMore: "加载更多 ({count})...",
filterByType: "按类型筛选",
+ sortConnections: "连接排序",
+ sortConnectionsManual: "手动排序",
+ sortConnectionsAscending: "名称:A–Z",
+ sortConnectionsDescending: "名称:Z–A",
searchScopeConnection: "连接",
searchScopeDatabase: "数据库",
searchScopeSchema: "Schema",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index 7811ea9275..fec1632dee 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -96,6 +96,10 @@ export default withEnglishFallback({
expand: "展開側邊欄",
showMore: "再顯示 {count} 個……",
filterByType: "依類型篩選",
+ sortConnections: "連線排序",
+ sortConnectionsManual: "手動排序",
+ sortConnectionsAscending: "名稱:A–Z",
+ sortConnectionsDescending: "名稱:Z–A",
searchScopeConnection: "連線",
searchScopeDatabase: "資料庫",
searchScopeSchema: "Schema",
diff --git a/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts
new file mode 100644
index 0000000000..88f65bcdc0
--- /dev/null
+++ b/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it } from "vitest";
+import { sortConnectionListForDisplay } from "@/lib/sidebar/connectionListSort";
+import type { TreeNode } from "@/types/database";
+
+function connection(id: string, label: string): TreeNode {
+ return { id, label, type: "connection", connectionId: id, children: [] };
+}
+
+function group(id: string, label: string, children: TreeNode[]): TreeNode {
+ return { id, label, type: "connection-group", isExpanded: true, children };
+}
+
+describe("connection list display sort", () => {
+ const manualTree = [connection("zebra", "zebra"), group("team", "Team databases", [connection("beta", "Beta"), connection("alpha", "alpha"), connection("alpha-two", "Alpha 2")]), connection("alpha-root", "Alpha"), connection("alpha-root-two", "alpha")];
+
+ it("sorts root and grouped connections in ascending name order while preserving group placement", () => {
+ const sorted = sortConnectionListForDisplay(manualTree, "asc");
+
+ expect(sorted.map((node) => node.id)).toEqual(["alpha-root", "team", "alpha-root-two", "zebra"]);
+ expect(sorted[1]?.children?.map((node) => node.id)).toEqual(["alpha", "alpha-two", "beta"]);
+ });
+
+ it("sorts root and grouped connections in descending name order", () => {
+ const sorted = sortConnectionListForDisplay(manualTree, "desc");
+
+ expect(sorted.map((node) => node.id)).toEqual(["zebra", "team", "alpha-root", "alpha-root-two"]);
+ expect(sorted[1]?.children?.map((node) => node.id)).toEqual(["beta", "alpha-two", "alpha"]);
+ });
+
+ it("keeps manual order and stored tree references untouched", () => {
+ const manual = sortConnectionListForDisplay(manualTree, "manual");
+ const sorted = sortConnectionListForDisplay(manualTree, "asc");
+
+ expect(manual).toBe(manualTree);
+ expect(manualTree.map((node) => node.id)).toEqual(["zebra", "team", "alpha-root", "alpha-root-two"]);
+ expect(manualTree[1]?.children?.map((node) => node.id)).toEqual(["beta", "alpha", "alpha-two"]);
+ expect(sorted[1]).not.toBe(manualTree[1]);
+ });
+});
diff --git a/apps/desktop/src/lib/sidebar/connectionListSort.ts b/apps/desktop/src/lib/sidebar/connectionListSort.ts
new file mode 100644
index 0000000000..03094700f8
--- /dev/null
+++ b/apps/desktop/src/lib/sidebar/connectionListSort.ts
@@ -0,0 +1,40 @@
+import type { TreeNode } from "@/types/database";
+
+export type ConnectionListSortMode = "manual" | "asc" | "desc";
+
+const connectionNameCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
+
+function sortConnectionSiblingsForDisplay(nodes: readonly TreeNode[], mode: Exclude<ConnectionListSortMode, "manual">): TreeNode[] {
+ const sortedConnections = nodes
+ .map((node, index) => ({ node, index }))
+ .filter(({ node }) => node.type === "connection")
+ .sort((left, right) => {
+ const compared = connectionNameCollator.compare(left.node.label, right.node.label);
+ const directional = mode === "asc" ? compared : -compared;
+ return directional || left.index - right.index;
+ })
+ .map(({ node }) => node);
+
+ let nextConnectionIndex = 0;
+ const displayNodes = nodes.map((node) => {
+ if (node.type === "connection") {
+ return sortedConnections[nextConnectionIndex++]!;
+ }
+
+ if (node.type !== "connection-group" || !node.children) return node;
+ const children = sortConnectionSiblingsForDisplay(node.children, mode);
+ return children === node.children ? node : { ...node, children };
+ });
+
+ return displayNodes.every((node, index) => node === nodes[index]) ? (nodes as TreeNode[]) : displayNodes;
+}
+
+/**
+ * Produces a display-only ordering of saved connections. Group positions and
+ * the persisted manual layout remain untouched, so switching back to manual
+ * order restores drag-and-drop placement without a data migration.
+ */
+export function sortConnectionListForDisplay(nodes: readonly TreeNode[], mode: ConnectionListSortMode): TreeNode[] {
+ if (mode === "manual") return nodes as TreeNode[];
+ return sortConnectionSiblingsForDisplay(nodes, mode);
+}
diff --git a/apps/desktop/src/stores/__tests__/settingsStore.spec.ts b/apps/desktop/src/stores/__tests__/settingsStore.spec.ts
index c73cc4e2bd..508775b24e 100644
--- a/apps/desktop/src/stores/__tests__/settingsStore.spec.ts
+++ b/apps/desktop/src/stores/__tests__/settingsStore.spec.ts
@@ -18,6 +18,13 @@ describe("normalizeEditorSettings", () => {
expect(normalizeEditorSettings({ autoAliasTables: false }).autoAliasTables).toBe(false);
});
+ it("defaults sidebar connection sorting to manual order and preserves valid alphabetical modes", () => {
+ expect(normalizeEditorSettings({}).sidebarConnectionSortMode).toBe("manual");
+ expect(normalizeEditorSettings({ sidebarConnectionSortMode: "asc" }).sidebarConnectionSortMode).toBe("asc");
+ expect(normalizeEditorSettings({ sidebarConnectionSortMode: "desc" }).sidebarConnectionSortMode).toBe("desc");
+ expect(normalizeEditorSettings({ sidebarConnectionSortMode: "invalid" as any }).sidebarConnectionSortMode).toBe("manual");
+ });
+
it("shows the current statement frame by default", () => {
expect(normalizeEditorSettings({}).showCurrentStatementFrame).toBe(true);
});
@@ -257,6 +264,25 @@ describe("settingsStore MCP policy persistence", () => {
});
});
+describe("settingsStore sidebar connection sort persistence", () => {
+ beforeEach(() => {
+ vi.resetModules();
+ setActivePinia(createPinia());
+ });
+
+ it("persists the selected alphabetical sort mode", async () => {
+ const saveEditorSettings = vi.fn().mockResolvedValue(undefined);
+ vi.doMock("@/lib/backend/api", () => ({ saveEditorSettings }));
+
+ const { useSettingsStore } = await import("@/stores/settingsStore");
+ const store = useSettingsStore();
+ store.updateEditorSettings({ sidebarConnectionSortMode: "desc" });
+
+ expect(store.editorSettings.sidebarConnectionSortMode).toBe("desc");
+ expect(saveEditorSettings).toHaveBeenCalledWith(expect.objectContaining({ sidebarConnectionSortMode: "desc" }));
+ });
+});
+
// --- activeModel lifecycle tests ---
describe("settingsStore activeModel lifecycle", () => {
diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.ts
index fbb3cefb28..417120c4eb 100644
--- a/apps/desktop/src/stores/settingsStore.ts
+++ b/apps/desktop/src/stores/settingsStore.ts
@@ -6,6 +6,7 @@ import { normalizeColumnFormatter, normalizeCustomColumnFormatter, normalizeGlob
import { normalizeShortcutSettings, type ShortcutSettings } from "@/lib/editor/shortcutRegistry";
import { normalizeResultPageSize } from "@/lib/dataGrid/paginationPageSize";
import { normalizeSidebarHiddenTablePrefixes } from "@/lib/sidebar/sidebarTableNameDisplay";
+import type { ConnectionListSortMode } from "@/lib/sidebar/connectionListSort";
import { DEFAULT_SQL_FORMATTER_SETTINGS, normalizeSqlFormatterSettings, type SqlFormatterSettings } from "@/lib/sql/sqlFormatterConfig";
import { normalizeSqlVariableSyntaxOverrides, type SqlVariableSyntaxOverrides } from "@/lib/sql/sqlVariableSyntax";
import type { SidebarActivation } from "@/lib/sidebar/treeNodeClick";
@@ -426,6 +427,7 @@ export interface EditorSettings {
shortcuts: ShortcutSettings;
sqlFormatter: SqlFormatterSettings;
sidebarActivation: SidebarActivation;
+ sidebarConnectionSortMode: ConnectionListSortMode;
sidebarObjectDisplay: "grouped" | "simple";
sidebarTableSearchEnabled: boolean;
autoSelectActiveSidebarNode: boolean;
@@ -574,6 +576,7 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
shortcuts: normalizeShortcutSettings(),
sqlFormatter: normalizeSqlFormatterSettings(DEFAULT_SQL_FORMATTER_SETTINGS),
sidebarActivation: "single",
+ sidebarConnectionSortMode: "manual",
sidebarObjectDisplay: "grouped",
sidebarTableSearchEnabled: false,
autoSelectActiveSidebarNode: false,
@@ -691,6 +694,10 @@ function normalizeOpenTabsRestoreMode(value: unknown, legacyRestoreOpenTabsOnLau
return DEFAULT_EDITOR_SETTINGS.openTabsRestoreMode;
}
+function normalizeConnectionListSortMode(value: unknown): ConnectionListSortMode {
+ return value === "asc" || value === "desc" ? value : "manual";
+}
+
function normalizeColumnFormatters(value: unknown): Record<string, ColumnFormatterConfig> {
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
const formatters: Record<string, ColumnFormatterConfig> = {};
@@ -828,6 +835,7 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
shortcuts: normalizeShortcutSettings(settings.shortcuts),
sqlFormatter: normalizeSqlFormatterSettings(settings.sqlFormatter),
sidebarActivation: settings.sidebarActivation === "single" || settings.sidebarActivation === "double" ? settings.sidebarActivation : DEFAULT_EDITOR_SETTINGS.sidebarActivation,
+ sidebarConnectionSortMode: normalizeConnectionListSortMode(settings.sidebarConnectionSortMode),
sidebarObjectDisplay: settings.sidebarObjectDisplay === "simple" || settings.sidebarObjectDisplay === "grouped" ? settings.sidebarObjectDisplay : DEFAULT_EDITOR_SETTINGS.sidebarObjectDisplay,
sidebarTableSearchEnabled: typeof settings.sidebarTableSearchEnabled === "boolean" ? settings.sidebarTableSearchEnabled : DEFAULT_EDITOR_SETTINGS.sidebarTableSearchEnabled,
autoSelectActiveSidebarNode: settings.autoSelectActiveSidebarNode ?? DEFAULT_EDITOR_SETTINGS.autoSelectActiveSidebarNode,
@@ -1186,6 +1194,7 @@ export const useSettingsStore = defineStore("settings", () => {
if (partial.shortcuts !== undefined) editorSettings.value.shortcuts = normalizeShortcutSettings(partial.shortcuts);
if (partial.sqlFormatter !== undefined) editorSettings.value.sqlFormatter = normalizeSqlFormatterSettings(partial.sqlFormatter);
if (partial.sidebarActivation !== undefined) editorSettings.value.sidebarActivation = partial.sidebarActivation;
+ if (partial.sidebarConnectionSortMode !== undefined) editorSettings.value.sidebarConnectionSortMode = normalizeConnectionListSortMode(partial.sidebarConnectionSortMode);
if (partial.sidebarObjectDisplay !== undefined) editorSettings.value.sidebarObjectDisplay = partial.sidebarObjectDisplay;
if (partial.sidebarTableSearchEnabled !== undefined) editorSettings.value.sidebarTableSearchEnabled = partial.sidebarTableSearchEnabled;
if (partial.autoSelectActiveSidebarNode !== undefined) editorSettings.value.autoSelectActiveSidebarNode = partial.autoSelectActiveSidebarNode;
diff --git a/docs/assets/connection-list-sort-redacted.png b/docs/assets/connection-list-sort-redacted.png
new file mode 100644
index 0000000000..0438639356
Binary files /dev/null and b/docs/assets/connection-list-sort-redacted.png differ
diff --git a/docs/superpowers/specs/2026-07-21-connection-list-alphabetical-sort-design.md b/docs/superpowers/specs/2026-07-21-connection-list-alphabetical-sort-design.md
new file mode 100644
index 0000000000..37849a3221
--- /dev/null
+++ b/docs/superpowers/specs/2026-07-21-connection-list-alphabetical-sort-design.md
@@ -0,0 +1,133 @@
+# Connection List Alphabetical Sort Design
+
+**Date:** 2026-07-21
+
+## Goal
+
+Add a connection-list sort control to the desktop sidebar. Users can view saved
+connections by name in ascending or descending alphabetical order, without
+destroying their existing group and drag-and-drop layout.
+
+## Background
+
+The source repository was searched before this change. Issue #72, "连接分组和拖拽排序",
+is closed because DBX already supports groups and manual drag sorting. No issue
+or announced plan covers alphabetical ordering of connection names.
+
+The current sidebar builds its root tree from the persisted `SidebarLayout`.
+That layout captures manual root and group ordering. Rewriting it for an
+alphabetical view would silently discard a user's manual arrangement.
+
+## Requirements
+
+- provide ascending and descending connection-name ordering from the sidebar
+- retain a way to return to the saved manual order
+- sort connections both at the root and inside each connection group
+- keep connection groups themselves in their saved order
+- do not mutate the persisted drag-and-drop layout when changing display sort
+- remember the selected sort mode across application restarts
+- keep search, selection, expand/collapse state, and virtualized rendering
+ working
+
+## Chosen Approach
+
+### Sort mode
+
+Add `sidebarConnectionSortMode` to editor settings with three values:
+
+- `manual` — existing persisted drag-and-drop order (default)
+- `asc` — connection names from A to Z
+- `desc` — connection names from Z to A
+
+The setting is normalized on load and saved through the existing editor-settings
+store, so old profiles safely default to `manual`.
+
+### Display transformation
+
+Create a pure sidebar utility that produces a display-only tree:
+
+- it recursively visits only `connection-group` nodes
+- at every such level, it sorts only sibling nodes whose type is `connection`
+- it preserves the positions and order of group nodes and any non-connection
+ nodes
+- it copies only the group branches whose child order changes; stored tree nodes
+ remain unmodified
+- it uses an `Intl.Collator` with numeric, case-insensitive comparison; names
+ that compare equally retain their manual relative order
+
+`ConnectionTree.vue` uses this transformed tree before it applies the existing
+search filter and flattening flow. This means all of the existing selection and
+virtualization logic continues to operate on the currently visible order.
+
+### User interface
+
+Add a compact sort dropdown next to the existing sidebar locate and filter
+controls. It exposes:
+
+- Manual order
+- Name: A–Z
+- Name: Z–A
+
+The active mode has an accessible label and visible selected state. New labels
+are added to every supported locale, with fallback coverage for any locale that
+does not yet provide a translation.
+
+Manual drag-and-drop is disabled while either alphabetical sort is active. This
+avoids a misleading interaction in which a successful drag immediately appears
+to be undone by the active display sort. Switching back to `manual` restores
+the untouched stored layout and drag behavior.
+
+## Files And Boundaries
+
+- `apps/desktop/src/lib/sidebar/connectionListSort.ts` — pure ordering utility
+ and its Vitest coverage
+- `apps/desktop/src/stores/settingsStore.ts` — typed default, normalization,
+ and persistence update for the mode
+- `apps/desktop/src/components/sidebar/ConnectionTree.vue` — dropdown,
+ display-tree integration, and drag guard
+- `apps/desktop/src/i18n/locales/*.ts` — sort-control labels
+
+No Rust backend, connection storage schema, or sidebar-layout persistence code
+changes. Sorting is entirely a frontend presentation preference.
+
+## Error Handling And Compatibility
+
+- missing, invalid, or legacy setting values normalize to `manual`
+- empty trees and groups remain unchanged
+- duplicate or equivalent names remain stable in their manual order
+- filtering continues to run after display sorting, so disconnected-connection
+ filtering has no new special case
+
+## Testing
+
+- unit-test ascending and descending ordering
+- verify groups retain their relative order while root and nested connections
+ sort independently
+- verify manual mode returns original references/order and input trees are not
+ mutated
+- test editor-settings default, normalization, and persisted update behavior
+- run targeted Vitest tests, frontend typecheck, Rust fast check, and local
+ `make dev-fast` native startup
+
+## Scope Boundaries
+
+Included:
+
+- connection-name alphabetical ascending/descending display sorting
+- remembered sort mode
+- grouped connection support
+
+Not included:
+
+- sorting databases, schemas, tables, or other tree objects
+- replacing manual drag ordering
+- changing connection configuration or the persisted sidebar layout format
+- per-group independent sort preferences
+
+## Success Criteria
+
+- a user can choose A–Z or Z–A from the sidebar and see all connections sorted
+ accordingly within their current groups
+- manual ordering can be restored without data loss
+- the chosen mode survives restart
+- native local startup completes with the control present and functional