@@ -52,7 +52,7 @@ const generateUnformattedCode = (
52
52
// returns an array of objects which may include components, html elements, and/or route links
53
53
const getEnrichedChildren = ( currentComponent : Component | ChildElement ) => {
54
54
// declare an array of enriched children
55
- const enrichedChildren = currentComponent . children . map ( ( elem : any ) => {
55
+ const enrichedChildren = currentComponent . children ? .map ( ( elem : any ) => {
56
56
//enrichedChildren is iterating through the children array
57
57
const child = { ...elem } ;
58
58
// check if child is a component
@@ -122,8 +122,21 @@ const generateUnformattedCode = (
122
122
//LEGACY PD: CAN ADD PROPS HERE AS JSX ATTRIBUTE
123
123
const elementTagDetails = ( childElement : object ) => {
124
124
let customizationDetails = '' ;
125
+ let passedInPropsString = '' ;
126
+ if ( childElement . type === 'Component' ) {
127
+ let childComponent ;
128
+ for ( let i = 0 ; i < components . length ; i ++ ) {
129
+ if ( childElement . name === components [ i ] . name ) {
130
+ childComponent = components [ i ] ;
131
+ }
132
+ }
133
+ childComponent . passedInProps . forEach ( prop => { passedInPropsString += `${ prop . key } = {${ prop . key } } `
134
+ } )
135
+ }
136
+
137
+
125
138
if ( childElement . childId && childElement . tag !== 'Route' ) //legacypd
126
- customizationDetails += ' ' + `id= "${ + childElement . childId } "` + ' props = {props}' ;
139
+ customizationDetails += ' ' + `id = "${ + childElement . childId } " ` + ` ${ passedInPropsString } ` ;
127
140
if ( childElement . attributes && childElement . attributes . cssClasses ) {
128
141
customizationDetails +=
129
142
' ' + `className="${ childElement . attributes . cssClasses } "` ;
@@ -244,7 +257,7 @@ const generateUnformattedCode = (
244
257
return `${ enrichedChildren
245
258
. map ( ( child : any ) => {
246
259
if ( child . type === 'Component' ) {
247
- return `<${ child . name } ${ elementTagDetails ( child ) } />` ;
260
+ return `<${ child . name } ${ elementTagDetails ( child ) } />` ;
248
261
} else if ( child . type === 'HTML Element' ) {
249
262
return elementGenerator ( child , level ) ;
250
263
}
@@ -301,38 +314,38 @@ const generateUnformattedCode = (
301
314
} ;
302
315
303
316
// // Generate import --- FROM PREVIOUS ITERATION BEFORE 12.0, NOT WORKING -> CONSIDER DELETING
304
- let importContext = '' ;
305
- if ( currComponent . useContext ) {
306
- for ( const providerId of Object . keys ( currComponent . useContext ) ) {
307
- const providerComponent = components [ parseInt ( providerId ) - 1 ] ;
308
- importContext += `import ${ providerComponent . name } Context from './${ providerComponent . name } .tsx'\n \t\t` ;
309
- }
310
- }
311
- if ( currComponent . useContext ) {
312
- for ( const providerId of Object . keys ( currComponent . useContext ) ) {
313
- const statesFromProvider =
314
- currComponent . useContext [ parseInt ( providerId ) ] . statesFromProvider ; //{1: {Set, compLink, compText}, 2 : {}... }
315
- const providerComponent = components [ parseInt ( providerId ) - 1 ] ;
316
- providers +=
317
- 'const ' +
318
- providerComponent . name . toLowerCase ( ) +
319
- 'Context = useContext(' +
320
- providerComponent . name +
321
- 'Context);\n \t\t' ;
322
- for ( let i = 0 ; i < providerComponent . stateProps . length ; i ++ ) {
323
- if ( statesFromProvider . has ( providerComponent . stateProps [ i ] . id ) ) {
324
- context +=
325
- 'const ' +
326
- providerComponent . stateProps [ i ] . key +
327
- ' = ' +
328
- providerComponent . name . toLowerCase ( ) +
329
- 'Context.' +
330
- providerComponent . stateProps [ i ] . key +
331
- '; \n \t\t' ;
332
- }
333
- }
334
- }
335
- }
317
+ // let importContext = '';
318
+ // if (currComponent.useContext) {
319
+ // for (const providerId of Object.keys(currComponent.useContext)) {
320
+ // const providerComponent = components[parseInt(providerId) - 1];
321
+ // importContext += `import ${providerComponent.name}Context from './${providerComponent.name}.tsx'\n \t\t`;
322
+ // }
323
+ // }
324
+ // if (currComponent.useContext) {
325
+ // for (const providerId of Object.keys(currComponent.useContext)) {
326
+ // const statesFromProvider =
327
+ // currComponent.useContext[parseInt(providerId)].statesFromProvider; //{1: {Set, compLink, compText}, 2 : {}... }
328
+ // const providerComponent = components[parseInt(providerId) - 1];
329
+ // providers +=
330
+ // 'const ' +
331
+ // providerComponent.name.toLowerCase() +
332
+ // 'Context = useContext(' +
333
+ // providerComponent.name +
334
+ // 'Context);\n \t\t';
335
+ // for (let i = 0; i < providerComponent.stateProps.length; i++) {
336
+ // if (statesFromProvider.has(providerComponent.stateProps[i].id)) {
337
+ // context +=
338
+ // 'const ' +
339
+ // providerComponent.stateProps[i].key +
340
+ // ' = ' +
341
+ // providerComponent.name.toLowerCase() +
342
+ // 'Context.' +
343
+ // providerComponent.stateProps[i].key +
344
+ // '; \n \t\t';
345
+ // }
346
+ // }
347
+ // }
348
+ // }
336
349
// create final component code. component code differs between classic react, next.js, gatsby.js
337
350
// classic react code
338
351
if ( projectType === 'Classic React' ) {
@@ -362,15 +375,15 @@ const generateUnformattedCode = (
362
375
363
376
if ( currComponent . name === 'App' ) {
364
377
allContext . reverse ( ) . forEach ( ( el , i ) => {
365
- let tabs = `\t\t` ;
366
- if ( i === allContext . length - 1 ) {
367
- tabs = `\t\t\t` ;
368
- }
369
- result = `${ tabs . repeat ( allContext . length - i ) } <${
370
- el . name
371
- } Provider>\n ${ result } \n ${ tabs . repeat ( allContext . length - i ) } </${
372
- el . name
373
- } Provider>`;
378
+ let tabs = `\t\t` ;
379
+ if ( i === allContext . length - 1 ) {
380
+ tabs = `\t\t\t` ;
381
+ }
382
+ result = `${ tabs . repeat ( allContext . length - i ) } <${
383
+ el . name
384
+ } Provider>\n ${ result } \n ${ tabs . repeat ( allContext . length - i ) } </${
385
+ el . name
386
+ } Provider>`;
374
387
} ) ;
375
388
}
376
389
return result ;
@@ -411,9 +424,7 @@ ${createContextImport()}
411
424
${ importsMapped }
412
425
${ `const ${ currComponent . name } = (props) => {` }
413
426
${ createUseContextHook ( ) }
414
- ${ ` const [value, setValue] = useState("");${ writeStateProps (
415
- currComponent . useStateCodes
416
- ) } `}
427
+ ${ `${ writeStateProps ( currComponent . useStateCodes ) } ` }
417
428
418
429
return(
419
430
<>
@@ -436,7 +447,6 @@ export default ${currComponent.name}
436
447
437
448
const ${ currComponent . name [ 0 ] . toUpperCase ( ) +
438
449
currComponent . name . slice ( 1 ) } = (props): JSX.Element => {
439
- const [value, setValue] = useState<any | undefined>("INITIAL VALUE");
440
450
return (
441
451
<>
442
452
${
@@ -462,7 +472,6 @@ export default ${currComponent.name}
462
472
import { StaticQuery, graphql } from 'gatsby';
463
473
${ links ? `import { Link } from 'gatsby'` : `` }
464
474
const ${ currComponent . name } = (props: any): JSX.Element => {
465
- const[value, setValue] = useState<any | undefined>("INITIAL VALUE");
466
475
return (
467
476
<>
468
477
${
0 commit comments