Fixed bug where visualizer not working after using focus more in visualiser context menu

Summary:
I introduced this to stop the visualiser going off while the framework events modal was open. However on mouse leave fires when the context menu is open. and if you click to focus then it never refires.

Also renamed the ref to make it clearer

Reviewed By: lblasa

Differential Revision: D47550672

fbshipit-source-id: 62e108e55e5c42a37d3aebded6467ececdc458df
This commit is contained in:
Luke De Feo
2023-07-21 07:17:31 -07:00
committed by Facebook GitHub Bot
parent f6dcaa2143
commit 8f857dc1c5

View File

@@ -42,7 +42,7 @@ export const Visualization2D: React.FC<
//this ref is to ensure the mouse has entered the visualiser, otherwise when you have overlapping modals //this ref is to ensure the mouse has entered the visualiser, otherwise when you have overlapping modals
//the hover state / tooltips all fire //the hover state / tooltips all fire
const mouseInVisualiserRef = useRef(false); const visualizerActive = useRef(false);
useEffect(() => { useEffect(() => {
const mouseListener = throttle((ev: MouseEvent) => { const mouseListener = throttle((ev: MouseEvent) => {
const domRect = rootNodeRef.current?.getBoundingClientRect(); const domRect = rootNodeRef.current?.getBoundingClientRect();
@@ -52,7 +52,7 @@ export const Visualization2D: React.FC<
!domRect || !domRect ||
instance.uiState.isContextMenuOpen.get() || instance.uiState.isContextMenuOpen.get() ||
!snapshotNode || !snapshotNode ||
!mouseInVisualiserRef.current !visualizerActive.current
) { ) {
return; return;
} }
@@ -98,6 +98,14 @@ export const Visualization2D: React.FC<
instance.uiActions, instance.uiActions,
]); ]);
useEffect(() => {
return instance.uiState.isContextMenuOpen.subscribe((value) => {
if (value === false) {
visualizerActive.current = true;
}
});
}, [instance.uiState.isContextMenuOpen]);
if (!focusState || !snapshotNode) { if (!focusState || !snapshotNode) {
return null; return null;
} }
@@ -114,10 +122,10 @@ export const Visualization2D: React.FC<
instance.uiActions.onHoverNode(); instance.uiActions.onHoverNode();
} }
mouseInVisualiserRef.current = false; visualizerActive.current = false;
}} }}
onMouseEnter={() => { onMouseEnter={() => {
mouseInVisualiserRef.current = true; visualizerActive.current = true;
}} }}
//this div is to ensure that the size of the visualiser doesnt change when focusings on a subtree //this div is to ensure that the size of the visualiser doesnt change when focusings on a subtree
style={ style={