@@ -53,25 +53,24 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
53
53
const [ eventAll , setEventAll ] = useState ( [ '' , '' ] ) ;
54
54
const [ eventRow , setEventRow ] = useState ( [ ] ) ;
55
55
// ------------------------------------------- added code above -------------------------------------------
56
-
57
- const currFocus = state . components
58
- . find ( ( el ) => {
59
- return el . id === state . canvasFocus . componentId ;
60
- } )
61
- . children . find ( ( el ) => {
62
- return el . childId === state . canvasFocus . childId ;
63
- } ) ;
64
- console . log ( currFocus ) ;
56
+ const currFocus = getFocus ( ) . child ;
57
+ // state.components
58
+ // .find((el) => {
59
+ // return el.id === state.canvasFocus.componentId;
60
+ // })
61
+ // .children.find((el) => {
62
+ // return el.childId === state.canvasFocus.childId;
63
+ // });
65
64
useEffect ( ( ) => {
66
65
currFocus ?. attributes ?. compLink && setCompLink ( currFocus . attributes . compLink ) ;
66
+ setEventAll ( [ '' , '' ] ) ;
67
67
if ( currFocus ) {
68
68
const addedEvent : [ ] = [ ] ;
69
69
for ( const [ event , funcName ] of Object . entries ( currFocus ?. events ) ) {
70
70
addedEvent . push ( { id : event , funcName } )
71
71
}
72
72
setEventRow ( addedEvent ) ;
73
73
}
74
- console . log ( state ) ;
75
74
} , [ state ] ) ;
76
75
77
76
//this function allows properties to persist and appear in nested divs
@@ -109,7 +108,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
109
108
setCompHeight ( style . height ? style . height : '' ) ;
110
109
setBGColor ( style . backgroundColor ? style . backgroundColor : '' ) ;
111
110
setEventAll ( [ '' , '' ] ) ;
112
- // setFuncName('');
113
111
} ;
114
112
let configTarget ;
115
113
// after component renders, reset the input fields with the current styles of the selected child
@@ -153,7 +151,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
153
151
// ------------------------------------------- added code below -------------------------------------------
154
152
case 'event' :
155
153
setEventAll ( inputVal ? [ inputVal , `handle${ inputVal . slice ( 2 ) } ` ] : [ '' , '' ] ) ;
156
- // setFuncName(currFocus.events[inputVal] ? currFocus.events[inputVal] : `handle${event.slice(2)}`);
157
154
break ;
158
155
case 'funcName' :
159
156
setEventAll ( [ eventAll [ 0 ] , inputVal ] ) ;
@@ -165,7 +162,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
165
162
} ;
166
163
// returns the current component referenced in canvasFocus
167
164
// along with its child instance, if it exists
168
- const getFocus = ( ) => {
165
+ function getFocus ( ) {
169
166
// find and store component's name based on canvasFocus.componentId
170
167
// note: deep clone here to make sure we don't end up altering state
171
168
const focusTarget = JSON . parse (
@@ -189,24 +186,26 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
189
186
if ( currentChild . childId === childInstanceId ) {
190
187
focusChild = currentChild ;
191
188
focusTarget . child . style = focusChild . style ;
189
+ focusTarget . child . events = focusChild . events ;
190
+ focusTarget . child . attributes = focusChild . attributes ;
192
191
break ;
193
192
}
194
193
if ( currentChild . name !== 'input' && currentChild . name !== 'img' )
195
194
currentChild . children . forEach ( child => searchArray . push ( child ) ) ;
196
195
}
197
-
196
+
198
197
// if type is Component, use child's typeId to search through state components and find matching component's name
199
198
if ( focusChild . type === 'Component' ) {
200
199
focusTarget . child . type = 'component' ;
201
200
focusTarget . child . name = state . components . find (
202
- comp => comp . id === focusChild . typeId
203
- ) . name ;
204
- // if type is HTML Element, search through HTML types to find matching element's name
201
+ comp => comp . id === focusChild . typeId
202
+ ) . name ;
203
+ // if type is HTML Element, search through HTML types to find matching element's name
205
204
} else if ( focusChild . type === 'HTML Element' ) {
206
205
focusTarget . child . type = 'HTML element' ;
207
206
focusTarget . child . name = state . HTMLTypes . find (
208
- elem => elem . id === focusChild . typeId
209
- ) . name ;
207
+ elem => elem . id === focusChild . typeId
208
+ ) . name ;
210
209
}
211
210
}
212
211
return focusTarget ;
@@ -279,25 +278,25 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
279
278
{
280
279
field : 'funcName' ,
281
280
headerName : 'Function Name' ,
282
- width : '40 %' ,
281
+ width : '50 %' ,
283
282
editable : false ,
284
283
flex : 1 ,
285
284
disableColumnMenu : true ,
286
285
} ,
287
286
{
288
287
field : 'delete' ,
289
- headerName : 'Delete Event ' ,
290
- width : '20 %' ,
288
+ headerName : 'Delete' ,
289
+ width : '10 %' ,
291
290
editable : false ,
292
291
flex : 1 ,
292
+ sortable : false ,
293
293
disableColumnMenu : true ,
294
- disableColumnFilter : true ,
295
294
renderCell : function renderCell ( params : any ) {
296
295
return (
297
296
< Button
298
- style = { { width : `${ 3 } px` } }
297
+ style = { { width : `${ 3 } px` , color : 'black' } }
299
298
onClick = { ( ) => {
300
- // deleteState (params.id);
299
+ deleteEvent ( params . id ) ;
301
300
} }
302
301
>
303
302
< ClearIcon style = { { width : `${ 15 } px` } } />
@@ -307,53 +306,54 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
307
306
}
308
307
] ;
309
308
309
+ const deleteEvent = selectedEvent => {
310
+ dispatch ( {
311
+ type : 'DELETE EVENT' ,
312
+ payload : { event : selectedEvent }
313
+ } ) ;
314
+ } ;
315
+
310
316
311
317
const handleSave = ( ) : Object => {
312
318
// ------------------------------------------- change code below -------------------------------------------
313
- const actions : object [ ] = [ ] ;
319
+ dispatch ( {
320
+ type : 'UPDATE STATE USED' ,
321
+ payload : { stateUsedObj : stateUsedObj }
322
+ } )
323
+
324
+ dispatch ( {
325
+ type : 'UPDATE USE CONTEXT' ,
326
+ payload : { useContextObj : useContextObj }
327
+ } )
314
328
315
329
const styleObj : any = { } ;
316
- let updateCSS : boolean = false ;
317
- if ( displayMode !== '' ) {
318
- updateCSS = true ;
319
- styleObj . display = displayMode ;
320
- }
330
+ if ( displayMode !== '' ) styleObj . display = displayMode ;
321
331
if ( flexDir !== '' ) styleObj . flexDirection = flexDir ;
322
332
if ( flexJustify !== '' ) styleObj . justifyContent = flexJustify ;
323
333
if ( flexAlign !== '' ) styleObj . alignItems = flexAlign ;
324
334
if ( compWidth !== '' ) styleObj . width = compWidth ;
325
335
if ( compHeight !== '' ) styleObj . height = compHeight ;
326
336
if ( BGColor !== '' ) styleObj . backgroundColor = BGColor ;
337
+ dispatch ( {
338
+ type : 'UPDATE CSS' ,
339
+ payload : { style : styleObj }
340
+ } ) ;
327
341
328
342
const attributesObj : any = { } ;
329
343
if ( compText !== '' ) attributesObj . compText = compText ;
330
344
if ( compLink !== '' ) attributesObj . compLink = compLink ;
331
345
if ( cssClasses !== '' ) attributesObj . cssClasses = cssClasses ;
332
-
333
- const eventsObj : any = { } ;
334
- if ( eventAll [ 0 ] !== '' ) eventsObj [ eventAll [ 0 ] ] = eventAll [ 1 ] ;
335
-
336
- dispatch ( {
337
- type : 'UPDATE STATE USED' ,
338
- payload : { stateUsedObj : stateUsedObj }
339
- } )
340
- dispatch ( {
341
- type : 'UPDATE USE CONTEXT' ,
342
- payload : { useContextObj : useContextObj }
343
- } )
344
- dispatch ( {
345
- type : 'UPDATE CSS' ,
346
- payload : { style : styleObj }
347
- } ) ;
348
346
dispatch ( {
349
347
type : 'UPDATE ATTRIBUTES' ,
350
348
payload : { attributes : attributesObj }
351
349
} ) ;
350
+
351
+ const eventsObj : any = { } ;
352
+ if ( eventAll [ 0 ] !== '' ) eventsObj [ eventAll [ 0 ] ] = eventAll [ 1 ] ;
352
353
dispatch ( {
353
354
type : 'UPDATE EVENTS' ,
354
355
payload : { events : eventsObj }
355
356
} ) ;
356
- setEventAll ( [ '' , '' ] )
357
357
// ------------------------------------------- change code above -------------------------------------------
358
358
return styleObj ;
359
359
} ;
@@ -781,11 +781,11 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
781
781
/>
782
782
</ FormControl >
783
783
</ div > ) }
784
- { Object . keys ( currFocus . events ) . length !== 0 && ( < div className = { 'event-table' } >
784
+ { currFocus && Object . keys ( currFocus . events ) . length !== 0 && ( < div className = { 'event-table' } >
785
785
< DataGrid
786
786
rows = { eventRow }
787
787
columns = { eventColumnTabs }
788
- // pageSize={5}
788
+ pageSize = { 5 }
789
789
// editRowsModel={editRowsModel}
790
790
// className={props.isThemeLight ? classes.themeLight : classes.themeDark}
791
791
/>
0 commit comments