Skip to content
Snippets Groups Projects
Commit 88e6f2b9 authored by Dennis Collaris's avatar Dennis Collaris Committed by Marcos Pieras
Browse files

refactor: simplify closing tooltips clicking outside pills

Reactflow already separates click and move events, mouseClickThreshold not needed
parent 5dd854e8
No related branches found
No related tags found
1 merge request!204feat: schema panel tooltips, redesigned tooltip, minimap configuration option
...@@ -54,8 +54,6 @@ export const Schema = (props: Props) => { ...@@ -54,8 +54,6 @@ export const Schema = (props: Props) => {
const [hasLayoutBeenRun, setHasLayoutBeenRun] = useState(false); const [hasLayoutBeenRun, setHasLayoutBeenRun] = useState(false);
// Time threshold for distinguishing between a click and a drag // Time threshold for distinguishing between a click and a drag
const mouseClickThreshold = 200;
const mouseDownTimestampRef = useRef<number | null>(null);
const isPillClicked = useRef<boolean>(false); const isPillClicked = useRef<boolean>(false);
const reactFlowInstanceRef = useRef<ReactFlowInstance | null>(null); const reactFlowInstanceRef = useRef<ReactFlowInstance | null>(null);
...@@ -204,52 +202,28 @@ export const Schema = (props: Props) => { ...@@ -204,52 +202,28 @@ export const Schema = (props: Props) => {
}, [graphStats]); }, [graphStats]);
const handleOnClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => { const handleOnClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
const holdDownTime = event.timeStamp - (mouseDownTimestampRef.current || 0); const target = event.target as HTMLElement;
if (holdDownTime < mouseClickThreshold && isPillClicked.current === false) { const clickedOutsideNode = target.classList.contains('react-flow__pane');
// Handle click on stage
setNodes((nds) => setNodes((nds) =>
nds.map((node) => ({ nds.map((node) => ({
...node, ...node,
data: { data: {
...node.data, ...node.data,
tooltipClose: true, tooltipClose: clickedOutsideNode,
}, },
})), })),
); );
setEdges((edg) =>
edg.map((edge) => ({
...edge,
data: {
...edge.data,
tooltipClose: true,
},
})),
);
isPillClicked.current = false;
} else {
setNodes((nds) =>
nds.map((node) => ({
...node,
data: {
...node.data,
tooltipClose: false,
},
})),
);
setEdges((edg) => setEdges((edg) =>
edg.map((edge) => ({ edg.map((edge) => ({
...edge, ...edge,
data: { data: {
...edge.data, ...edge.data,
tooltipClose: false, tooltipClose: clickedOutsideNode,
}, },
})), })),
); );
}
}; };
return ( return (
...@@ -333,10 +307,6 @@ export const Schema = (props: Props) => { ...@@ -333,10 +307,6 @@ export const Schema = (props: Props) => {
<div <div
className="schema-panel w-full h-full flex flex-col justify-between" className="schema-panel w-full h-full flex flex-col justify-between"
ref={reactFlowRef} ref={reactFlowRef}
onMouseUpCapture={(event) => {
// this only fires when a pill is cliced, not in background
isPillClicked.current = true;
}}
> >
{nodes.length === 0 ? ( {nodes.length === 0 ? (
<p className="m-3 text-xl font-bold">No Elements</p> <p className="m-3 text-xl font-bold">No Elements</p>
...@@ -352,11 +322,7 @@ export const Schema = (props: Props) => { ...@@ -352,11 +322,7 @@ export const Schema = (props: Props) => {
connectionLineComponent={ConnectionDragLine} connectionLineComponent={ConnectionDragLine}
onNodesChange={onNodesChange} onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange} onEdgesChange={onEdgesChange}
onMouseDownCapture={(event) => { onMouseDownCapture={() => dispatch(resultSetFocus({ focusType: 'schema' }))}
mouseDownTimestampRef.current = event.timeStamp;
dispatch(resultSetFocus({ focusType: 'schema' }));
isPillClicked.current = false;
}}
nodes={nodes} nodes={nodes}
edges={edges} edges={edges}
onInit={(reactFlowInstance) => { onInit={(reactFlowInstance) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment