1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable no-restricted-syntax */
3
+ /* eslint-disable guard-for-in */
1
4
// @ts -nocheck
2
- import React , { useState } from 'react' ;
5
+ import React , { useState , useEffect } from 'react' ;
3
6
import { Group } from '@visx/group' ;
4
7
import { hierarchy , Tree } from '@visx/hierarchy' ;
5
8
import { LinearGradient } from '@visx/gradient' ;
@@ -11,12 +14,16 @@ import {
11
14
TooltipWithBounds ,
12
15
defaultStyles ,
13
16
} from '@visx/tooltip' ;
17
+ import { isAbsolute } from 'path' ;
18
+ import { nest } from 'jscharting' ;
14
19
import useForceUpdate from './useForceUpdate' ;
15
20
import LinkControls from './LinkControls' ;
16
21
import getLinkComponent from './getLinkComponent' ;
17
22
import { onHover , onHoverExit } from '../actions/actions' ;
18
23
import { useStoreContext } from '../store' ;
19
24
25
+ const exclude = [ 'childExpirationTime' , 'staticContext' , '_debugSource' , 'actualDuration' , 'actualStartTime' , 'treeBaseDuration' , '_debugID' , '_debugIsCurrentlyTiming' , 'selfBaseDuration' , 'expirationTime' , 'effectTag' , 'alternate' , '_owner' , '_store' , 'get key' , 'ref' , '_self' , '_source' , 'firstBaseUpdate' , 'updateQueue' , 'lastBaseUpdate' , 'shared' , 'responders' , 'pending' , 'lanes' , 'childLanes' , 'effects' , 'memoizedState' , 'pendingProps' , 'lastEffect' , 'firstEffect' , 'tag' , 'baseState' , 'baseQueue' , 'dependencies' , 'Consumer' , 'context' , '_currentRenderer' , '_currentRenderer2' , 'mode' , 'flags' , 'nextEffect' , 'sibling' , 'create' , 'deps' , 'next' , 'destroy' , 'parentSub' , 'child' , 'key' , 'return' , 'children' , '$$typeof' , '_threadCount' , '_calculateChangedBits' , '_currentValue' , '_currentValue2' , 'Provider' , '_context' , 'stateNode' , 'elementType' , 'type' ] ;
26
+
20
27
// const root = hierarchy({
21
28
// name: 'root',
22
29
// children: [
@@ -128,12 +135,13 @@ export default function ComponentMap({
128
135
lineHeight : '18px' ,
129
136
fontFamily : 'Roboto' ,
130
137
zIndex : 100 ,
138
+ 'pointer-events' : 'all !important' ,
131
139
} ;
132
140
133
141
const scrollStyle = {
134
142
minWidth : '60' ,
135
143
maxWidth : '300' ,
136
- maxHeight : '100px ' ,
144
+ maxHeight : '200px ' ,
137
145
overflowY : 'scroll' ,
138
146
overflowWrap : 'break-word' ,
139
147
} ;
@@ -143,53 +151,117 @@ export default function ComponentMap({
143
151
return `${ time } ms ` ;
144
152
} ;
145
153
146
- //places all nodes into a flat array
154
+ // places all nodes into a flat array
147
155
const nodeList = [ ] ;
148
156
157
+ // if (exclude.includes(key) === true) {
158
+ // nestedObj[key] = 'react related';
159
+ // }
160
+ // if (typeof data[key] === 'object' && exclude.includes(key) !== true) {
161
+ // nestedObj = makePropsPretty(data[key]);
162
+ // if (Array.isArray(nestedObj)) {
163
+ // try {
164
+ // if (nestedObj[0].$$typeof) {
165
+ // nestedObj = null;
166
+ // } else {
167
+ // nestedObj = nestedObj.forEach(e => makePropsPretty(e));
168
+ // }
169
+ // } catch (error) {
170
+ // console.log('not a react componenet');
171
+ // }
172
+ // }
173
+ // }
174
+ // const makePropsPretty = data => {
175
+ // const propsFormat = [];
176
+ // let nestedObj;
177
+ // for (const key in data) {
178
+ // if (data[key] !== 'reactFiber' && typeof data[key] !== 'object' && exclude.includes(key) !== true) {
179
+ // propsFormat.push(<p className="stateprops">
180
+ // {`${key}: ${nestedObj || data[key]}` }
181
+ // </p>);
182
+ // } else if (typeof data[key] === 'object' && exclude.includes(key) !== true) {
183
+ // nestedObj = makePropsPretty(data[key]);
184
+ // try {
185
+ // if (nestedObj[0].$$typeof) {
186
+ // // nestedObj = nestedObj.forEach(e => makePropsPretty(e.props.children));
187
+ // nestedObj = nestedObj.forEach(e => {
188
+ // console.log('this is e show the object', e);
189
+ // if (typeof e.props.children === 'object') {
190
+ // console.log('nested obj show me ', typeof e.props.children, e.props.children);
191
+ // return e.props.children;
192
+ // }
193
+ // console.log('not an object in nestedobj', typeof e.props.children, e.props.children);
194
+ // return e.props.children;
195
+ // });
196
+ // console.log('show me show show show show show show show', nestedObj);
197
+ // // console.log('show me the nestedobj after the react thing', nestedObj)
198
+ // } else {
199
+ // nestedObj = nestedObj.forEach(e =>{
200
+ // console.log('this is not a react thing so show me', e)
201
+ // makePropsPretty(e)
202
+ // });
203
+ // }
204
+ // } catch (error) {
205
+ // console.log(error);
206
+ // }
207
+ // }
208
+ // if (nestedObj) {
209
+ // propsFormat.push(nestedObj);
210
+ // }
211
+ // }
212
+ // return propsFormat;
213
+ // };
214
+
149
215
const makePropsPretty = data => {
150
216
const propsFormat = [ ] ;
217
+ const nestedObj = [ ] ;
218
+ // console.log('show me the data we are getting', data);
151
219
for ( const key in data ) {
152
- console . log ( 'this is the key' , key ) ;
153
- if ( typeof data [ key ] === 'object' ) {
154
- const nestedObj = makePropsPretty ( data [ key ] ) ;
220
+ if ( data [ key ] !== 'reactFiber' && typeof data [ key ] !== 'object' && exclude . includes ( key ) !== true ) {
221
+ propsFormat . push ( < p className = "stateprops" >
222
+ { `${ key } : ${ data [ key ] } ` }
223
+ </ p > ) ;
224
+ } else if ( data [ key ] !== 'reactFiber' && typeof data [ key ] === 'object' && exclude . includes ( key ) !== true ) {
225
+ const result = makePropsPretty ( data [ key ] ) ;
226
+ nestedObj . push ( result ) ;
155
227
}
156
- propsFormat . push ( < p >
157
- { `${ JSON . stringify ( key ) } : ${ JSON . stringify ( nestedObj || data [ key ] ) } ` }
158
- </ p > ) ;
159
228
}
160
- console . log ( 'this is propsFormat' , propsFormat ) ;
229
+ if ( nestedObj ) {
230
+ propsFormat . push ( nestedObj ) ;
231
+ }
232
+ // console.log('this is propsformat', propsFormat);
161
233
return propsFormat ;
162
234
} ;
163
235
164
- const collectNodes = ( node ) => {
236
+ const collectNodes = node => {
165
237
nodeList . splice ( 0 , nodeList . length ) ;
166
- console . log ( " Root node:" , node ) ;
238
+ // console.log(' Root node:' , node);
167
239
nodeList . push ( node ) ;
168
240
for ( let i = 0 ; i < nodeList . length ; i ++ ) {
169
241
const cur = nodeList [ i ] ;
170
242
if ( cur . children && cur . children . length > 0 ) {
171
- for ( let child of cur . children ) {
243
+ for ( const child of cur . children ) {
172
244
nodeList . push ( child ) ;
173
245
}
174
246
}
175
247
}
176
- console . log ( 'NODELIST in ComponentMap: ' , nodeList ) ;
177
- }
248
+ // console.log('NODELIST in ComponentMap: ', nodeList);
249
+ } ;
178
250
collectNodes ( snapshots [ lastNode ] ) ;
179
251
180
- //find the node that has been selected and use it as the root
252
+ // find the node that has been selected and use it as the root
181
253
const startNode = null ;
182
254
const findSelectedNode = ( ) => {
183
- console . log ( selectedNode ) ;
184
- for ( let node of nodeList ) {
255
+ // console.log(selectedNode);
256
+ for ( const node of nodeList ) {
185
257
if ( node . name === selectedNode ) {
186
258
startNode = node ;
187
259
}
188
260
}
189
- }
261
+ } ;
190
262
findSelectedNode ( ) ;
191
263
192
- // controls for the map
264
+ // controls for the map
193
265
const LinkComponent = getLinkComponent ( { layout, linkType, orientation } ) ;
194
266
return totalWidth < 10 ? null : (
195
267
< div >
@@ -255,7 +327,7 @@ export default function ComponentMap({
255
327
}
256
328
257
329
// mousing controls & Tooltip display logic
258
- const handleMouseOver = event => {
330
+ const handleMouseAndClickOver = event => {
259
331
( ) => dispatch ( onHover ( node . data . rtid ) ) ;
260
332
console . log ( 'line 197 event.target' , event . target . ownerSVGElement ) ;
261
333
console . log ( 'line 199 This is DATA: ' , data ) ;
@@ -276,7 +348,7 @@ export default function ComponentMap({
276
348
} ;
277
349
278
350
return (
279
- < Group top = { top } left = { left } key = { key } >
351
+ < Group top = { top } left = { left } key = { key } className = "rect" >
280
352
{ node . depth === 0 && (
281
353
< circle
282
354
r = { 12 }
@@ -287,17 +359,17 @@ export default function ComponentMap({
287
359
forceUpdate ( ) ;
288
360
} }
289
361
/>
290
- ) }
362
+ ) }
291
363
{ /* This creates the rectangle boxes for each component and sets it relative position to other parent nodes of the same level. */ }
292
364
{ node . depth !== 0 && (
293
365
< rect
294
366
height = { height }
295
367
width = { width }
296
368
y = { - height / 2 }
297
369
x = { - width / 2 }
298
- //node.children = if node has children
370
+ // node.children = if node has children
299
371
fill = { node . children ? '#161521' : '#62d6fb' }
300
- //node.data.isExpanded = if node is collapsed
372
+ // node.data.isExpanded = if node is collapsed
301
373
// stroke={(node.data.isExpanded && node.child) ? '#95fb62' : '#a69ff5'} => node.child is gone when clicked, even if it actually has children. Maybe better call node.children => node.leaf
302
374
stroke = { ( node . data . isExpanded && node . data . children . length > 0 ) ? '#95fb62' : '#a69ff5' }
303
375
@@ -308,42 +380,48 @@ export default function ComponentMap({
308
380
rx = { node . children ? 4 : 10 }
309
381
onDoubleClick = { ( ) => {
310
382
node . data . isExpanded = ! node . data . isExpanded ;
383
+ hideTooltip ( ) ;
384
+ setTooltip ( false ) ;
311
385
forceUpdate ( ) ;
312
386
} }
313
387
// Tooltip event handlers
314
388
// test feature
315
- // onClick = {handleMouseOver }
389
+ // onClick = {handleMouseAndClickOver }
316
390
onClick = { event => {
317
- if ( tooltip ) { // cohort 45
318
- hideTooltip ( ) ;
319
- setTooltip ( false ) ;
320
- } else {
321
- handleMouseOver ( event ) ;
391
+ if ( ! tooltip ) {
392
+ handleMouseAndClickOver ( event ) ;
322
393
setTooltip ( true ) ;
323
394
}
395
+ // if (tooltip) { // cohort 45
396
+ // hideTooltip();
397
+ // setTooltip(false);
398
+ // } else {
399
+ // handleMouseAndClickOver(event);
400
+ // setTooltip(true);
401
+ // }
324
402
} }
325
403
onMouseEnter = { ( ) => dispatch ( onHover ( node . data . rtid ) ) } // fix this not working
326
404
onMouseLeave = { ( ) => dispatch ( onHoverExit ( node . data . rtid ) ) }
327
405
/>
328
- ) }
406
+ ) }
329
407
{ /* Display text inside of each component node */ }
330
408
< text
331
- dy = ".33em"
332
- fontSize = { 10 }
333
- fontFamily = "Roboto"
334
- textAnchor = "middle"
335
- style = { { pointerEvents : 'none' } }
336
- fill = {
409
+ dy = ".33em"
410
+ fontSize = { 10 }
411
+ fontFamily = "Roboto"
412
+ textAnchor = "middle"
413
+ style = { { pointerEvents : 'none' } }
414
+ fill = {
337
415
node . depth === 0
338
416
? '#161521'
339
417
: node . children
340
418
? 'white'
341
419
: '#161521'
342
420
}
343
- z
344
- >
345
- { node . data . name }
346
- </ text >
421
+ z
422
+ >
423
+ { node . data . name }
424
+ </ text >
347
425
</ Group >
348
426
) ;
349
427
} ) }
@@ -361,7 +439,11 @@ export default function ComponentMap({
361
439
style = { tooltipStyles }
362
440
onClick = { hideTooltip }
363
441
>
364
- < div >
442
+ < div onClick = { ( ) => {
443
+ setTooltip ( false ) ;
444
+ hideTooltip ( ) ;
445
+ } }
446
+ >
365
447
< div style = { { } } >
366
448
{ ' ' }
367
449
< strong > { tooltipData . name } </ strong >
@@ -379,14 +461,13 @@ export default function ComponentMap({
379
461
{ tooltipData . state }
380
462
</ div >
381
463
< div style = { scrollStyle } >
382
- Props:
383
- { makePropsPretty ( tooltipData . componentData . props ) }
384
- { /* {JSON.stringify(tooltipData.componentData.props)} */ }
464
+ < div className = "props" >
465
+ Props:
466
+ { makePropsPretty ( tooltipData . componentData . props ) }
467
+ </ div >
385
468
</ div >
386
469
</ div >
387
470
</ TooltipInPortal >
388
-
389
-
390
471
) }
391
472
</ div >
392
473
) ;
0 commit comments