@@ -17,6 +17,7 @@ import { localPoint } from '@visx/event';
17
17
import { useTooltip , useTooltipInPortal , defaultStyles } from '@visx/tooltip' ;
18
18
import LinkControls from './LinkControls' ;
19
19
import getLinkComponent from './getLinkComponent' ;
20
+ import ToolTipDataDisplay from './ToolTipDataDisplay' ;
20
21
import { toggleExpanded , setCurrentTabInApp } from '../../../actions/actions' ;
21
22
import { useStoreContext } from '../../../store' ;
22
23
@@ -122,19 +123,6 @@ export default function ComponentMap({
122
123
return `${ renderTime } ms ` ;
123
124
} ;
124
125
125
- const formatData = ( data , type ) => {
126
- const contextFormat = [ ] ;
127
- for ( const key in data ) {
128
- // Suggestion: update the front end to display as a list if we have object
129
- let inputData = data [ key ] ;
130
- if ( inputData !== null && typeof inputData === 'object' ) {
131
- inputData = JSON . stringify ( inputData ) ;
132
- }
133
- contextFormat . push ( < p className = { `${ type } -item` } > { `${ key } : ${ inputData } ` } </ p > ) ;
134
- }
135
- return contextFormat ;
136
- } ;
137
-
138
126
const formatState = ( state ) => {
139
127
if ( state === 'stateless' ) return [ 'stateless' ] ;
140
128
return [ 'stateful' ] ;
@@ -296,19 +284,13 @@ export default function ComponentMap({
296
284
onMouseEnter = { ( event ) => {
297
285
/** This 'if' statement block checks to see if you've just left another component node
298
286
* by seeing if there's a current setTimeout waiting to close that component node's
299
- * tooltip (see onMouseLeave immediately below).
300
- * This setTimeout gives the mouse time to enter the tooltip element so the tooltip
301
- * can persist. If instead of entering said tooltip element you've left the previous
302
- * component node to enter this component node, this logic will clear the timeout event,
303
- * and close the tooltip. */
287
+ * tooltip (see onMouseLeave immediately below). If so it clears the tooltip generated
288
+ * from that component node so a new tooltip for the node you've just entered can render. */
304
289
if ( toolTipTimeoutID . current !== null ) {
305
290
clearTimeout ( toolTipTimeoutID . current ) ;
306
291
hideTooltip ( ) ;
307
292
}
308
- /** The following line resets the toolTipTimeoutID.current to null, showing that there
309
- * are no current setTimeouts running. I placed this outside of the above if statement
310
- * to make sure there are no edge cases that would allow for the toolTipTimeoutID.current
311
- * to hold onto an old reference. */
293
+ // Removes the previous timeoutID to avoid errors
312
294
toolTipTimeoutID . current = null ;
313
295
//This generates a tooltip for the component node the mouse has entered.
314
296
handleMouseAndClickOver ( event ) ;
@@ -322,13 +304,11 @@ export default function ComponentMap({
322
304
* If the mouse enters the tooltip before the timeout delay has passed, the
323
305
* setTimeout event will be canceled. */
324
306
onMouseLeave = { ( ) => {
325
- // This line invokes setTimeout and saves its ID to the useRef var toolTipTimeoutID
307
+ // Store setTimeout ID so timeout can be cleared if necessary
326
308
toolTipTimeoutID . current = setTimeout ( ( ) => {
327
309
// hideTooltip unmounts the tooltip
328
310
hideTooltip ( ) ;
329
- // As the timeout has been executed, the timeoutID can be reset to null
330
311
toolTipTimeoutID . current = null ;
331
- //There is a delay of 300 ms
332
312
} , 300 ) ;
333
313
} }
334
314
/>
@@ -361,23 +341,16 @@ export default function ComponentMap({
361
341
style = { tooltipStyles }
362
342
363
343
//------------- Mouse Over TooltipInPortal--------------------------------------------------------------------
364
- /** This onMouseEnter fires when the mouse first moves/hovers over the tooltip
365
- * The supplied event listener callback stops the setTimeout that was going to
366
- * close the tooltip from firing */
367
-
344
+ /** After the mouse enters the tooltip, it's able to persist by clearing the setTimeout
345
+ * that would've unmounted it */
368
346
onMouseEnter = { ( ) => {
369
- // The setTimeoutID stored in toolTipTimeoutID.current is from the setTimeout initiated by leaving the
370
- // component node that generated the tooltip. If you've triggered an onMouseEnter event in that tooltip,
371
347
clearTimeout ( toolTipTimeoutID . current ) ;
372
- // This line resets the timeoutID to null
373
348
toolTipTimeoutID . current = null ;
374
349
} }
375
350
376
351
//------------- Mouse Leave TooltipInPortal -----------------------------------------------------------------
377
- /** This onMouseLeave event fires when the mouse leaves the tooltip
378
- * The supplied event listener callback unmounts the tooltip */
352
+ /** When the mouse leaves the tooltip, the tooltip unmounts */
379
353
onMouseLeave = { ( ) => {
380
- // hideTooltip unmounts the tooltip
381
354
hideTooltip ( ) ;
382
355
} }
383
356
>
@@ -391,26 +364,18 @@ export default function ComponentMap({
391
364
State: { formatState ( tooltipData . state ) }
392
365
</ div >
393
366
< div style = { React . scrollStyle } >
394
- < div className = 'tooltipWrapper' >
395
- < h2 > Props:</ h2 >
396
- { formatData ( tooltipData . componentData . props , 'props' ) }
397
- </ div >
398
367
399
- { /* Currently no use for this field
400
- <div className='tooltipWrapper'>
401
- <h2>Initial Context:</h2>
402
- {formatData(tooltipData.componentData.context, 'context')}
403
- </div> */ }
368
+ < ToolTipDataDisplay
369
+ containerName = 'Props'
370
+ dataObj = { tooltipData . componentData . props }
371
+ />
404
372
405
- < div className = 'tooltipWrapper' >
406
- < h2 > State:</ h2 >
407
- { formatData (
408
- tooltipData . componentData . hooksIndex
409
- ? tooltipData . componentData . hooksState
410
- : tooltipData . componentData . state ,
411
- 'state' ,
412
- ) }
413
- </ div >
373
+ < ToolTipDataDisplay
374
+ containerName = 'State'
375
+ dataObj = { tooltipData . componentData . hooksIndex
376
+ ? tooltipData . componentData . hooksState
377
+ : tooltipData . componentData . state }
378
+ />
414
379
</ div >
415
380
</ div >
416
381
</ TooltipInPortal >
0 commit comments