From 52eacdd9df5094010cf93099390a188d5dab86e8 Mon Sep 17 00:00:00 2001 From: Syngnat Date: Tue, 30 Jun 2026 21:46:13 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(sidebar):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=A1=A8=E5=88=86=E7=BB=84=E6=8A=98=E5=8F=A0=E5=90=8E?= =?UTF-8?q?=E4=BA=8C=E6=AC=A1=E5=B1=95=E5=BC=80=E6=B6=88=E5=A4=B1=20Fixes?= =?UTF-8?q?=20#606?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 限制侧边栏折叠时的子树释放范围,只清理可重新懒加载的 connection/database 节点 - 保留 tables object-group 的已加载子节点,避免二次点击展开后表列表被清空 - 补充针对大表分组折叠场景的回归测试 --- .../sidebarV2Utils.command-search.test.ts | 31 +++++++++++-------- frontend/src/components/sidebarV2Utils.ts | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/sidebarV2Utils.command-search.test.ts b/frontend/src/components/sidebarV2Utils.command-search.test.ts index 2c77363e..e17dc900 100644 --- a/frontend/src/components/sidebarV2Utils.command-search.test.ts +++ b/frontend/src/components/sidebarV2Utils.command-search.test.ts @@ -116,28 +116,33 @@ describe('sidebarV2 command search performance helpers', () => { })).toEqual(['conn-1-db-a', 'conn-1-db-b']); }); - it('clears only large loaded sidebar subtrees on collapse', () => { - const routineChildren = Array.from({ length: 180 }, (_, index) => ({ - key: `routine-${index}`, - title: `routine_${index}`, - type: 'routine' as const, + it('keeps large table groups loaded on collapse and only unloads reloadable database trees', () => { + const tableChildren = Array.from({ length: 180 }, (_, index) => ({ + key: `table-${index}`, + title: `table_${index}`, + type: 'table' as const, })); - const largeRoutineGroup = { - key: 'conn-1-db-a-routines', - title: '函数', + const largeTableGroup = { + key: 'conn-1-db-a-tables', + title: '表', type: 'object-group' as const, - children: routineChildren, + dataRef: { groupKey: 'tables' }, + children: tableChildren, }; - expect(collectSidebarSubtreeKeys(largeRoutineGroup)).toHaveLength(180); - expect(shouldClearSidebarNodeChildrenOnCollapse(largeRoutineGroup)).toBe(true); + expect(collectSidebarSubtreeKeys(largeTableGroup)).toHaveLength(180); + expect(shouldClearSidebarNodeChildrenOnCollapse(largeTableGroup)).toBe(false); expect(shouldClearSidebarNodeChildrenOnCollapse({ type: 'object-group', - children: routineChildren.slice(0, 8), + children: tableChildren.slice(0, 8), })).toBe(false); + expect(shouldClearSidebarNodeChildrenOnCollapse({ + type: 'database', + children: tableChildren, + })).toBe(true); expect(shouldClearSidebarNodeChildrenOnCollapse({ type: 'table', - children: routineChildren, + children: tableChildren, })).toBe(false); }); }); diff --git a/frontend/src/components/sidebarV2Utils.ts b/frontend/src/components/sidebarV2Utils.ts index f7154023..4eb449d9 100644 --- a/frontend/src/components/sidebarV2Utils.ts +++ b/frontend/src/components/sidebarV2Utils.ts @@ -825,7 +825,7 @@ export const shouldClearSidebarNodeChildrenOnCollapse = ( if (!node || node.isLeaf === true || !node.children?.length) { return false; } - if (node.type !== 'connection' && node.type !== 'database' && node.type !== 'object-group') { + if (node.type !== 'connection' && node.type !== 'database') { return false; } return collectSidebarSubtreeKeys(node).length >= SIDEBAR_COLLAPSE_UNLOAD_SUBTREE_LIMIT;