@@ -17,6 +17,7 @@ import { localPoint } from '@visx/event';
1717import { useTooltip , useTooltipInPortal , defaultStyles } from '@visx/tooltip' ;
1818import LinkControls from './LinkControls' ;
1919import getLinkComponent from './getLinkComponent' ;
20+ import ToolTipDataDisplay from './ToolTipDataDisplay' ;
2021import { toggleExpanded , setCurrentTabInApp } from '../../../actions/actions' ;
2122import { useStoreContext } from '../../../store' ;
2223
@@ -122,19 +123,6 @@ export default function ComponentMap({
122123 return `${ renderTime } ms ` ;
123124 } ;
124125
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-
138126 const formatState = ( state ) => {
139127 if ( state === 'stateless' ) return [ 'stateless' ] ;
140128 return [ 'stateful' ] ;
@@ -296,19 +284,13 @@ export default function ComponentMap({
296284 onMouseEnter = { ( event ) => {
297285 /** This 'if' statement block checks to see if you've just left another component node
298286 * 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. */
304289 if ( toolTipTimeoutID . current !== null ) {
305290 clearTimeout ( toolTipTimeoutID . current ) ;
306291 hideTooltip ( ) ;
307292 }
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
312294 toolTipTimeoutID . current = null ;
313295 //This generates a tooltip for the component node the mouse has entered.
314296 handleMouseAndClickOver ( event ) ;
@@ -322,13 +304,11 @@ export default function ComponentMap({
322304 * If the mouse enters the tooltip before the timeout delay has passed, the
323305 * setTimeout event will be canceled. */
324306 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
326308 toolTipTimeoutID . current = setTimeout ( ( ) => {
327309 // hideTooltip unmounts the tooltip
328310 hideTooltip ( ) ;
329- // As the timeout has been executed, the timeoutID can be reset to null
330311 toolTipTimeoutID . current = null ;
331- //There is a delay of 300 ms
332312 } , 300 ) ;
333313 } }
334314 />
@@ -361,23 +341,16 @@ export default function ComponentMap({
361341 style = { tooltipStyles }
362342
363343 //------------- 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 */
368346 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,
371347 clearTimeout ( toolTipTimeoutID . current ) ;
372- // This line resets the timeoutID to null
373348 toolTipTimeoutID . current = null ;
374349 } }
375350
376351 //------------- 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 */
379353 onMouseLeave = { ( ) => {
380- // hideTooltip unmounts the tooltip
381354 hideTooltip ( ) ;
382355 } }
383356 >
@@ -391,26 +364,18 @@ export default function ComponentMap({
391364 State: { formatState ( tooltipData . state ) }
392365 </ div >
393366 < div style = { React . scrollStyle } >
394- < div className = 'tooltipWrapper' >
395- < h2 > Props:</ h2 >
396- { formatData ( tooltipData . componentData . props , 'props' ) }
397- </ div >
398367
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+ />
404372
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+ />
414379 </ div >
415380 </ div >
416381 </ TooltipInPortal >
0 commit comments