diff --git a/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx b/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx index 21087b5be..f02e21805 100644 --- a/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx +++ b/desktop/plugins/public/ui-debugger/components/visualizer/Visualization2D.tsx @@ -7,21 +7,15 @@ * @format */ -import React, {ReactNode, useEffect, useMemo, useRef, useState} from 'react'; +import React, {useEffect, useMemo, useRef} from 'react'; import {Bounds, Coordinate, Id, ClientNode} from '../../ClientTypes'; import {NestedNode, OnSelectNode} from '../../DesktopTypes'; import {produce, styled, theme, usePlugin, useValue} from 'flipper-plugin'; import {plugin} from '../../index'; import {head, isEqual, throttle} from 'lodash'; -import {Dropdown, Menu, Tooltip} from 'antd'; -import {UIDebuggerMenuItem} from '../util/UIDebuggerMenuItem'; import {useDelay} from '../../hooks/useDelay'; -import { - AimOutlined, - FullscreenExitOutlined, - FullscreenOutlined, -} from '@ant-design/icons'; +import {Tooltip} from 'antd'; export const Visualization2D: React.FC< { @@ -118,85 +112,83 @@ export const Visualization2D: React.FC< const pxScaleFactor = calcPxScaleFactor(snapshotNode.bounds, width); return ( - -
{ - e.stopPropagation(); - //the context menu triggers this callback but we dont want to remove hover effect - if (!instance.uiState.isContextMenuOpen.get()) { - instance.uiActions.onHoverNode(); - } +
{ + e.stopPropagation(); + //the context menu triggers this callback but we dont want to remove hover effect + if (!instance.uiState.isContextMenuOpen.get()) { + instance.uiActions.onHoverNode(); + } - visualizerActive.current = false; - }} - onMouseEnter={() => { - visualizerActive.current = true; - }} - //this div is to ensure that the size of the visualiser doesnt change when focusings on a subtree - style={ - { - backgroundColor: theme.backgroundWash, - borderRadius: theme.borderRadius, - overflowY: 'auto', - overflowX: 'hidden', - position: 'relative', //this is for the absolutely positioned overlays - [pxScaleFactorCssVar]: pxScaleFactor, - width: toPx(focusState.actualRoot.bounds.width), - height: toPx(focusState.actualRoot.bounds.height), - } as React.CSSProperties - }> - {hoveredNodeId && ( - { + visualizerActive.current = true; + }} + //this div is to ensure that the size of the visualiser doesnt change when focusings on a subtree + style={ + { + backgroundColor: theme.backgroundWash, + borderRadius: theme.borderRadius, + overflowY: 'auto', + overflowX: 'hidden', + position: 'relative', //this is for the absolutely positioned overlays + [pxScaleFactorCssVar]: pxScaleFactor, + width: toPx(focusState.actualRoot.bounds.width), + height: toPx(focusState.actualRoot.bounds.height), + } as React.CSSProperties + }> + {hoveredNodeId && ( + + )} + {selectedNodeId && ( + + )} +
+ {snapshotNode && ( + )} - {selectedNodeId && ( - - )} -
- {snapshotNode && ( - - )} - -
+
- +
); }; @@ -346,109 +338,6 @@ function getTotalOffset(id: Id, nodes: Map): Coordinate { return offset; } -function notEmpty(value: TValue | null | undefined): value is TValue { - return value != null; -} - -const iconStyle = {fontSize: 14}; -const ContextMenu: React.FC<{nodes: Map}> = ({children}) => { - const instance = usePlugin(plugin); - const focusedNodeId = useValue(instance.uiState.focusedNode); - const hoveredNodeIds = useValue(instance.uiState.hoveredNodes); - - const nodes = useValue(instance.nodes); - - const hoveredNodes = hoveredNodeIds - .map((id) => nodes.get(id)) - .filter(notEmpty) - .reverse(); - - const focusItems = hoveredNodes.map((node: ClientNode) => ( - { - instance.uiActions.onHoverNode(node.id); - }} - text={node.name} - onClick={() => { - instance.uiActions.onFocusNode(node.id); - }} - /> - )); - - const selectItems = hoveredNodes.map((node: ClientNode) => ( - { - instance.uiActions.onHoverNode(node.id); - }} - onClick={() => { - instance.uiActions.onSelectNode(node.id, 'visualiser'); - }} - /> - )); - - //since the context menu changes the hover state to indicate where you are this - //causes a rerender and therefore changes the context menu items. to work around - //we grab the hovered items at the time the context menu opens and this is unaffected - //by any further changes to hover state - const [staticItems, setStaticItems] = useState<{ - focusItems: ReactNode[]; - selectItems: ReactNode[]; - }>({ - selectItems: [], - focusItems: [], - }); - - return ( - { - instance.uiActions.onContextMenuOpen(open); - if (open) { - setStaticItems({focusItems: focusItems, selectItems: selectItems}); - } - }} - trigger={['contextMenu']} - overlay={() => { - return ( - - {staticItems.focusItems.length > 0 && ( - }> - {staticItems.focusItems} - - )} - - {focusedNodeId != null && ( - } - key="remove-focus" - text="Remove focus" - onClick={() => { - instance.uiActions.onFocusNode(undefined); - }} - /> - )} - - {focusedNodeId != null && } - - {staticItems.selectItems.length > 0 && ( - }> - {staticItems.selectItems} - - )} - - ); - }}> - {children} - - ); -}; - /** * this is the border that shows the green or blue line, it is implemented as a sibling to the * node itself so that it has the same size but the border doesnt affect the sizing of its children