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
1720 parsedData . forEach ( ( item ) => {
1821 const node = {
1922 id : ( ++ this . id ) . toString ( ) ,
2023 data : {
2124 label : (
22- < div key = { this . id } >
23- < ul >
24- < li > { item . fileName } </ li >
25- < li > Client Component: { item . isClientComponent . toString ( ) } </ li >
26- </ ul >
25+ < div className = { `-mx-2.5 -my-2.5 py-2 px-9 shadow-lg rounded-md border-2 border-gray-500 ${ ( item . isClientComponent ) ? 'bg-orange-300' : 'bg-blue-300' } ` } >
26+ < div className = "flex justify-center place-items-center" key = { this . id } >
27+ < div className = "text-sm font-medium" > { item . fileName } </ div >
28+ </ div >
2729 </ div >
2830 )
2931 } ,
30- type : item . depth === 0 ? 'input' : '' ,
31- position : { x : 0 , y : 0 } ,
32+ // type: item.depth === 0 ? 'input' : '',
33+ // type: item.isClientComponent ? 'input' : 'output',
34+ type : 'default' ,
35+ position : { x : x += 40 , y : y += 30 } ,
3236 style : {
33- backgroundColor : "var(--vscode-dropdown-background)" ,
34- borderRadius : "15px" ,
35- width : '265px' ,
36- boxShadow : '0px 4px 4px rgba(0, 0, 0, 0.25)' ,
3737 border : 'none' ,
38- padding : '10px 10px 3px 10px'
39- } ,
38+ borderRadius : "6px"
39+ }
4040 } ;
4141 this . initialNodes . push ( node ) ;
4242 if ( item . children ) {
43- this . buildNodesArray ( item . children ) ;
43+ this . buildNodesArray ( item . children , this . x += 40 , this . y += 30 ) ;
4444 }
4545 } ) ;
46- // console.log('initialNodes', this.initialNodes);
4746 } ;
4847
4948 buildEdgesArray ( parsedData , parentID ) {
@@ -65,7 +64,6 @@ class FlowBuilder {
6564 this . buildEdgesArray ( item . children , nodeID ) ;
6665 }
6766 } ) ;
68- // console.log('initialEdges', this.initialEdges);
6967 }
7068
7169 build ( settings ) {
@@ -98,7 +96,7 @@ class FlowBuilder {
9896 } ) ;
9997 }
10098 traverse ( treeParsed ) ;
101- // Update the vewData state
99+ // Update the viewData state
102100 this . viewData = ( [ treeParsed ] ) ;
103101 console . log ( 'viewData:' , this . viewData ) ;
104102 this . buildNodesArray ( this . viewData ) ;
0 commit comments