1+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2+ /* eslint-disable no-restricted-syntax */
3+ /* eslint-disable guard-for-in */
14// @ts -nocheck
2- import React , { useState } from 'react' ;
5+ import React , { useState , useEffect } from 'react' ;
36import { Group } from '@visx/group' ;
47import { hierarchy , Tree } from '@visx/hierarchy' ;
58import { LinearGradient } from '@visx/gradient' ;
@@ -11,12 +14,16 @@ import {
1114 TooltipWithBounds ,
1215 defaultStyles ,
1316} from '@visx/tooltip' ;
17+ import { isAbsolute } from 'path' ;
18+ import { nest } from 'jscharting' ;
1419import useForceUpdate from './useForceUpdate' ;
1520import LinkControls from './LinkControls' ;
1621import getLinkComponent from './getLinkComponent' ;
1722import { onHover , onHoverExit } from '../actions/actions' ;
1823import { useStoreContext } from '../store' ;
1924
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+
2027// const root = hierarchy({
2128// name: 'root',
2229// children: [
@@ -128,12 +135,13 @@ export default function ComponentMap({
128135 lineHeight : '18px' ,
129136 fontFamily : 'Roboto' ,
130137 zIndex : 100 ,
138+ 'pointer-events' : 'all !important' ,
131139 } ;
132140
133141 const scrollStyle = {
134142 minWidth : '60' ,
135143 maxWidth : '300' ,
136- maxHeight : '100px ' ,
144+ maxHeight : '200px ' ,
137145 overflowY : 'scroll' ,
138146 overflowWrap : 'break-word' ,
139147 } ;
@@ -143,53 +151,117 @@ export default function ComponentMap({
143151 return `${ time } ms ` ;
144152 } ;
145153
146- //places all nodes into a flat array
154+ // places all nodes into a flat array
147155 const nodeList = [ ] ;
148156
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+
149215 const makePropsPretty = data => {
150216 const propsFormat = [ ] ;
217+ const nestedObj = [ ] ;
218+ // console.log('show me the data we are getting', data);
151219 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 ) ;
155227 }
156- propsFormat . push ( < p >
157- { `${ JSON . stringify ( key ) } : ${ JSON . stringify ( nestedObj || data [ key ] ) } ` }
158- </ p > ) ;
159228 }
160- console . log ( 'this is propsFormat' , propsFormat ) ;
229+ if ( nestedObj ) {
230+ propsFormat . push ( nestedObj ) ;
231+ }
232+ // console.log('this is propsformat', propsFormat);
161233 return propsFormat ;
162234 } ;
163235
164- const collectNodes = ( node ) => {
236+ const collectNodes = node => {
165237 nodeList . splice ( 0 , nodeList . length ) ;
166- console . log ( " Root node:" , node ) ;
238+ // console.log(' Root node:' , node);
167239 nodeList . push ( node ) ;
168240 for ( let i = 0 ; i < nodeList . length ; i ++ ) {
169241 const cur = nodeList [ i ] ;
170242 if ( cur . children && cur . children . length > 0 ) {
171- for ( let child of cur . children ) {
243+ for ( const child of cur . children ) {
172244 nodeList . push ( child ) ;
173245 }
174246 }
175247 }
176- console . log ( 'NODELIST in ComponentMap: ' , nodeList ) ;
177- }
248+ // console.log('NODELIST in ComponentMap: ', nodeList);
249+ } ;
178250 collectNodes ( snapshots [ lastNode ] ) ;
179251
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
181253 const startNode = null ;
182254 const findSelectedNode = ( ) => {
183- console . log ( selectedNode ) ;
184- for ( let node of nodeList ) {
255+ // console.log(selectedNode);
256+ for ( const node of nodeList ) {
185257 if ( node . name === selectedNode ) {
186258 startNode = node ;
187259 }
188260 }
189- }
261+ } ;
190262 findSelectedNode ( ) ;
191263
192- // controls for the map
264+ // controls for the map
193265 const LinkComponent = getLinkComponent ( { layout, linkType, orientation } ) ;
194266 return totalWidth < 10 ? null : (
195267 < div >
@@ -255,7 +327,7 @@ export default function ComponentMap({
255327 }
256328
257329 // mousing controls & Tooltip display logic
258- const handleMouseOver = event => {
330+ const handleMouseAndClickOver = event => {
259331 ( ) => dispatch ( onHover ( node . data . rtid ) ) ;
260332 console . log ( 'line 197 event.target' , event . target . ownerSVGElement ) ;
261333 console . log ( 'line 199 This is DATA: ' , data ) ;
@@ -276,7 +348,7 @@ export default function ComponentMap({
276348 } ;
277349
278350 return (
279- < Group top = { top } left = { left } key = { key } >
351+ < Group top = { top } left = { left } key = { key } className = "rect" >
280352 { node . depth === 0 && (
281353 < circle
282354 r = { 12 }
@@ -287,17 +359,17 @@ export default function ComponentMap({
287359 forceUpdate ( ) ;
288360 } }
289361 />
290- ) }
362+ ) }
291363 { /* This creates the rectangle boxes for each component and sets it relative position to other parent nodes of the same level. */ }
292364 { node . depth !== 0 && (
293365 < rect
294366 height = { height }
295367 width = { width }
296368 y = { - height / 2 }
297369 x = { - width / 2 }
298- //node.children = if node has children
370+ // node.children = if node has children
299371 fill = { node . children ? '#161521' : '#62d6fb' }
300- //node.data.isExpanded = if node is collapsed
372+ // node.data.isExpanded = if node is collapsed
301373 // 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
302374 stroke = { ( node . data . isExpanded && node . data . children . length > 0 ) ? '#95fb62' : '#a69ff5' }
303375
@@ -308,42 +380,48 @@ export default function ComponentMap({
308380 rx = { node . children ? 4 : 10 }
309381 onDoubleClick = { ( ) => {
310382 node . data . isExpanded = ! node . data . isExpanded ;
383+ hideTooltip ( ) ;
384+ setTooltip ( false ) ;
311385 forceUpdate ( ) ;
312386 } }
313387 // Tooltip event handlers
314388 // test feature
315- // onClick = {handleMouseOver }
389+ // onClick = {handleMouseAndClickOver }
316390 onClick = { event => {
317- if ( tooltip ) { // cohort 45
318- hideTooltip ( ) ;
319- setTooltip ( false ) ;
320- } else {
321- handleMouseOver ( event ) ;
391+ if ( ! tooltip ) {
392+ handleMouseAndClickOver ( event ) ;
322393 setTooltip ( true ) ;
323394 }
395+ // if (tooltip) { // cohort 45
396+ // hideTooltip();
397+ // setTooltip(false);
398+ // } else {
399+ // handleMouseAndClickOver(event);
400+ // setTooltip(true);
401+ // }
324402 } }
325403 onMouseEnter = { ( ) => dispatch ( onHover ( node . data . rtid ) ) } // fix this not working
326404 onMouseLeave = { ( ) => dispatch ( onHoverExit ( node . data . rtid ) ) }
327405 />
328- ) }
406+ ) }
329407 { /* Display text inside of each component node */ }
330408 < 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 = {
337415 node . depth === 0
338416 ? '#161521'
339417 : node . children
340418 ? 'white'
341419 : '#161521'
342420 }
343- z
344- >
345- { node . data . name }
346- </ text >
421+ z
422+ >
423+ { node . data . name }
424+ </ text >
347425 </ Group >
348426 ) ;
349427 } ) }
@@ -361,7 +439,11 @@ export default function ComponentMap({
361439 style = { tooltipStyles }
362440 onClick = { hideTooltip }
363441 >
364- < div >
442+ < div onClick = { ( ) => {
443+ setTooltip ( false ) ;
444+ hideTooltip ( ) ;
445+ } }
446+ >
365447 < div style = { { } } >
366448 { ' ' }
367449 < strong > { tooltipData . name } </ strong >
@@ -379,14 +461,13 @@ export default function ComponentMap({
379461 { tooltipData . state }
380462 </ div >
381463 < 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 >
385468 </ div >
386469 </ div >
387470 </ TooltipInPortal >
388-
389-
390471 ) }
391472 </ div >
392473 ) ;
0 commit comments