@@ -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' ;
2223import { LinkTypesProps , DefaultMargin , ToolTipStyles } from '../../../components/FrontendTypes'
@@ -93,7 +94,7 @@ export default function ComponentMap({
9394 ...defaultStyles ,
9495 minWidth : 60 ,
9596 maxWidth : 300 ,
96- backgroundColor : 'rgba(0,0,0,0.9 )' ,
97+ backgroundColor : 'rgb(15,15,15 )' ,
9798 color : 'white' ,
9899 fontSize : '14px' ,
99100 lineHeight : '18px' ,
@@ -116,24 +117,6 @@ export default function ComponentMap({
116117 return `${ renderTime } ms ` ;
117118 } ;
118119
119- const formatData : [ ] = ( data , type ) => {
120- const contextFormat : string [ ] = [ ] ;
121- for ( const key in data ) {
122- // Suggestion: update the front end to display as a list if we have object
123- let inputData = data [ key ] ;
124- if ( inputData !== null && typeof inputData === 'object' ) {
125- inputData = JSON . stringify ( inputData ) ;
126- }
127- contextFormat . push ( < p className = { `${ type } -item` } > { `${ key } : ${ inputData } ` } </ p > ) ;
128- }
129- return contextFormat ;
130- } ;
131-
132- const formatState : string [ ] = ( state ) => {
133- if ( state === 'stateless' ) return [ 'stateless' ] ;
134- return [ 'stateful' ] ;
135- } ;
136-
137120 // places all nodes into a flat array
138121 const nodeList : [ ] = [ ] ;
139122
@@ -290,19 +273,13 @@ export default function ComponentMap({
290273 onMouseEnter = { ( event ) => {
291274 /** This 'if' statement block checks to see if you've just left another component node
292275 * by seeing if there's a current setTimeout waiting to close that component node's
293- * tooltip (see onMouseLeave immediately below).
294- * This setTimeout gives the mouse time to enter the tooltip element so the tooltip
295- * can persist. If instead of entering said tooltip element you've left the previous
296- * component node to enter this component node, this logic will clear the timeout event,
297- * and close the tooltip. */
276+ * tooltip (see onMouseLeave immediately below). If so it clears the tooltip generated
277+ * from that component node so a new tooltip for the node you've just entered can render. */
298278 if ( toolTipTimeoutID . current !== null ) {
299279 clearTimeout ( toolTipTimeoutID . current ) ;
300280 hideTooltip ( ) ;
301281 }
302- /** The following line resets the toolTipTimeoutID.current to null, showing that there
303- * are no current setTimeouts running. I placed this outside of the above if statement
304- * to make sure there are no edge cases that would allow for the toolTipTimeoutID.current
305- * to hold onto an old reference. */
282+ // Removes the previous timeoutID to avoid errors
306283 toolTipTimeoutID . current = null ;
307284 //This generates a tooltip for the component node the mouse has entered.
308285 handleMouseAndClickOver ( event ) ;
@@ -316,13 +293,11 @@ export default function ComponentMap({
316293 * If the mouse enters the tooltip before the timeout delay has passed, the
317294 * setTimeout event will be canceled. */
318295 onMouseLeave = { ( ) => {
319- // This line invokes setTimeout and saves its ID to the useRef var toolTipTimeoutID
296+ // Store setTimeout ID so timeout can be cleared if necessary
320297 toolTipTimeoutID . current = setTimeout ( ( ) => {
321298 // hideTooltip unmounts the tooltip
322299 hideTooltip ( ) ;
323- // As the timeout has been executed, the timeoutID can be reset to null
324300 toolTipTimeoutID . current = null ;
325- //There is a delay of 300 ms
326301 } , 300 ) ;
327302 } }
328303 />
@@ -355,56 +330,39 @@ export default function ComponentMap({
355330 style = { tooltipStyles }
356331
357332 //------------- Mouse Over TooltipInPortal--------------------------------------------------------------------
358- /** This onMouseEnter fires when the mouse first moves/hovers over the tooltip
359- * The supplied event listener callback stops the setTimeout that was going to
360- * close the tooltip from firing */
361-
333+ /** After the mouse enters the tooltip, it's able to persist by clearing the setTimeout
334+ * that would've unmounted it */
362335 onMouseEnter = { ( ) => {
363- // The setTimeoutID stored in toolTipTimeoutID.current is from the setTimeout initiated by leaving the
364- // component node that generated the tooltip. If you've triggered an onMouseEnter event in that tooltip,
365336 clearTimeout ( toolTipTimeoutID . current ) ;
366- // This line resets the timeoutID to null
367337 toolTipTimeoutID . current = null ;
368338 } }
369339
370340 //------------- Mouse Leave TooltipInPortal -----------------------------------------------------------------
371- /** This onMouseLeave event fires when the mouse leaves the tooltip
372- * The supplied event listener callback unmounts the tooltip */
341+ /** When the mouse leaves the tooltip, the tooltip unmounts */
373342 onMouseLeave = { ( ) => {
374- // hideTooltip unmounts the tooltip
375343 hideTooltip ( ) ;
376344 } }
377345 >
378346 < div >
379- < div style = { { } } >
380- { ' ' }
381- < strong > { tooltipData . name } </ strong > { ' ' }
347+ < div >
348+ < strong > { tooltipData . name } </ strong >
382349 </ div >
383- < div > Render time: { formatRenderTime ( tooltipData . componentData . actualDuration ) } </ div >
384- < div className = 'stateTip' >
385- State: { formatState ( tooltipData . state ) }
350+ < div className = 'tooltipKey' >
351+ key: { tooltipData . componentData . key !== null ? tooltipData . componentData . key : 'null' }
386352 </ div >
387- < div style = { React . scrollStyle } >
388- < div className = 'tooltipWrapper' >
389- < h2 > Props:</ h2 >
390- { formatData ( tooltipData . componentData . props , 'props' ) }
391- </ div >
392-
393- { /* Currently no use for this field
394- <div className='tooltipWrapper'>
395- <h2>Initial Context:</h2>
396- {formatData(tooltipData.componentData.context, 'context')}
397- </div> */ }
398-
399- < div className = 'tooltipWrapper' >
400- < h2 > State:</ h2 >
401- { formatData (
402- tooltipData . componentData . hooksIndex
403- ? tooltipData . componentData . hooksState
404- : tooltipData . componentData . state ,
405- 'state' ,
406- ) }
407- </ div >
353+ < div > Render time: { formatRenderTime ( tooltipData . componentData . actualDuration ) } </ div >
354+
355+ < div >
356+ < ToolTipDataDisplay
357+ containerName = 'Props'
358+ dataObj = { tooltipData . componentData . props }
359+ />
360+ < ToolTipDataDisplay
361+ containerName = 'State'
362+ dataObj = { tooltipData . componentData . hooksIndex
363+ ? tooltipData . componentData . hooksState
364+ : tooltipData . componentData . state }
365+ />
408366 </ div >
409367 </ div >
410368 </ TooltipInPortal >
0 commit comments