🐛 fix(sidebar): 修复元数据展示开关未过滤嵌套对象

- 修复子节点数量不变时误复用未过滤父节点的问题
- 保留标签、连接、数据库与 Schema 包装层中的深层过滤结果
- 补充多层侧栏树对象显隐回归测试
This commit is contained in:
Syngnat
2026-07-16 15:56:15 +08:00
parent 0080cb33ac
commit dfa6836580
2 changed files with 59 additions and 2 deletions

View File

@@ -42,6 +42,60 @@ describe('sidebar object visibility', () => {
]);
});
it('keeps filtered descendants when wrapper child counts stay unchanged', () => {
const tree = [{
key: 'connection-1',
type: 'connection',
children: [{
key: 'database-1',
type: 'database',
children: [
{ key: 'database-1-tables', type: 'object-group', dataRef: { groupKey: 'tables' } },
{ key: 'database-1-views', type: 'object-group', dataRef: { groupKey: 'views' } },
{ key: 'database-1-routines', type: 'object-group', dataRef: { groupKey: 'routines' } },
],
}],
}];
const filtered = filterSidebarTreeByHiddenObjectGroups(tree, ['views', 'routines']);
expect(filtered[0].children?.[0].children?.map((node) => node.key)).toEqual([
'database-1-tables',
]);
expect(filtered[0]).not.toBe(tree[0]);
expect(filtered[0].children?.[0]).not.toBe(tree[0].children[0]);
});
it('keeps deeply filtered schema descendants through tag and connection wrappers', () => {
const tree = [{
key: 'tag-1',
type: 'tag',
children: [{
key: 'connection-1',
type: 'connection',
children: [{
key: 'database-1',
type: 'database',
children: [{
key: 'database-1-public',
type: 'object-group',
dataRef: { groupKey: 'schema' },
children: [
{ key: 'public-tables', type: 'object-group', dataRef: { groupKey: 'tables' } },
{ key: 'public-events', type: 'object-group', dataRef: { groupKey: 'events' } },
],
}],
}],
}],
}];
const filtered = filterSidebarTreeByHiddenObjectGroups(tree, ['events']);
expect(filtered[0].children?.[0].children?.[0].children?.[0].children?.map((node) => node.key)).toEqual([
'public-tables',
]);
});
it('drops invalid and duplicate persisted object group keys', () => {
expect(sanitizeSidebarHiddenObjectGroups([
'views',

View File

@@ -63,9 +63,12 @@ export const filterSidebarTreeByHiddenObjectGroups = <T extends SidebarObjectVis
if (objectGroupKey && hidden.has(objectGroupKey)) return [];
if (!node.children || node.children.length === 0) return [node];
const children = filterSidebarTreeByHiddenObjectGroups(node.children as T[], hiddenObjectGroups);
const originalChildren = node.children;
const children = filterSidebarTreeByHiddenObjectGroups(originalChildren as T[], hiddenObjectGroups);
if (isSchemaGroupNode(node) && children.length === 0) return [];
if (children.length === node.children.length) return [node];
const childrenUnchanged = children.length === originalChildren.length
&& children.every((child, index) => child === originalChildren[index]);
if (childrenUnchanged) return [node];
return [{
...node,