11import React from 'react' ;
22// will create a build func and then call the helper funcs to return an object
33// make a new instance of this class in flow, call the build method, and pass this as state
4+
45class FlowBuilder {
56 constructor ( data ) {
67 this . parsedData = [ data ] ;
78 this . id = 0 ;
9+ this . x = 0 ;
10+ this . y = 0 ;
811 this . initialNodes = [ ] ;
912 this . viewData ;
1013 this . edgeId = 0 ;
1114 this . initialEdges = [ ] ;
1215 }
1316
14- buildNodesArray ( parsedData ) {
17+ buildNodesArray ( parsedData , x = this . x , y = this . y ) {
1518 if ( ! parsedData ) return ;
1619
20+
1721 parsedData . forEach ( ( item ) => {
1822 const node = {
1923 id : ( ++ this . id ) . toString ( ) ,
2024 data : {
2125 label : (
22- < div key = { this . id } >
23- < ul >
24- < li > { item . fileName } </ li >
25- < li > Client Component: { item . isClientComponent . toString ( ) } </ li >
26- </ ul >
27- </ div >
26+ < div className = "text-sm font-medium text-ellipsis overflow-hidden ..." key = { this . id } > { item . fileName } </ div >
2827 )
2928 } ,
30- type : item . depth === 0 ? 'input' : '' ,
31- position : { x : 0 , y : 0 } ,
29+ // type: item.depth === 0 ? 'input' : '',
30+ type : 'default' ,
31+ position : { x : x += 40 , y : y += 30 } ,
3232 style : {
33- backgroundColor : "var(--vscode-dropdown-background)" ,
34- borderRadius : "15px" ,
35- width : '265px' ,
36- boxShadow : '0px 4px 4px rgba(0, 0, 0, 0.25)' ,
37- border : 'none' ,
38- padding : '10px 10px 3px 10px'
33+ borderRadius : '6px' ,
34+ borderWidth : '2px' ,
35+ borderColor : '#6b7280' ,
36+ display : 'flex' ,
37+ justifyContent : 'center' ,
38+ placeItems : 'center' ,
39+ backgroundColor : `${ ( item . isClientComponent ) ? '#fdba74' : '#93C5FD' } ` ,
3940 } ,
4041 } ;
4142 this . initialNodes . push ( node ) ;
4243 if ( item . children ) {
43- this . buildNodesArray ( item . children ) ;
44+ this . buildNodesArray ( item . children , this . x += 40 , this . y += 30 ) ;
4445 }
4546 } ) ;
46- // console.log('initialNodes', this.initialNodes);
4747 } ;
4848
4949 buildEdgesArray ( parsedData , parentID ) {
@@ -65,7 +65,6 @@ class FlowBuilder {
6565 this . buildEdgesArray ( item . children , nodeID ) ;
6666 }
6767 } ) ;
68- // console.log('initialEdges', this.initialEdges);
6968 }
7069
7170 build ( settings ) {
@@ -98,7 +97,7 @@ class FlowBuilder {
9897 } ) ;
9998 }
10099 traverse ( treeParsed ) ;
101- // Update the vewData state
100+ // Update the viewData state
102101 this . viewData = ( [ treeParsed ] ) ;
103102 console . log ( 'viewData:' , this . viewData ) ;
104103 this . buildNodesArray ( this . viewData ) ;
0 commit comments