@@ -33,7 +33,7 @@ import cloneDeep from 'lodash/cloneDeep';
33
33
import { useDispatch } from "react-redux" ;
34
34
import { useApplicationId } from "util/hooks" ;
35
35
import { updateApplication } from "redux/reduxActions/applicationActions" ;
36
- import { Button , Divider , Dropdown , Flex , Input , MenuProps , Space } from "antd" ;
36
+ import { Button , Divider , Dropdown , Flex , Input , Menu , MenuProps , Space } from "antd" ;
37
37
import { Switch } from "antd" ;
38
38
import {
39
39
saveCollisionStatus ,
@@ -223,19 +223,7 @@ export const LeftLayersContent = (props: LeftLayersContentProps) => {
223
223
pos : index ,
224
224
} ;
225
225
} )
226
-
227
- dispatch (
228
- updateApplication ( {
229
- applicationId : applicationId ,
230
- editingApplicationDSL : {
231
- ...dsl ,
232
- ui : {
233
- ...dsl . ui ,
234
- layout,
235
- }
236
- } as object ,
237
- } )
238
- ) ;
226
+
239
227
editorState . rootComp . children . ui . dispatchChangeValueAction ( {
240
228
...dsl . ui ,
241
229
layout,
@@ -292,30 +280,32 @@ export const LeftLayersContent = (props: LeftLayersContentProps) => {
292
280
return checkedKeys ;
293
281
}
294
282
283
+ useEffect ( ( ) => {
284
+ console . log ( 'onChange' , actionValue ) ;
285
+ } , [ actionValue ] )
286
+
295
287
const getActionValue = ( ) => {
296
288
return actionValue ;
297
289
}
298
290
299
- const handleComponentsActions = ( actionType : string ) => {
291
+ const handleComponentsActions = useCallback ( ( actionType : string ) => {
292
+ const value = getActionValue ( ) ;
300
293
for ( let key of getCheckedKeys ( ) ) {
301
294
const node = getTreeNodeByKey ( componentTreeData , key ) ;
302
295
const comp = editorState . getUICompByName ( node . title ) ;
303
- if ( comp != undefined ) {
304
- if ( actionType === "hidden" ) {
305
- comp . children . comp . dispatchChangeValueAction ( { hidden : getActionValue ( ) } ) ;
306
- }
307
- else if ( actionType === "disable" ) {
308
- comp . children . comp . dispatchChangeValueAction ( { disabled : getActionValue ( ) } ) ;
309
- }
310
- else if ( actionType === "background" ) {
311
- comp . children . comp . dispatchChangeValueAction ( { BackgroundColor : getActionValue ( ) } ) ;
296
+ if ( comp ) {
297
+ const { children } = comp . children . comp
298
+ const types = actionType . split ( '.' ) ;
299
+
300
+ if ( types . length === 1 ) { // e.g hidden, disabled
301
+ children [ types [ 0 ] ] ?. dispatchChangeValueAction ( value ) ;
312
302
}
313
- else {
314
- comp . children . comp . dispatchChangeValueAction ( { actionType : getActionValue ( ) } ) ;
303
+ else if ( types . length === 2 ) { // nested object e.g. style.background
304
+ children [ types [ 0 ] ] [ types [ 1 ] ] ?. dispatchChangeValueAction ( value ) ;
315
305
}
316
306
}
317
307
}
318
- }
308
+ } , [ getActionValue , getCheckedKeys ] ) ;
319
309
320
310
/*
321
311
@@ -331,18 +321,15 @@ export const LeftLayersContent = (props: LeftLayersContentProps) => {
331
321
const layerActions : ItemType [ ] = [
332
322
{
333
323
label : 'Hide Component' ,
334
- key : 'hide' ,
335
- onClick : ( ) => handleComponentsActions ( "hidden" ) ,
324
+ key : 'hidden' ,
336
325
} ,
337
326
{
338
327
label : 'Disable Component' ,
339
- key : 'background' ,
340
- onClick : ( ) => handleComponentsActions ( "disable" ) ,
328
+ key : 'disable' ,
341
329
} ,
342
330
{
343
331
label : 'Component Background' ,
344
- key : '3' ,
345
- onClick : ( ) => handleComponentsActions ( "background" ) ,
332
+ key : 'style.background' ,
346
333
} ,
347
334
{
348
335
label : 'Unlock' ,
@@ -396,7 +383,14 @@ export const LeftLayersContent = (props: LeftLayersContentProps) => {
396
383
{ trans ( "leftPanel.selectedComponents" ) } < br />
397
384
{ trans ( "leftPanel.displayComponents" ) }
398
385
< Input placeholder = "Action Value" onChange = { handleActionValueChange } />
399
- < CustomDropdown menu = { { items : layerActions } } >
386
+ < CustomDropdown
387
+ dropdownRender = { ( ) => (
388
+ < Menu
389
+ items = { layerActions }
390
+ onClick = { ( { key} ) => handleComponentsActions ( key ) }
391
+ />
392
+ ) }
393
+ >
400
394
< Button size = { "small" } >
401
395
< Space >
402
396
Action
0 commit comments