From 65d6089ed278c932d21b6de7c4c8f164c1c8fc5f Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Mon, 12 Dec 2022 07:28:37 -0800 Subject: [PATCH] Added context menu and focus mode Reviewed By: antonk52 Differential Revision: D41838172 fbshipit-source-id: 7c5fad5a7520cea5f0dbabb9f99ef436ad87ec60 --- .../public/ui-debugger/components/Tree2.tsx | 106 +++++++++++++----- 1 file changed, 76 insertions(+), 30 deletions(-) diff --git a/desktop/plugins/public/ui-debugger/components/Tree2.tsx b/desktop/plugins/public/ui-debugger/components/Tree2.tsx index 0d89f74b8..80e72a392 100644 --- a/desktop/plugins/public/ui-debugger/components/Tree2.tsx +++ b/desktop/plugins/public/ui-debugger/components/Tree2.tsx @@ -30,6 +30,8 @@ import {plugin} from '../index'; import {Glyph} from 'flipper'; import {head} from 'lodash'; import {reverse} from 'lodash/fp'; +import {Dropdown, Menu} from 'antd'; +import {UIDebuggerMenuItem} from './util/UIDebuggerMenuItem'; export function Tree2({ nodes, @@ -43,18 +45,19 @@ export function Tree2({ onSelectNode: (node?: Id) => void; }) { const instance = usePlugin(plugin); + const focusedNode = useValue(instance.uiState.focusedNode); const expandedNodes = useValue(instance.uiState.expandedNodes); const searchTerm = useValue(instance.uiState.searchTerm); const {treeNodes, refs} = useMemo(() => { - const treeNodes = toTreeList(nodes, rootId, expandedNodes); + const treeNodes = toTreeList(nodes, focusedNode || rootId, expandedNodes); const refs: React.RefObject[] = treeNodes.map(() => React.createRef(), ); return {treeNodes, refs}; - }, [expandedNodes, nodes, rootId]); + }, [expandedNodes, focusedNode, nodes, rootId]); const isUsingKBToScroll = useRef(false); @@ -121,35 +124,40 @@ function TreeItemContainer({ const instance = usePlugin(plugin); const isHovered = useIsHovered(treeNode.id); return ( - { - if (isUsingKBToScroll.current === false) { - instance.uiState.hoveredNodes.set([treeNode.id]); - } - }} - onClick={() => { - onSelectNode(treeNode.id); - }} - item={treeNode}> - { - instance.uiState.expandedNodes.update((draft) => { - if (draft.has(treeNode.id)) { - draft.delete(treeNode.id); - } else { - draft.add(treeNode.id); - } - }); + + { + if ( + isUsingKBToScroll.current === false && + instance.uiState.isContextMenuOpen.get() == false + ) { + instance.uiState.hoveredNodes.set([treeNode.id]); + } }} - /> - {nodeIcon(treeNode)} - - + onClick={() => { + onSelectNode(treeNode.id); + }} + item={treeNode}> + { + instance.uiState.expandedNodes.update((draft) => { + if (draft.has(treeNode.id)) { + draft.delete(treeNode.id); + } else { + draft.add(treeNode.id); + } + }); + }} + /> + {nodeIcon(treeNode)} + + + ); } @@ -232,6 +240,44 @@ const DecorationImage = styled.img({ const renderDepthOffset = 4; +const ContextMenu: React.FC<{node: TreeNode}> = ({node, children}) => { + const instance = usePlugin(plugin); + const focusedNode = instance.uiState.focusedNode.get(); + + return ( + { + instance.uiState.isContextMenuOpen.set(visible); + }} + overlay={() => ( + + {focusedNode !== head(instance.uiState.hoveredNodes.get()) && ( + { + instance.uiState.focusedNode.set(node.id); + }} + /> + )} + + {focusedNode && ( + { + instance.uiState.focusedNode.set(undefined); + }} + /> + )} + + )} + trigger={['contextMenu']}> +
{children}
+
+ ); +}; + function toTreeList( nodes: Map, rootId: Id,