@@ -160,6 +160,24 @@ export default function ComponentMap({
160
160
}
161
161
} ;
162
162
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
+
163
181
const shouldIncludeNode = ( node ) => {
164
182
// Return false if node has any context properties
165
183
if ( node ?. componentData ?. context && Object . keys ( node . componentData . context ) . length > 0 ) {
@@ -400,17 +418,18 @@ export default function ComponentMap({
400
418
}
401
419
402
420
// 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
+ }
414
433
} ;
415
434
416
435
return (
@@ -440,38 +459,23 @@ export default function ComponentMap({
440
459
dispatch ( toggleExpanded ( node . data ) ) ;
441
460
hideTooltip ( ) ;
442
461
} }
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
-
447
462
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 ) ;
455
470
}
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 ) ;
460
471
} }
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. */
468
472
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
+ }
475
479
} }
476
480
/>
477
481
) }
0 commit comments