From 01f7fa34e51e0468bbcf2f861ab5d6347e9e410d Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Thu, 24 Nov 2022 09:23:16 -0800 Subject: [PATCH] Remove per node snapshot in favour of single top level snapshot Summary: In order to support focus mode we need to have only 1 snapshot. In practice this is the case but we are making this more apparant in this diff. Reviewed By: lblasa Differential Revision: D41493003 fbshipit-source-id: 19ed7213d15adaea4732f4ec60309efa8dae6f94 --- .../components/Visualization2D.tsx | 44 ++++++------------- .../public/ui-debugger/components/main.tsx | 2 - desktop/plugins/public/ui-debugger/index.tsx | 13 +++--- 3 files changed, 22 insertions(+), 37 deletions(-) diff --git a/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx b/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx index e034a812f..4494ff28e 100644 --- a/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx +++ b/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx @@ -8,17 +8,9 @@ */ import React, {useEffect, useMemo, useRef, useState} from 'react'; -import { - Bounds, - Coordinate, - Id, - NestedNode, - Snapshot, - Tag, - UINode, -} from '../types'; +import {Bounds, Coordinate, Id, NestedNode, Tag, UINode} from '../types'; -import {styled, theme, usePlugin} from 'flipper-plugin'; +import {styled, theme, usePlugin, useValue} from 'flipper-plugin'; import {plugin} from '../index'; import {throttle, isEqual, head} from 'lodash'; @@ -26,23 +18,16 @@ export const Visualization2D: React.FC< { rootId: Id; nodes: Map; - snapshots: Map; selectedNode?: Id; onSelectNode: (id?: Id) => void; modifierPressed: boolean; } & React.HTMLAttributes -> = ({ - rootId, - nodes, - snapshots, - selectedNode, - onSelectNode, - modifierPressed, -}) => { +> = ({rootId, nodes, selectedNode, onSelectNode, modifierPressed}) => { const root = useMemo(() => toNestedNode(rootId, nodes), [rootId, nodes]); const rootNodeRef = useRef(); const instance = usePlugin(plugin); + const snapshot = useValue(instance.snapshot); useEffect(() => { const mouseListener = throttle((ev: MouseEvent) => { const domRect = rootNodeRef.current?.getBoundingClientRect(); @@ -80,6 +65,7 @@ export const Visualization2D: React.FC< return null; } + const snapshotNode = snapshot && nodes.get(snapshot.nodeId); return (
+ {snapshot && snapshotNode && ( + + )} ; modifierPressed: boolean; selectedNode?: Id; onSelectNode: (id?: Id) => void; }) { - const snapshot = snapshots.get(node.id); const instance = usePlugin(plugin); const [isHovered, setIsHovered] = useState(false); @@ -174,7 +165,6 @@ function Visualization2DNode({ - {snapshot && ( - - )} {isHovered &&

{node.name}

} {children}
diff --git a/desktop/plugins/public/ui-debugger/components/main.tsx b/desktop/plugins/public/ui-debugger/components/main.tsx index f2fb33d3e..80847c52f 100644 --- a/desktop/plugins/public/ui-debugger/components/main.tsx +++ b/desktop/plugins/public/ui-debugger/components/main.tsx @@ -24,7 +24,6 @@ export function Component() { const rootId = useValue(instance.rootId); const nodes: Map = useValue(instance.nodes); const metadata: Map = useValue(instance.metadata); - const snapshots: Map = useValue(instance.snapshots); const [showPerfStats, setShowPerfStats] = useState(false); const [selectedNode, setSelectedNode] = useState(undefined); @@ -70,7 +69,6 @@ export function Component() { ) { }); const nodes = createState>(new Map()); - const snapshots = createState>(new Map()); + const snapshot = createState<{nodeId: Id; base64Image: Snapshot} | null>( + null, + ); const treeState = createState({expandedNodes: []}); @@ -71,9 +73,10 @@ export function plugin(client: PluginClient) { const seenNodes = new Set(); client.onMessage('subtreeUpdate', (event) => { - snapshots.update((draft) => { - draft.set(event.rootId, event.snapshot); - }); + if (event.snapshot) { + snapshot.set({nodeId: event.rootId, base64Image: event.snapshot}); + } + nodes.update((draft) => { event.nodes.forEach((node) => { draft.set(node.id, node); @@ -105,7 +108,7 @@ export function plugin(client: PluginClient) { rootId, nodes, metadata, - snapshots, + snapshot, hoveredNodes, perfEvents, treeState,