🐛 fix(sidebar): 修复表分组折叠后二次展开消失 Fixes #606

- 限制侧边栏折叠时的子树释放范围,只清理可重新懒加载的 connection/database 节点

- 保留 tables object-group 的已加载子节点,避免二次点击展开后表列表被清空

- 补充针对大表分组折叠场景的回归测试
This commit is contained in:
Syngnat
2026-06-30 21:46:13 +08:00
parent a9bae6bb3f
commit 52eacdd9df
2 changed files with 19 additions and 14 deletions

View File

@@ -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);
});
});

View File

@@ -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;