Skip to content

Commit

Permalink
Selection interaction from overlay
Browse files Browse the repository at this point in the history
Summary:
Previously we were registering a click handler with every single div in the visualiser. This is somewhat wasteful as well as was causing issues since i needed to call stop propagation to prevent the click bubbling and selecting all the parents too.

as a result of stop propagation the context menu behaviour was weird, when left clicking elsewhere to close the context menu it wouldnt work as the click was swallowed by the click handlers for the nodes.

Now we have a much simpler system. The hovered overlay is the click handler. Thats it.

Another benefit of this is the visualisation nodes under the overlays are all interaction less so they can be moved to canvas one day if need be

Reviewed By: lblasa

Differential Revision: D47550673

fbshipit-source-id: 1a607059c68f0b936f0184bd98a6a1492703d41b
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Jul 21, 2023
1 parent 6faccc4 commit f6dcaa2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions desktop/plugins/public/ui-debugger/components/Visualization2D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const Visualization2D: React.FC<
}>
{hoveredNodeId && (
<HoveredOverlay
onSelectNode={instance.uiActions.onSelectNode}
key={hoveredNodeId}
nodeId={hoveredNodeId}
nodes={nodes}
Expand Down Expand Up @@ -241,13 +242,6 @@ function Visualization2DNode({
height: toPx(node.bounds.height),
opacity: isHighlighted ? 0.3 : 1,
backgroundColor: isHighlighted ? 'red' : 'transparent',
}}
onClick={(e) => {
e.stopPropagation();

const hoveredNodes = instance.uiState.hoveredNodes.get();

onSelectNode(hoveredNodes[0], 'visualiser');
}}>
<NodeBorder />

Expand All @@ -259,9 +253,11 @@ function Visualization2DNode({
function HoveredOverlay({
nodeId,
nodes,
onSelectNode,
}: {
nodeId: Id;
nodes: Map<Id, ClientNode>;
onSelectNode: OnSelectNode;
}) {
const node = nodes.get(nodeId);

Expand All @@ -278,7 +274,14 @@ function HoveredOverlay({
align={{
offset: [0, 7],
}}>
<OverlayBorder nodeId={nodeId} nodes={nodes} type="hovered" />
<OverlayBorder
onClick={() => {
onSelectNode(nodeId, 'visualiser');
}}
nodeId={nodeId}
nodes={nodes}
type="hovered"
/>
</Tooltip>
);
}
Expand All @@ -292,7 +295,7 @@ const OverlayBorder = styled.div<{
const node = nodes.get(nodeId);
return {
zIndex: 100,
pointerEvents: 'none',
pointerEvents: type === 'selected' ? 'none' : 'auto',
cursor: 'pointer',
position: 'absolute',
top: toPx(offset.y),
Expand Down

0 comments on commit f6dcaa2

Please sign in to comment.