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): preserve unloaded container nodes when filtering by type (#13762)
lxk95559f25abce60e
diff --git a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts b/apps/desktop/src/lib/sidebar/sidebarSearchTree.tsindex 034e764b66..6cef1c37f1 100644--- a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts+++ b/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts@@ -377,6 +377,60 @@ function preservedSearchChildren(node: TreeNode, collapsedIds: ReadonlySet<strinreturn node.children.filter((child) => !hiddenSearchNodeTypes.has(child.type)).map((child) => applySearchCollapsedState(child, collapsedIds));}+const typeFilterDatabaseDescendantTypes = new Set<TreeNodeType>([+ "database",+ "redis-db",+ "mq-tenant",+ "nacos-namespace",+ "consul-root",+ "mongo-db",+ "doris-catalog",+ "linked-server",+ "linked-server-catalog",+ "linked-server-schema",+ "schema",+ "table",+ "mongo-collection",+ "mongo-bucket",+ "dynamodb-table",+ "vector-collection",+ "elasticsearch-index",+ "view",+ "materialized_view",+]);++const typeFilterSchemaDescendantTypes = new Set<TreeNodeType>(["schema", "linked-server-schema", "table", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index", "view", "materialized_view"]);++const typeFilterTableDescendantTypes = new Set<TreeNodeType>(["table", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index", "view", "materialized_view"]);++function isUnloadedTypeFilterContainer(node: TreeNode, searchableNodeTypes: ReadonlySet<TreeNodeType>): boolean {+ if (node.children && node.children.length > 0) return false;+ if (searchableNodeTypes.has(node.type)) return false;++ if (node.type === "connection") {+ for (const type of searchableNodeTypes) {+ if (typeFilterDatabaseDescendantTypes.has(type)) return true;+ }+ return false;+ }++ if (node.type === "database" || node.type === "redis-db" || node.type === "mongo-db" || node.type === "doris-catalog" || node.type === "linked-server") {+ for (const type of searchableNodeTypes) {+ if (typeFilterSchemaDescendantTypes.has(type)) return true;+ }+ return false;+ }++ if (node.type === "schema" || node.type === "linked-server-schema" || node.type === "group-tables" || node.type === "group-views" || node.type === "table-vgroup") {+ for (const type of searchableNodeTypes) {+ if (typeFilterTableDescendantTypes.has(type)) return true;+ }+ return false;+ }++ return false;+}+function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabelMatcher | undefined, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>, resolveLabel?: (node: TreeNode) => string, query?: string): TreeNode[] {const filteredNodes: { node: TreeNode; score: number }[] = [];@@ -410,13 +464,16 @@ function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabe// A type-matched table keeps its loaded detail groups after the text query// is cleared instead of being rebuilt with an empty filtered child list.const preservesTypeMatchedTable = !matchLabel && !!selfMatch && node.type === "table";+ // Unloaded container nodes (such as unexpanded connections or database-level containers)+ // must be preserved during type-only filtering so the user can access and expand them.+ const isUnloadedContainer = !matchLabel && !!searchableNodeTypes && isUnloadedTypeFilterContainer(node, searchableNodeTypes);// Connection utility entries are synthetic navigation actions, not schema// search results. Keep real loaded descendants for connection-name matches,// but do not let those actions make a disconnected result look expanded.const filteredChildren = preservesSubtree ? preservedSearchChildren(node, collapsedIds) : node.children ? filterSidebarTreeWithMatcher(node.children, matchLabel, collapsedIds, searchableNodeTypes, resolveLabel, query) : undefined;- if (selfMatch || (filteredChildren && filteredChildren.length > 0)) {- if (!node.children || preservesTypeMatchedTable) {+ if (selfMatch || (filteredChildren && filteredChildren.length > 0) || isUnloadedContainer) {+ if (!node.children || preservesTypeMatchedTable || isUnloadedContainer) {filteredNodes.push({ node, score: selfMatch?.score ?? 0 });} else {const children = filteredChildren ?? [];diff --git a/packages/app-tests/sidebarSearchTree.test.ts b/packages/app-tests/sidebarSearchTree.test.tsindex cfccdd141e..7066574ed1 100644--- a/packages/app-tests/sidebarSearchTree.test.ts+++ b/packages/app-tests/sidebarSearchTree.test.ts@@ -1267,3 +1267,103 @@ test("connection search copies preserve loading state", () => {assert.equal(filtered[0]?.type, "connection");assert.equal(filtered[0]?.isLoading, true);});++test("preserves unloaded connections and connection-groups when filtering by database or table type without text query (#13741)", () => {+ const unopenedConnection: TreeNode = {+ id: "conn:unopened",+ label: "350A(MySQL)",+ type: "connection",+ connectionId: "conn:unopened",+ isExpanded: false,+ children: [],+ };+ const groupedConnection: TreeNode = {+ id: "conn:grouped",+ label: "Local-Oracle",+ type: "connection",+ connectionId: "conn:grouped",+ isExpanded: false,+ children: [],+ };+ const group: TreeNode = {+ id: "group:navicat",+ label: "Navicat",+ type: "connection-group",+ isExpanded: true,+ children: [groupedConnection],+ };+ const nodes = [group, unopenedConnection];++ // Filtering by database type keeps unloaded connections so the user can open them+ const filteredByDb = filterSidebarTree(nodes, "", new Set(), new Set(["database"]));+ assert.equal(filteredByDb.length, 2);+ assert.equal(filteredByDb[0]?.id, "group:navicat");+ assert.equal(filteredByDb[0]?.children?.[0]?.id, "conn:grouped");+ assert.equal(filteredByDb[1]?.id, "conn:unopened");++ // Filtering by table type also keeps unloaded connections+ const filteredByTable = filterSidebarTree(nodes, "", new Set(), new Set(["table"]));+ assert.equal(filteredByTable.length, 2);+ assert.equal(filteredByTable[0]?.id, "group:navicat");+ assert.equal(filteredByTable[1]?.id, "conn:unopened");++ // However, searching for a non-matching text query still filters them out+ const filteredWithQuery = filterSidebarTree(nodes, "nonexistent", new Set(), new Set(["database"]));+ assert.equal(filteredWithQuery.length, 0);+});++test("preserves unexpanded database containers when filtering by table type without text query (#13741)", () => {+ const unexpandedDb: TreeNode = {+ id: "conn:1:db:unexpanded",+ label: "unexpanded_db",+ type: "database",+ connectionId: "conn:1",+ database: "unexpanded_db",+ isExpanded: false,+ children: [],+ };+ const expandedDbWithTable: TreeNode = {+ id: "conn:1:db:expanded",+ label: "expanded_db",+ type: "database",+ connectionId: "conn:1",+ database: "expanded_db",+ isExpanded: true,+ children: [+ {+ id: "conn:1:db:expanded:users",+ label: "users",+ type: "table",+ connectionId: "conn:1",+ database: "expanded_db",+ },+ {+ id: "conn:1:db:expanded:user_view",+ label: "user_view",+ type: "view",+ connectionId: "conn:1",+ database: "expanded_db",+ },+ ],+ };+ const conn: TreeNode = {+ id: "conn:1",+ label: "MySQL",+ type: "connection",+ connectionId: "conn:1",+ isExpanded: true,+ children: [unexpandedDb, expandedDbWithTable],+ };++ const filtered = filterSidebarTree([conn], "", new Set(), new Set(["table"]));+ assert.equal(filtered.length, 1);+ assert.equal(filtered[0]?.children?.length, 2);+ // Unexpanded database is kept as an unloaded table container+ assert.equal(filtered[0]?.children?.[0]?.id, "conn:1:db:unexpanded");+ // Expanded database is kept, but only its tables survive (views pruned)+ assert.equal(filtered[0]?.children?.[1]?.id, "conn:1:db:expanded");+ assert.deepEqual(+ filtered[0]?.children?.[1]?.children?.map((child) => child.label),+ ["users"],+ );+});