import { Dictionary, groupBy } from 'lodash'; import { useMemo } from 'react'; import { ScopesTreeHeadline } from './ScopesTreeHeadline'; import { ScopesTreeItem } from './ScopesTreeItem'; import { ScopesTreeLoading } from './ScopesTreeLoading'; import { ScopesTreeSearch } from './ScopesTreeSearch'; import { Node, NodeReason, NodesMap, OnNodeSelectToggle, OnNodeUpdate, TreeScope } from './types'; export interface ScopesTreeProps { nodes: NodesMap; nodePath: string[]; loadingNodeName: string | undefined; scopes: TreeScope[]; onNodeUpdate: OnNodeUpdate; onNodeSelectToggle: OnNodeSelectToggle; } export function ScopesTree({ nodes, nodePath, loadingNodeName, scopes, onNodeUpdate, onNodeSelectToggle, }: ScopesTreeProps) { const nodeId = nodePath[nodePath.length - 1]; const node = nodes[nodeId]; const childNodes = Object.values(node.nodes); const isNodeLoading = loadingNodeName === nodeId; const scopeNames = scopes.map(({ scopeName }) => scopeName); const anyChildExpanded = childNodes.some(({ isExpanded }) => isExpanded); const groupedNodes: Dictionary = useMemo(() => groupBy(childNodes, 'reason'), [childNodes]); const isLastExpandedNode = !anyChildExpanded && node.isExpanded; return ( <> ); }