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): preserve Mongo collection children in search

二丫讲梵ddf6b3ed6b1b
diff --git a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts b/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts
index f30704e589..73f8d6bb37 100644
--- a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts
@@ -1,7 +1,7 @@
import type { TreeNode, TreeNodeType } from "@/types/database";
import { createSidebarLabelMatcher, type SidebarLabelMatcher } from "@/lib/sidebar/sidebarSearch";
-const preserveMatchedSubtreeTypes = new Set(["connection", "database", "schema", "table", "view"]);
+const preserveMatchedSubtreeTypes = new Set(["connection", "database", "schema", "table", "view", "mongo-db", "mongo-collection"]);
const normalizedLabelCache = new WeakMap<TreeNode, { label: string; normalized: string }>();
diff --git a/packages/app-tests/sidebarSearchTree.test.ts b/packages/app-tests/sidebarSearchTree.test.ts
index 30ec2ad37f..7f4843c117 100644
--- a/packages/app-tests/sidebarSearchTree.test.ts
+++ b/packages/app-tests/sidebarSearchTree.test.ts
@@ -84,6 +84,97 @@ test("preserves loaded schema children when the database itself matches search",
assert.equal(filtered[0]?.children?.[0]?.label, "public");
});
+test("preserves loaded MongoDB collection children when the database itself matches search", () => {
+ const nodes: TreeNode[] = [
+ {
+ id: "conn:analytics",
+ label: "analytics",
+ type: "mongo-db",
+ connectionId: "conn",
+ database: "analytics",
+ isExpanded: true,
+ children: [
+ {
+ id: "conn:analytics:__gridfs",
+ label: "tree.gridfs",
+ type: "mongo-gridfs",
+ connectionId: "conn",
+ database: "analytics",
+ isExpanded: false,
+ },
+ {
+ id: "conn:analytics:orders",
+ label: "orders",
+ type: "mongo-collection",
+ connectionId: "conn",
+ database: "analytics",
+ isExpanded: false,
+ },
+ ],
+ },
+ ];
+
+ const filtered = filterSidebarTree(nodes, "analytics", new Set());
+
+ assert.equal(filtered[0]?.label, "analytics");
+ assert.deepEqual(
+ filtered[0]?.children?.map((child) => child.type),
+ ["mongo-gridfs", "mongo-collection"],
+ );
+ assert.equal(filtered[0]?.children?.[1]?.label, "orders");
+});
+
+test("preserves loaded MongoDB collection groups when the collection itself matches search", () => {
+ const nodes: TreeNode[] = [
+ {
+ id: "conn:analytics",
+ label: "analytics",
+ type: "mongo-db",
+ connectionId: "conn",
+ database: "analytics",
+ isExpanded: true,
+ children: [
+ {
+ id: "conn:analytics:orders",
+ label: "orders",
+ type: "mongo-collection",
+ connectionId: "conn",
+ database: "analytics",
+ isExpanded: true,
+ children: [
+ {
+ id: "conn:analytics:orders:__columns",
+ label: "tree.columns",
+ type: "group-columns",
+ connectionId: "conn",
+ database: "analytics",
+ tableName: "orders",
+ isExpanded: true,
+ children: [
+ {
+ id: "conn:analytics:orders:__columns:_id",
+ label: "_id",
+ type: "column",
+ connectionId: "conn",
+ database: "analytics",
+ tableName: "orders",
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ ];
+
+ const filtered = filterSidebarTree(nodes, "orders", new Set());
+
+ const collection = filtered[0]?.children?.[0];
+ assert.equal(collection?.label, "orders");
+ assert.equal(collection?.children?.[0]?.label, "tree.columns");
+ assert.equal(collection?.children?.[0]?.children?.[0]?.label, "_id");
+});
+
test("preserves loaded children when the connection itself matches search", () => {
const nodes: TreeNode[] = [
{