diff --git a/desktop/plugins/public/ui-debugger/components/Tree2.tsx b/desktop/plugins/public/ui-debugger/components/Tree2.tsx index 3f97873bc..056ef56ff 100644 --- a/desktop/plugins/public/ui-debugger/components/Tree2.tsx +++ b/desktop/plugins/public/ui-debugger/components/Tree2.tsx @@ -6,6 +6,7 @@ * * @format */ + import {Id, UINode} from '../types'; import React from 'react'; import { @@ -18,6 +19,7 @@ import { useValue, } from 'flipper-plugin'; import {plugin} from '../index'; +import {Glyph} from 'flipper'; export function Tree2({ nodes, @@ -56,6 +58,7 @@ export function Tree2({ export type TreeNode = UINode & { depth: number; + isExpanded: boolean; }; function TreeItemContainer({ @@ -69,6 +72,7 @@ function TreeItemContainer({ hoveredNode?: Id; onSelectNode: (node?: Id) => void; }) { + const instance = usePlugin(plugin); return ( - {/*{arrow}*/} - {defaultIcon(treeNode)} + { + instance.uiState.expandedNodes.update((draft) => { + if (draft.has(treeNode.id)) { + draft.delete(treeNode.id); + } else { + draft.add(treeNode.id); + } + }); + }} + /> + + {nodeIcon(treeNode)} ); @@ -100,12 +116,29 @@ const TreeItem = styled.li<{ backgroundColor: isSelected ? theme.selectionBackgroundColor : theme.white, })); +function Arrow(props: {onClick: () => void; expanded: boolean}) { + return ( +
+ +
+ ); +} + function HighlightedText(props: {text: string}) { const highlightManager: HighlightManager = useHighlighter(); return {highlightManager.render(props.text)}; } -function defaultIcon(node: UINode) { +function nodeIcon(node: UINode) { if (node.tags.includes('Litho')) { return ; } @@ -122,21 +155,27 @@ const renderDepthOffset = 4; function toTreeList( nodes: Map, rootId: Id, - expanded: Set, + expandedNodes: Set, ): TreeNode[] { - const stack = [[nodes.get(rootId), 0]] as [UINode, number][]; + const root = nodes.get(rootId); + if (root == null) { + return []; + } + const stack = [[root, 0]] as [UINode, number][]; const res = [] as TreeNode[]; while (stack.length > 0) { const [cur, depth] = stack.pop()!!; + const isExpanded = expandedNodes.has(cur.id); res.push({ ...cur, depth, + isExpanded, }); - if (expanded.has(cur.id)) { + if (isExpanded) { for (const childId of cur.children) { const child = nodes.get(childId); if (child != null) {