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 search results when re-expanding projection (#12766)
zhukj8398a462fb3c
diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vueindex 5ebeeed9d6..b750bdd09d 100644--- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue+++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue@@ -916,6 +916,14 @@ async function toggle(requestId = beginNavigationRequest()) {emit("search-toggle", node);const wasExpanded = !!node.isExpanded;+ // A search result is a projection over children that are already loaded for+ // the query. Expanding a collapsed result must only remove it from the+ // projection's collapsed set; entering the normal load path here can replace+ // the live subtree with the filtered projection and leave the sidebar blank.+ if (!wasExpanded && node.children?.length && sidebarTreeContext?.isSearchProjectionActive?.()) {+ return;+ }+if (node.type === "connection-group") {node.isExpanded = !node.isExpanded;if (!node.isExpanded) collapseSubtreeDescendants(node);diff --git a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.tsindex 328dd1e1aa..09b7df959e 100644--- a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts+++ b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts@@ -744,6 +744,57 @@ describe("SidebarTreeRuntimeHost expansion", () => {expect(connectionStore.releaseCollapsedTreeNodeChildren).not.toHaveBeenCalled();});+ it("expands a collapsed search projection without reloading its live subtree", async () => {+ const tableGroup: TreeNode = {+ id: "mysql:basic:__tables",+ label: "tree.tables",+ type: "group-tables",+ connectionId: "mysql",+ database: "basic",+ isExpanded: true,+ children: [{ id: "mysql:basic:__tables:json_orders", label: "json_orders", type: "table", connectionId: "mysql", database: "basic" }],+ };+ const database: TreeNode = {+ id: "mysql:basic",+ label: "basic",+ type: "database",+ connectionId: "mysql",+ database: "basic",+ isExpanded: false,+ children: [tableGroup],+ };+ connectionStore.sidebarSearchQuery = "json";+ const searchToggle = vi.fn();+ const nodeToggled = vi.fn();++ const host = ref<InstanceType<typeof SidebarTreeRuntimeHost> | null>(null);+ const app = createApp(+ defineComponent({+ setup() {+ provide(sidebarTreeContextKey, {+ getVisibleNodes: () => [database],+ getVisibleNodeIndex: () => 0,+ isSearchProjectionActive: () => true,+ });+ return () => h(SidebarTreeRuntimeHost, { ref: host, node: database, depth: 0, onSearchToggle: searchToggle, onNodeToggled: nodeToggled });+ },+ }),+ );+ mountedApps.push(app);+ const container = document.createElement("div");+ document.body.append(container);+ app.use(i18n);+ app.mount(container);++ host.value?.toggleNode(database);+ await nextTick();++ expect(searchToggle).toHaveBeenCalledWith(database);+ expect(nodeToggled).not.toHaveBeenCalled();+ expect(connectionStore.loadTables).not.toHaveBeenCalled();+ expect(connectionStore.releaseCollapsedTreeNodeChildren).not.toHaveBeenCalled();+ });+it("expands an unloaded object group without leaking a matching connection name", async () => {const group: TreeNode = {id: "mysql:basic:__tables",