Skip to content

Commit 1e187c8

Browse files
committed
added function to only show tool tip display when there there are properties to display
1 parent deb1d8a commit 1e187c8

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ export default function ComponentMap({
160160
}
161161
};
162162

163+
const hasDisplayableData = (nodeData) => {
164+
// Check if the node has props
165+
const hasProps =
166+
nodeData.componentData?.props && Object.keys(nodeData.componentData.props).length > 0;
167+
168+
// Check if the node has state
169+
const hasState =
170+
(nodeData.componentData?.state && Object.keys(nodeData.componentData.state).length > 0) ||
171+
(nodeData.componentData?.hooksState &&
172+
Object.keys(nodeData.componentData.hooksState).length > 0);
173+
174+
// Check if the node has reducer states
175+
const hasReducers =
176+
nodeData.componentData?.reducerStates && nodeData.componentData.reducerStates.length > 0;
177+
178+
return hasProps || hasState || hasReducers;
179+
};
180+
163181
const shouldIncludeNode = (node) => {
164182
// Return false if node has any context properties
165183
if (node?.componentData?.context && Object.keys(node.componentData.context).length > 0) {
@@ -400,17 +418,18 @@ export default function ComponentMap({
400418
}
401419

402420
// mousing controls & Tooltip display logic
403-
const handleMouseAndClickOver: void = (event) => {
404-
const coords = localPoint(event.target.ownerSVGElement, event);
405-
const tooltipObj = { ...node.data };
406-
407-
showTooltip({
408-
tooltipLeft: coords.x,
409-
tooltipTop: coords.y,
410-
tooltipData: tooltipObj,
411-
// this is where the data for state and render time is displayed
412-
// but does not show props functions and etc
413-
});
421+
const handleMouseAndClickOver = (event, nodeData) => {
422+
// Only show tooltip if the node has data to display
423+
if (hasDisplayableData(nodeData)) {
424+
const coords = localPoint(event.target.ownerSVGElement, event);
425+
const tooltipObj = { ...nodeData };
426+
427+
showTooltip({
428+
tooltipLeft: coords.x,
429+
tooltipTop: coords.y,
430+
tooltipData: tooltipObj,
431+
});
432+
}
414433
};
415434

416435
return (
@@ -440,38 +459,23 @@ export default function ComponentMap({
440459
dispatch(toggleExpanded(node.data));
441460
hideTooltip();
442461
}}
443-
// Mouse Enter Rect (Component Node) -----------------------------------------------------------------------
444-
/** This onMouseEnter event fires when the mouse first moves/hovers over a component node.
445-
* The supplied event listener callback produces a Tooltip element for the current node. */
446-
447462
onMouseEnter={(event) => {
448-
/** This 'if' statement block checks to see if you've just left another component node
449-
* by seeing if there's a current setTimeout waiting to close that component node's
450-
* tooltip (see onMouseLeave immediately below). If so it clears the tooltip generated
451-
* from that component node so a new tooltip for the node you've just entered can render. */
452-
if (toolTipTimeoutID.current !== null) {
453-
clearTimeout(toolTipTimeoutID.current);
454-
hideTooltip();
463+
if (hasDisplayableData(node.data)) {
464+
if (toolTipTimeoutID.current !== null) {
465+
clearTimeout(toolTipTimeoutID.current);
466+
hideTooltip();
467+
}
468+
toolTipTimeoutID.current = null;
469+
handleMouseAndClickOver(event, node.data);
455470
}
456-
// Removes the previous timeoutID to avoid errors
457-
toolTipTimeoutID.current = null;
458-
//This generates a tooltip for the component node the mouse has entered.
459-
handleMouseAndClickOver(event);
460471
}}
461-
// Mouse Leave Rect (Component Node) --------------------------------------------------------------------------
462-
/** This onMouseLeave event fires when the mouse leaves a component node.
463-
* The supplied event listener callback generates a setTimeout call which gives the
464-
* mouse a certain amount of time between leaving the current component node and
465-
* closing the tooltip for that node.
466-
* If the mouse enters the tooltip before the timeout delay has passed, the
467-
* setTimeout event will be canceled. */
468472
onMouseLeave={() => {
469-
// Store setTimeout ID so timeout can be cleared if necessary
470-
toolTipTimeoutID.current = setTimeout(() => {
471-
// hideTooltip unmounts the tooltip
472-
hideTooltip();
473-
toolTipTimeoutID.current = null;
474-
}, 300);
473+
if (hasDisplayableData(node.data)) {
474+
toolTipTimeoutID.current = setTimeout(() => {
475+
hideTooltip();
476+
toolTipTimeoutID.current = null;
477+
}, 300);
478+
}
475479
}}
476480
/>
477481
)}

src/app/styles/layout/_stateContainer.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@
116116
width: 300px;
117117
background-color: #111827;
118118
border-radius: 8px;
119-
box-shadow:
120-
0 4px 6px -1px rgba(0, 0, 0, 0.1),
121-
0 2px 4px -1px rgba(0, 0, 0, 0.06);
122119
font-family: 'Outfit', sans-serif;
123120
color: #f9fafb;
124121
overflow: hidden;

0 commit comments

Comments
 (0)