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
feat(sidebar): apply type-only search filters
t8y2f468eb8f475a
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vueindex afab9270c8..38a9a5abb9 100644--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue@@ -325,8 +325,8 @@ const filteredNodes = computed(() => {let nodes = store.treeNodes;const q = deferredSearchQuery.value;+ nodes = filterSidebarTree(nodes, q, searchCollapsedIds.value, searchableNodeTypes.value);if (q) {- nodes = filterSidebarTree(nodes, q, searchCollapsedIds.value, searchableNodeTypes.value);nodes = filterSidebarSearchRootsByConnectionState(nodes, store.connectedIds);}diff --git a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts b/apps/desktop/src/lib/sidebar/sidebarSearchTree.tsindex 73f8d6bb37..926d6e334e 100644--- a/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts+++ b/apps/desktop/src/lib/sidebar/sidebarSearchTree.ts@@ -23,23 +23,32 @@ function normalizedLabel(node: TreeNode): string {}export function filterSidebarTree(nodes: TreeNode[], query: string, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>): TreeNode[] {- return filterSidebarTreeWithMatcher(nodes, createSidebarLabelMatcher(query), collapsedIds, searchableNodeTypes);+ const matchLabel = query ? createSidebarLabelMatcher(query) : undefined;+ if (!matchLabel && searchableNodeTypes === undefined) return nodes;+ return filterSidebarTreeWithMatcher(nodes, matchLabel, collapsedIds, searchableNodeTypes);}-function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabelMatcher, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>): TreeNode[] {+function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabelMatcher | undefined, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>): TreeNode[] {const filteredNodes: { node: TreeNode; score: number }[] = [];for (const node of nodes) {if (node.type === "object-browser" && node.hiddenChildren) {- const matches = node.hiddenChildren.map((child) => ({ node: child, score: matchLabel(normalizedLabel(child))?.score ?? 0 })).filter((match) => match.score > 0);+ const matches = node.hiddenChildren.flatMap((child) => {+ if (searchableNodeTypes && !searchableNodeTypes.has(child.type)) return [];+ const match = matchLabel?.(normalizedLabel(child));+ if (matchLabel && !match) return [];+ return [{ node: child, score: match?.score ?? 0 }];+ });filteredNodes.push(...matches);continue;}const label = normalizedLabel(node);const canSelfMatch = !searchableNodeTypes || searchableNodeTypes.has(node.type);- const selfMatch = canSelfMatch ? bestMatch(matchLabel, label, node.comment) : null;- const preservesSubtree = !!selfMatch && preserveMatchedSubtreeTypes.has(node.type);+ const selfMatch = canSelfMatch ? (matchLabel ? bestMatch(matchLabel, label, node.comment) : { score: 0 }) : null;+ // Type-only filtering keeps matching rows and their ancestor path, but not+ // unrelated descendants that would make the selected type appear ignored.+ const preservesSubtree = !!matchLabel && !!selfMatch && preserveMatchedSubtreeTypes.has(node.type);const filteredChildren = preservesSubtree ? node.children : node.children ? filterSidebarTreeWithMatcher(node.children, matchLabel, collapsedIds, searchableNodeTypes) : undefined;if (selfMatch || (filteredChildren && filteredChildren.length > 0)) {diff --git a/packages/app-tests/sidebarSearchTree.test.ts b/packages/app-tests/sidebarSearchTree.test.tsindex 7f4843c117..e3e1b25f31 100644--- a/packages/app-tests/sidebarSearchTree.test.ts+++ b/packages/app-tests/sidebarSearchTree.test.ts@@ -274,6 +274,106 @@ test("search scope excludes non-selected node self matches", () => {assert.equal(filtered.length, 0);});+function scopedSearchNodes(): TreeNode[] {+ return [+ {+ id: "conn:1",+ label: "warehouse",+ type: "connection",+ connectionId: "conn:1",+ isExpanded: true,+ children: [+ {+ id: "conn:1:db",+ label: "inventory",+ type: "database",+ connectionId: "conn:1",+ database: "inventory",+ isExpanded: true,+ children: [+ {+ id: "conn:1:db:sales-order",+ label: "sales_order",+ type: "schema",+ connectionId: "conn:1",+ database: "inventory",+ schema: "sales_order",+ isExpanded: true,+ children: [+ {+ id: "conn:1:db:sales-order:orders",+ label: "orders",+ type: "table",+ connectionId: "conn:1",+ database: "inventory",+ schema: "sales_order",+ },+ ],+ },+ {+ id: "conn:1:db:audit",+ label: "audit",+ type: "schema",+ connectionId: "conn:1",+ database: "inventory",+ schema: "audit",+ isExpanded: true,+ children: [+ {+ id: "conn:1:db:audit:order-log",+ label: "order_log",+ type: "table",+ connectionId: "conn:1",+ database: "inventory",+ schema: "audit",+ },+ ],+ },+ ],+ },+ ],+ },+ ];+}++test("filters the sidebar by node type without a text query", () => {+ const filtered = filterSidebarTree(scopedSearchNodes(), "", new Set(), new Set(["schema"]));++ const schemas = filtered[0]?.children?.[0]?.children;+ assert.deepEqual(+ schemas?.map((node) => node.label),+ ["sales_order", "audit"],+ );+ assert.deepEqual(+ schemas?.map((node) => node.children),+ [[], []],+ );+});++test("combines text search with the selected node types", () => {+ const filtered = filterSidebarTree(scopedSearchNodes(), "order", new Set(), new Set(["schema"]));++ assert.deepEqual(+ filtered[0]?.children?.[0]?.children?.map((node) => node.label),+ ["sales_order"],+ );+});++test("clearing the type filter restores default text search", () => {+ const filtered = filterSidebarTree(scopedSearchNodes(), "order", new Set());++ assert.deepEqual(+ filtered[0]?.children?.[0]?.children?.map((node) => node.label),+ ["sales_order", "audit"],+ );+});++test("clearing all search criteria preserves the original tree", () => {+ const nodes = scopedSearchNodes();++ assert.equal(filterSidebarTree(nodes, "", new Set()), nodes);+});+test("connection search results stay visible before connecting", () => {const nodes: TreeNode[] = [{