@@ -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
import { LinkTypesProps , DefaultMargin , ToolTipStyles } from '../../../components/FrontendTypes'
@@ -93,7 +94,7 @@ export default function ComponentMap({
93
94
...defaultStyles ,
94
95
minWidth : 60 ,
95
96
maxWidth : 300 ,
96
- backgroundColor : 'rgba(0,0,0,0.9 )' ,
97
+ backgroundColor : 'rgb(15,15,15 )' ,
97
98
color : 'white' ,
98
99
fontSize : '14px' ,
99
100
lineHeight : '18px' ,
@@ -116,24 +117,6 @@ export default function ComponentMap({
116
117
return `${ renderTime } ms ` ;
117
118
} ;
118
119
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
-
137
120
// places all nodes into a flat array
138
121
const nodeList : [ ] = [ ] ;
139
122
@@ -290,19 +273,13 @@ export default function ComponentMap({
290
273
onMouseEnter = { ( event ) => {
291
274
/** This 'if' statement block checks to see if you've just left another component node
292
275
* 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. */
298
278
if ( toolTipTimeoutID . current !== null ) {
299
279
clearTimeout ( toolTipTimeoutID . current ) ;
300
280
hideTooltip ( ) ;
301
281
}
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
306
283
toolTipTimeoutID . current = null ;
307
284
//This generates a tooltip for the component node the mouse has entered.
308
285
handleMouseAndClickOver ( event ) ;
@@ -316,13 +293,11 @@ export default function ComponentMap({
316
293
* If the mouse enters the tooltip before the timeout delay has passed, the
317
294
* setTimeout event will be canceled. */
318
295
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
320
297
toolTipTimeoutID . current = setTimeout ( ( ) => {
321
298
// hideTooltip unmounts the tooltip
322
299
hideTooltip ( ) ;
323
- // As the timeout has been executed, the timeoutID can be reset to null
324
300
toolTipTimeoutID . current = null ;
325
- //There is a delay of 300 ms
326
301
} , 300 ) ;
327
302
} }
328
303
/>
@@ -355,56 +330,39 @@ export default function ComponentMap({
355
330
style = { tooltipStyles }
356
331
357
332
//------------- 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 */
362
335
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,
365
336
clearTimeout ( toolTipTimeoutID . current ) ;
366
- // This line resets the timeoutID to null
367
337
toolTipTimeoutID . current = null ;
368
338
} }
369
339
370
340
//------------- 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 */
373
342
onMouseLeave = { ( ) => {
374
- // hideTooltip unmounts the tooltip
375
343
hideTooltip ( ) ;
376
344
} }
377
345
>
378
346
< div >
379
- < div style = { { } } >
380
- { ' ' }
381
- < strong > { tooltipData . name } </ strong > { ' ' }
347
+ < div >
348
+ < strong > { tooltipData . name } </ strong >
382
349
</ 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' }
386
352
</ 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
+ />
408
366
</ div >
409
367
</ div >
410
368
</ TooltipInPortal >
0 commit comments