@@ -6,16 +6,16 @@ import {
6
6
CollapseTitle as Title ,
7
7
CopyTextButton ,
8
8
FoldedIcon ,
9
+ LeftClose ,
9
10
LeftCommon ,
10
- LeftInfoFill ,
11
- LeftInfoLine ,
11
+ LeftOpen ,
12
12
PadDiv ,
13
13
ScrollBar ,
14
14
Tooltip ,
15
15
UnfoldIcon ,
16
16
UnShow ,
17
17
} from "lowcoder-design" ;
18
- import React , { ReactNode , useCallback , useContext , useMemo , useState , useEffect } from "react" ;
18
+ import React , { ReactNode , useCallback , useContext , useMemo , useState } from "react" ;
19
19
import { hookCompCategory } from "comps/hooks/hookCompTypes" ;
20
20
import _ from "lodash" ;
21
21
import styled from "styled-components" ;
@@ -32,11 +32,6 @@ import { UICompType } from "comps/uiCompRegistry";
32
32
import { CollapseWrapper , DirectoryTreeStyle , Node } from "./styledComponents" ;
33
33
import { DataNode , EventDataNode } from "antd/lib/tree" ;
34
34
import { isAggregationApp } from "util/appUtils" ;
35
- import cloneDeep from 'lodash/cloneDeep' ;
36
- import { useDispatch } from "react-redux" ;
37
- import { useApplicationId } from "util/hooks" ;
38
- import { updateApplication } from "redux/reduxActions/applicationActions" ;
39
- import { Divider } from "antd" ;
40
35
41
36
const CollapseTitleWrapper = styled . div `
42
37
display: flex;
@@ -196,8 +191,6 @@ const CollapseView = React.memo(
196
191
197
192
interface LeftContentProps {
198
193
uiComp : InstanceType < typeof UIComp > ;
199
- checkable ?: boolean ;
200
- isDraggable ?: boolean ;
201
194
}
202
195
203
196
enum LeftTabKey {
@@ -215,8 +208,6 @@ type NodeItem = {
215
208
title : string ;
216
209
type ?: UICompType ;
217
210
children : NodeItem [ ] ;
218
- pos ?: number ;
219
- disabled ?: boolean ;
220
211
} ;
221
212
222
213
type NodeInfo = {
@@ -251,30 +242,25 @@ export const LeftContent = (props: LeftContentProps) => {
251
242
const editorState = useContext ( EditorContext ) ;
252
243
const [ expandedKeys , setExpandedKeys ] = useState < Array < React . Key > > ( [ ] ) ;
253
244
const [ showData , setShowData ] = useState < NodeInfo [ ] > ( [ ] ) ;
254
- const dispatch = useDispatch ( ) ;
255
- const applicationId = useApplicationId ( ) ;
256
- const checkable = props . checkable || false ;
257
- const isDraggable = props . isDraggable || false ;
258
245
259
246
const getTree = ( tree : CompTree , result : NodeItem [ ] , key ?: string ) => {
260
247
const { items, children } = tree ;
261
248
if ( Object . keys ( items ) . length ) {
262
249
for ( const i in items ) {
263
- const info : NodeItem = {
250
+ const info = {
264
251
title : items [ i ] . children . name . getView ( ) ,
265
252
type : items [ i ] . children . compType . getView ( ) as UICompType ,
266
253
key : i ,
267
254
children : [ ] ,
268
255
} ;
269
256
if ( key ) {
270
257
const parent = getTreeNodeByKey ( result , key ) ;
271
- info . disabled = true ;
272
258
parent ?. children . push ( info ) ;
273
259
} else {
274
260
result . push ( info ) ;
275
261
}
276
262
}
277
- // result = _.sortBy(result, [(x) => x.title]);
263
+ result = _ . sortBy ( result , [ ( x ) => x . title ] ) ;
278
264
}
279
265
if ( Object . keys ( children ) . length ) {
280
266
for ( const i in children ) {
@@ -367,7 +353,7 @@ export const LeftContent = (props: LeftContentProps) => {
367
353
setShowData ( newData ) ;
368
354
} }
369
355
>
370
- < LeftInfoLine />
356
+ < LeftOpen />
371
357
</ div >
372
358
</ Tooltip >
373
359
) : (
@@ -400,7 +386,7 @@ export const LeftContent = (props: LeftContentProps) => {
400
386
setShowData ( newData ) ;
401
387
} }
402
388
>
403
- < LeftInfoFill />
389
+ < LeftClose />
404
390
</ div >
405
391
</ Tooltip >
406
392
) ) }
@@ -422,57 +408,17 @@ export const LeftContent = (props: LeftContentProps) => {
422
408
) ;
423
409
} ;
424
410
425
- const [ componentTreeData , setComponentTreeData ] = useState < NodeItem [ ] > ( [ ] ) ;
426
- const [ modalsTreeData , setModalsTreeData ] = useState < NodeItem [ ] > ( [ ] ) ;
427
-
428
- useEffect ( ( ) => {
429
- const compData = getTreeUIData ( TreeUIKey . Components ) ;
430
- setComponentTreeData ( compData ) ;
431
- } , [ editorState ] ) ;
432
-
433
- useEffect ( ( ) => {
434
- const modalsData = getTreeUIData ( TreeUIKey . Modals ) ;
435
- setModalsTreeData ( modalsData ) ;
436
- } , [ editorState ] ) ;
437
-
438
- const getTreeUIData = ( type : TreeUIKey ) => {
439
- const tree =
440
- type === TreeUIKey . Components
441
- ? editorState . getUIComp ( ) . getTree ( )
442
- : editorState . getHooksComp ( ) . getUITree ( ) ;
443
- const explorerData : NodeItem [ ] = getTree ( tree , [ ] ) ;
444
- // TODO: handle sorting inside modals/drawers
445
- if ( type === TreeUIKey . Modals ) return explorerData ;
446
-
447
- const dsl = editorState . rootComp . toJsonValue ( ) ;
448
- explorerData . forEach ( data => {
449
- data [ 'pos' ] = dsl . ui . layout [ data . key ] . pos ;
450
- } )
451
- explorerData . sort ( ( a , b ) => {
452
- const aPos = a ?. pos || 0 ;
453
- const bPos = b ?. pos || 0 ;
454
- if ( aPos < bPos ) return - 1 ;
455
- if ( aPos > bPos ) return 1 ;
456
- return 0 ;
457
- } ) ;
458
- return explorerData ;
459
- }
460
-
461
-
462
411
const getTreeUI = ( type : TreeUIKey ) => {
463
- // here the components get sorted by name
464
- // TODO: sort by category
465
- // TODO: sort by Types etc.
466
412
const uiCompInfos = _ . sortBy ( editorState . uiCompInfoList ( ) , [ ( x ) => x . name ] ) ;
467
- /* const tree =
413
+ const tree =
468
414
type === TreeUIKey . Components
469
415
? editorState . getUIComp ( ) . getTree ( )
470
416
: editorState . getHooksComp ( ) . getUITree ( ) ;
471
- const explorerData: NodeItem[] = getTree(tree, []); */
417
+ const explorerData : NodeItem [ ] = getTree ( tree , [ ] ) ;
472
418
let selectedKeys = [ ] ;
473
419
if ( editorState . selectedCompNames . size === 1 ) {
474
420
const key = Object . keys ( editorState . selectedComps ( ) ) [ 0 ] ;
475
- const parentKeys = getParentNodeKeysByKey ( type === TreeUIKey . Components ? componentTreeData : modalsTreeData , key ) ;
421
+ const parentKeys = getParentNodeKeysByKey ( explorerData , key ) ;
476
422
if ( parentKeys && parentKeys . length ) {
477
423
let needSet = false ;
478
424
parentKeys . forEach ( ( key ) => {
@@ -486,38 +432,38 @@ export const LeftContent = (props: LeftContentProps) => {
486
432
}
487
433
488
434
return (
489
- < > < DirectoryTreeStyle
490
- treeData = { type === TreeUIKey . Components ? componentTreeData : modalsTreeData }
491
- icon = { ( props : any ) => props . type && (
492
- < div style = { { margin : '3px 0 0 -3px' } } > { /* Adjust the margin as needed */ }
493
- { CompStateIcon [ props . type as UICompType ] || < LeftCommon /> }
494
- </ div >
495
- ) }
496
- switcherIcon = { ( props : any ) => props . expanded ? < FoldedIcon /> : < UnfoldIcon /> }
435
+ < DirectoryTreeStyle
436
+ treeData = { explorerData }
437
+ // icon={(props: NodeItem) => props.type && (CompStateIcon[props.type] || <LeftCommon />)}
438
+ icon = { ( props : any ) => props . type && ( CompStateIcon [ props . type as UICompType ] || < LeftCommon /> ) }
439
+ // switcherIcon={({ expanded }: { expanded: boolean }) =>
440
+ // expanded ? <FoldedIcon /> : <UnfoldIcon />
441
+ // }
442
+ switcherIcon = { ( props : any ) =>
443
+ props . expanded ? < FoldedIcon /> : < UnfoldIcon />
444
+ }
497
445
expandedKeys = { expandedKeys }
498
446
onExpand = { ( keys ) => setExpandedKeys ( keys ) }
499
447
onClick = { ( e , node ) => handleNodeClick ( e , node , uiCompInfos ) }
500
448
selectedKeys = { selectedKeys }
501
- titleRender = { ( nodeData ) => getTreeNode ( nodeData as NodeItem , uiCompInfos ) } />
502
- < Divider />
503
- < div > </ div >
504
- </ >
449
+ titleRender = { ( nodeData ) => getTreeNode ( nodeData as NodeItem , uiCompInfos ) }
450
+ />
505
451
) ;
506
452
} ;
507
453
508
454
const uiCollapse = useMemo ( ( ) => {
509
455
if ( isAggregationApp ( editorState . getAppType ( ) ) ) {
510
456
return ;
511
457
}
512
- return getTreeUI ( TreeUIKey . Components ) ; // Pass componentTreeData
513
- } , [ editorState , uiCollapseClick , expandedKeys , showData , componentTreeData ] ) ;
514
-
458
+ return getTreeUI ( TreeUIKey . Components ) ;
459
+ } , [ editorState , uiCollapseClick , expandedKeys , showData ] ) ;
460
+
515
461
const modalsCollapse = useMemo ( ( ) => {
516
462
if ( isAggregationApp ( editorState . getAppType ( ) ) ) {
517
463
return ;
518
464
}
519
- return getTreeUI ( TreeUIKey . Modals ) ; // Pass modalsTreeData
520
- } , [ editorState , uiCollapseClick , expandedKeys , showData , modalsTreeData ] ) ;
465
+ return getTreeUI ( TreeUIKey . Modals ) ;
466
+ } , [ editorState , uiCollapseClick , expandedKeys , showData ] ) ;
521
467
522
468
const bottomResCollapse = useMemo ( ( ) => {
523
469
return editorState
@@ -551,7 +497,6 @@ export const LeftContent = (props: LeftContentProps) => {
551
497
} , [ editorState ] ) ;
552
498
553
499
const moduleLayoutComp = uiComp . getModuleLayoutComp ( ) ;
554
-
555
500
const stateContent = (
556
501
< ScrollBar >
557
502
< div style = { { paddingBottom : 80 } } >
@@ -604,4 +549,4 @@ export const LeftContent = (props: LeftContentProps) => {
604
549
</ LeftContentTabs >
605
550
</ LeftContentWrapper >
606
551
) ;
607
- } ;
552
+ } ;
0 commit comments