Files
dbx/apps/desktop/src/composables/useFlatTree.ts
T
二丫讲梵 af9ad39ffb feat(sidebar): 添加一键折叠所有节点功能
- 在侧边栏中添加了“折叠所有”按钮,用户可以一键折叠所有展开的节点。
- 更新了相关的国际化文本,支持多语言。
- 增加了 collapseAllGroups 和 collapseExpandedTreeNodes 函数以支持新功能。
2026-07-02 18:50:01 +08:00

39 lines
963 B
TypeScript

import type { TreeNode, TreeNodeType } from "@/types/database";
export const SIDEBAR_TREE_ROW_HEIGHT = 28;
export const SIDEBAR_TREE_SCROLL_BUFFER = 600;
export const SIDEBAR_TREE_PRERENDER_COUNT = 48;
export interface FlatTreeNode {
node: TreeNode;
depth: number;
id: string;
type: TreeNodeType;
poolType: string;
}
function walk(children: TreeNode[], depth: number, result: FlatTreeNode[]) {
for (const node of children) {
result.push({
node,
depth,
id: node.id,
type: node.type,
poolType: node.type === "connection-group" ? `${node.type}:${node.id}` : node.type,
});
if (node.isExpanded && node.children) {
walk(node.children, depth + 1, result);
}
}
}
export function flattenTree(nodes: TreeNode[]): FlatTreeNode[] {
const result: FlatTreeNode[] = [];
walk(nodes, 0, result);
return result;
}
export function shouldVirtualizeFlatTree(count: number): boolean {
return count > 0;
}