@@ -14,11 +14,16 @@ import Tooltip from '@material-ui/core/Tooltip';
14
14
import Collapse from '@material-ui/core/Collapse' ;
15
15
import Switch from '@material-ui/core/Switch' ; // for state/class toggling
16
16
import InputLabel from '@material-ui/core/InputLabel' ; // labeling of state/class toggles
17
- import { ComponentInt , ComponentsInt , PropsInt } from '../../interfaces/Interfaces' ; // unused
17
+ import {
18
+ ComponentInt ,
19
+ ComponentsInt ,
20
+ PropsInt
21
+ } from '../../interfaces/Interfaces' ; // unused
18
22
interface LeftColExpPanPropsInt extends PropsInt {
19
23
classes : any ;
20
24
id ?: number ;
21
25
component : ComponentInt ;
26
+ addProp ( arg : { title : string ; type : string } ) : void ;
22
27
addChild ( arg : { title : string ; childType : string ; HTMLInfo ?: object } ) : void ;
23
28
changeFocusComponent ( arg : { title : string } ) : void ;
24
29
selectableChildren : number [ ] ;
@@ -45,6 +50,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
45
50
focusComponent,
46
51
components,
47
52
component,
53
+ addProp,
48
54
addChild,
49
55
changeFocusComponent,
50
56
selectableChildren,
@@ -65,8 +71,6 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
65
71
// state/class toggles will be displayed when a component is focused
66
72
const focusedToggle = isFocused ( ) === 'focused' ? true : false ;
67
73
68
-
69
-
70
74
//this function determines whether edit mode for component name should be entered or not
71
75
//resets the title if 'escape' key is hit
72
76
const handleEdit = ( ) => {
@@ -78,12 +82,54 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
78
82
}
79
83
} ;
80
84
85
+ // function adds childProps & also addsChild at the same time to the parents and updates state
86
+ // to reflect the childrenArray to be update inside the parent as well as the props from the child
87
+ // automatically destructured in the parents
88
+ const addChildProps = ( ) => {
89
+ const addedChildProps = components . find (
90
+ ( component : ComponentInt ) => component . title === title
91
+ ) ;
92
+
93
+ const parentKeys : any [ ] = [ ] ;
94
+ if ( focusComponent . props . length > 0 ) {
95
+ focusComponent . props . forEach ( key => parentKeys . push ( key . key ) ) ;
96
+ }
97
+ console . log ( 'this is parentKeys' , parentKeys ) ;
98
+ // sorting through object keys of the focusComponent
99
+
100
+ let i = 0 ;
101
+ while ( i <= addedChildProps . props . length ) {
102
+ if ( addedChildProps . props . length ) {
103
+ if ( i === 0 ) {
104
+ addChild ( { title, childType : 'COMP' } ) ;
105
+ changeFocusComponent ( { title : focusComponent . title } ) ;
106
+ }
107
+ if ( addedChildProps . props [ i ] ) {
108
+ const newKey = addedChildProps . props [ i ] [ 'key' ] ,
109
+ newType = addedChildProps . props [ i ] [ 'type' ] ;
110
+ if ( ! parentKeys . includes ( newKey ) )
111
+ addProp ( {
112
+ key : newKey ,
113
+ type : newType
114
+ } ) ;
115
+ else console . log ( 'child prop already exists in parent!' ) ;
116
+ }
117
+ } else {
118
+ if ( i === 0 ) {
119
+ addChild ( { title, childType : 'COMP' } ) ;
120
+ changeFocusComponent ( { title : focusComponent . title } ) ;
121
+ }
122
+ }
123
+ i ++ ;
124
+ }
125
+ } ;
126
+
81
127
return (
82
128
< Grid
83
129
container
84
- direction = " row"
85
- justify = " center"
86
- alignItems = " center"
130
+ direction = ' row'
131
+ justify = ' center'
132
+ alignItems = ' center'
87
133
style = { {
88
134
minWidth : '470px'
89
135
} }
@@ -106,7 +152,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
106
152
in = { focusedToggle }
107
153
collapsedHeight = { '80px' } //The type for the Collapse component is asking for a string, but if you put in a string and not a number, the component itself breaks.
108
154
style = { { borderRadius : '5px' } }
109
- timeout = " auto"
155
+ timeout = ' auto'
110
156
>
111
157
{ /* NOT SURE WHY COLOR: RED IS USED, TRIED REMOVING IT AND NO VISIBLE CHANGE OCCURED. */ }
112
158
< Grid
@@ -156,10 +202,10 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
156
202
</ Typography >
157
203
) : (
158
204
< TextField //show a text field for editing instead if edit mode entered
159
- id = " filled"
160
- label = " Change Component Name"
205
+ id = ' filled'
206
+ label = ' Change Component Name'
161
207
defaultValue = { title }
162
- variant = " outlined"
208
+ variant = ' outlined'
163
209
className = { classes . text }
164
210
InputProps = { {
165
211
className : classes . light //all of these styling makes the input box border, label, and text default to white.
@@ -191,7 +237,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
191
237
{ focusedToggle ? (
192
238
< span style = { { display : 'inline-flex' } } >
193
239
< InputLabel
194
- htmlFor = " stateful"
240
+ htmlFor = ' stateful'
195
241
style = { {
196
242
color : '#fff' ,
197
243
marginBottom : '0px' ,
@@ -210,12 +256,12 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
210
256
toggleComponentState ( { id } ) ;
211
257
changeFocusComponent ( { title } ) ;
212
258
} }
213
- value = " stateful"
214
- color = " primary"
259
+ value = ' stateful'
260
+ color = ' primary'
215
261
// id={props.id.toString()}
216
262
/>
217
263
< InputLabel
218
- htmlFor = " classBased"
264
+ htmlFor = ' classBased'
219
265
style = { {
220
266
color : '#fff' ,
221
267
marginBottom : '0px' ,
@@ -234,19 +280,19 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
234
280
toggleComponentClass ( { id } ) ;
235
281
changeFocusComponent ( { title } ) ;
236
282
} }
237
- value = " classBased"
238
- color = " primary"
283
+ value = ' classBased'
284
+ color = ' primary'
239
285
/>
240
286
</ span >
241
287
) : (
242
288
''
243
289
) }
244
290
{ focusedToggle && component . id !== 1 ? (
245
291
< Button
246
- variant = " text"
247
- size = " small"
248
- color = " default"
249
- aria-label = " Delete"
292
+ variant = ' text'
293
+ size = ' small'
294
+ color = ' default'
295
+ aria-label = ' Delete'
250
296
className = { classes . margin }
251
297
onClick = { ( ) =>
252
298
deleteComponent ( {
@@ -295,15 +341,14 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
295
341
< div />
296
342
) : (
297
343
< Tooltip
298
- title = " add as child"
299
- aria-label = " add as child"
300
- placement = " left"
344
+ title = ' add as child'
345
+ aria-label = ' add as child'
346
+ placement = ' left'
301
347
>
302
348
< IconButton
303
- aria-label = " Add"
349
+ aria-label = ' Add'
304
350
onClick = { ( ) => {
305
- addChild ( { title, childType : 'COMP' } ) ;
306
- changeFocusComponent ( { title : focusComponent . title } ) ;
351
+ addChildProps ( ) ;
307
352
} }
308
353
>
309
354
< AddIcon style = { { color, float : 'right' , marginTop : '10px' } } />
0 commit comments