(
nodes: T[],
depth = 0,
collapsedState: Record<string, boolean> = {}
)
| 606 | } |
| 607 | |
| 608 | function createNodeItems<T extends { id: string; children?: T[] }>( |
| 609 | nodes: T[], |
| 610 | depth = 0, |
| 611 | collapsedState: Record<string, boolean> = {} |
| 612 | ): TreeNodeItem<T>[] { |
| 613 | return nodes.flatMap((node, index) => { |
| 614 | const children = node.children |
| 615 | ? collapsedState[node.id] |
| 616 | ? [] |
| 617 | : createNodeItems(node.children, depth + 1, collapsedState) |
| 618 | : []; |
| 619 | return [ |
| 620 | { |
| 621 | id: node.id, |
| 622 | depth, |
| 623 | node, |
| 624 | pos: index + 1, |
| 625 | size: nodes.length, |
| 626 | isCollapsed: !!collapsedState[node.id], |
| 627 | }, |
| 628 | ...children, |
| 629 | ]; |
| 630 | }); |
| 631 | } |
| 632 | |
| 633 | function createTreeProps<T extends { id: string; children?: T[] }>( |
| 634 | dispatch: Dispatch<TreeAction> |
no outgoing calls
no test coverage detected