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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sidebar): keep tables sorted by visible name
t8y20aab07e92325
diff --git a/apps/desktop/src/lib/tableTree.ts b/apps/desktop/src/lib/tableTree.tsindex 90be61d49c..531f0ab82a 100644--- a/apps/desktop/src/lib/tableTree.ts+++ b/apps/desktop/src/lib/tableTree.ts@@ -208,8 +208,12 @@ export function sortDatabaseObjectsByPrefixPriority<T>(items: readonly T[], getNreturn [...items].sort((left, right) => compareNames(getName(left), getName(right)));}+export function sortDatabaseObjectsByName<T>(items: readonly T[], getName: (item: T) => string): T[] {+ return [...items].sort((left, right) => databaseObjectNameCollator.compare(getName(left), getName(right)));+}+function buildPartitionTree(entries: TableTreeEntry[], connectionId: string, database: string): TreeNode[] {- const orderedEntries = sortDatabaseObjectsByPrefixPriority(entries, (entry) => entry.node.label);+ const orderedEntries = sortDatabaseObjectsByName(entries, (entry) => entry.node.label);const byKey = new Map<string, TableTreeEntry>();for (const entry of orderedEntries) {byKey.set(entry.key, entry);@@ -368,7 +372,7 @@ export function buildSimpleObjectTreeNodes({return [...buildPartitionTree(tableEntries, connectionId, database),- ...sortDatabaseObjectsByPrefixPriority(viewNodes, (node) => node.label),+ ...sortDatabaseObjectsByName(viewNodes, (node) => node.label),];}@@ -471,7 +475,7 @@ export function buildGroupedObjectTreeNodes({objects: items,objectType: def.objectTypes[0] as "TABLE" | "VIEW",})- : sortDatabaseObjectsByPrefixPriority(items, (obj) => obj.name).map((obj) => {+ : sortDatabaseObjectsByName(items, (obj) => obj.name).map((obj) => {const childSchema = obj.schema ? normalizeDatabaseObjectName(obj.schema) : schema;const objectType = normalizeObjectType(obj.object_type);const childType = typeof def.childType === "function" ? def.childType(objectType) : def.childType;diff --git a/packages/app-tests/tableTree.test.ts b/packages/app-tests/tableTree.test.tsindex 9a511f8a58..994cf4fdc5 100644--- a/packages/app-tests/tableTree.test.ts+++ b/packages/app-tests/tableTree.test.ts@@ -75,7 +75,7 @@ test("buildTableTreeNodes keeps partitions visible when their parent is not load);});-test("buildTableTreeNodes keeps base-prefixed tables before prefixed variants", () => {+test("buildTableTreeNodes keeps sidebar tables in natural name order", () => {const nodes = buildTableTreeNodes({nodeId: "conn:app:public",connectionId: "conn",@@ -86,7 +86,21 @@ test("buildTableTreeNodes keeps base-prefixed tables before prefixed variants",assert.deepEqual(nodes.map((node) => node.label),- ["staff", "staff_his", "chat_staff", "chat_staff_his"],+ ["chat_staff", "chat_staff_his", "staff", "staff_his"],+ );+});++test("buildTableTreeNodes does not relocate prefixed business tables by suffix", () => {+ const nodes = buildTableTreeNodes({+ nodeId: "conn:app",+ connectionId: "conn",+ database: "app",+ tables: [table("CurrentStock"), table("YonSuite_CurrentStock"), table("YonSuite_LocationStock")],+ });++ assert.deepEqual(+ nodes.map((node) => node.label),+ ["CurrentStock", "YonSuite_CurrentStock", "YonSuite_LocationStock"],);});@@ -112,7 +126,7 @@ test("buildGroupedObjectTreeNodes nests partitions inside the tables group", ());});-test("buildGroupedObjectTreeNodes applies prefix-priority sorting inside object groups", () => {+test("buildGroupedObjectTreeNodes applies natural name sorting inside object groups", () => {const groups = buildGroupedObjectTreeNodes({nodeId: "conn:app:public",connectionId: "conn",@@ -124,7 +138,7 @@ test("buildGroupedObjectTreeNodes applies prefix-priority sorting inside objectconst tableGroup = groups.find((node) => node.type === "group-tables");assert.deepEqual(tableGroup?.children?.map((node) => node.label),- ["staff", "staff_his", "chat_staff", "chat_staff_his"],+ ["chat_staff", "chat_staff_his", "staff", "staff_his"],);});