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。

fix(sidebar): sort connection groups and nested groups in display sort mode (#13743)

lxk955442895749a0f
diff --git a/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts b/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts
index 81447e0941..ef4355caa8 100644
--- a/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sidebar/connectionListSort.spec.ts
@@ -50,4 +50,42 @@ describe("connection list display sort", () => {
expect(orderConnectionsForSidebarDisplay(connections, tree, "asc").map((connection) => connection.id)).toEqual(["alpha", "beta", "zebra"]);
});
+
+ it("sorts multiple root connection groups in ascending and descending order (#13738)", () => {
+ const tree = [group("group-z", "Zeta Group", [connection("conn-1", "Conn 1")]), group("group-b", "Beta Group", [connection("conn-2", "Conn 2")]), group("group-a", "Alpha Group", [connection("conn-3", "Conn 3")])];
+
+ const asc = sortConnectionListForDisplay(tree, "asc");
+ expect(asc.map((node) => node.id)).toEqual(["group-a", "group-b", "group-z"]);
+
+ const desc = sortConnectionListForDisplay(tree, "desc");
+ expect(desc.map((node) => node.id)).toEqual(["group-z", "group-b", "group-a"]);
+ });
+
+ it("sorts newly created group into its alphabetical position (#13738)", () => {
+ // When a new group is created, it is appended to the bottom in manual order.
+ const initialTree = [group("group-prod", "Production", [connection("c-prod", "Prod")]), group("group-staging", "Staging", [connection("c-stg", "Staging")])];
+ // Newly created group appended at the end
+ const treeWithNewGroup = [...initialTree, group("group-dev", "Development", [connection("c-dev", "Dev")])];
+
+ const sortedAsc = sortConnectionListForDisplay(treeWithNewGroup, "asc");
+ expect(sortedAsc.map((node) => node.id)).toEqual(["group-dev", "group-prod", "group-staging"]);
+ });
+
+ it("sorts nested subgroups within a connection group (#13738)", () => {
+ const tree = [group("parent", "Parent Group", [group("sub-z", "Sub Z", [connection("c-1", "Conn 1")]), group("sub-a", "Sub A", [connection("c-2", "Conn 2")])])];
+
+ const sortedAsc = sortConnectionListForDisplay(tree, "asc");
+ expect(sortedAsc[0]?.children?.map((node) => node.id)).toEqual(["sub-a", "sub-z"]);
+
+ const sortedDesc = sortConnectionListForDisplay(tree, "desc");
+ expect(sortedDesc[0]?.children?.map((node) => node.id)).toEqual(["sub-z", "sub-a"]);
+ });
+
+ it("projects configs with multiple groups ordered alphabetically (#13738)", () => {
+ const connections = [{ id: "c-z" }, { id: "c-a" }];
+ const tree = [group("group-z", "Zeta Group", [connection("c-z", "Z Conn")]), group("group-a", "Alpha Group", [connection("c-a", "A Conn")])];
+
+ expect(orderConnectionsForSidebarDisplay(connections, tree, "asc").map((c) => c.id)).toEqual(["c-a", "c-z"]);
+ expect(orderConnectionsForSidebarDisplay(connections, tree, "desc").map((c) => c.id)).toEqual(["c-z", "c-a"]);
+ });
});
diff --git a/apps/desktop/src/lib/sidebar/connectionListSort.ts b/apps/desktop/src/lib/sidebar/connectionListSort.ts
index ff0c786796..5473dc187d 100644
--- a/apps/desktop/src/lib/sidebar/connectionListSort.ts
+++ b/apps/desktop/src/lib/sidebar/connectionListSort.ts
@@ -15,24 +15,42 @@ function sortConnectionSiblingsForDisplay(nodes: readonly TreeNode[], mode: Excl
})
.map(({ node }) => node);
+ const sortedGroups = nodes
+ .map((node, index) => ({ node, index }))
+ .filter(({ node }) => node.type === "connection-group")
+ .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 }) => {
+ if (!node.children) return node;
+ const children = sortConnectionSiblingsForDisplay(node.children, mode);
+ return children === node.children ? node : { ...node, children };
+ });
+
let nextConnectionIndex = 0;
+ let nextGroupIndex = 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 };
+ if (node.type === "connection-group") {
+ return sortedGroups[nextGroupIndex++]!;
+ }
+
+ return node;
});
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.
+ * Produces a display-only ordering of saved connections. In asc/desc modes
+ * both connections and groups are ordered by name; the persisted manual
+ * layout remains 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[];