@@ -13,13 +13,13 @@ import {
13
13
PointIcon ,
14
14
PopupCard ,
15
15
UnfoldIcon ,
16
- FileFolderIcon
16
+ FileFolderIcon , messageInstance , CustomModal
17
17
} from "lowcoder-design" ;
18
- import { trans } from "i18n" ;
18
+ import { trans , transToNode } from "i18n" ;
19
19
import { draggingUtils } from "layout/draggingUtils" ;
20
- import { CSSProperties , useContext , useEffect , useState } from "react" ;
20
+ import React , { CSSProperties , useContext , useEffect , useState } from "react" ;
21
21
import { useDispatch , useSelector } from "react-redux" ;
22
- import { fetchAllModules } from "redux/reduxActions/applicationActions" ;
22
+ import { fetchAllModules , recycleApplication } from "redux/reduxActions/applicationActions" ;
23
23
import styled from "styled-components" ;
24
24
import CreateAppButton from "components/CreateAppButton" ;
25
25
import { TransparentImg } from "util/commonUtils" ;
@@ -31,12 +31,20 @@ import {showAppSnapshotSelector} from "@lowcoder-ee/redux/selectors/appSnapshotS
31
31
import { DraggableTreeNode , DraggableTreeNodeItemRenderProps } from "@lowcoder-ee/components/DraggableTree/types" ;
32
32
import RefTreeComp from "@lowcoder-ee/comps/comps/refTreeComp" ;
33
33
import { EmptyContent } from "components/EmptyContent" ;
34
+ import { moveToFolder } from "@lowcoder-ee/redux/reduxActions/folderActions" ;
35
+ import { HomeResInfo } from "@lowcoder-ee/util/homeResUtils" ;
34
36
const ItemWrapper = styled . div `
35
37
display: flex;
36
38
flex-direction: row;
37
39
&:last-child {
38
40
margin-bottom: 0;
39
41
}
42
+ .module-container {
43
+ //width: 70px;
44
+ display: flex;
45
+ justify-content: space-between;
46
+ text-align: left;
47
+ }
40
48
.module-icon {
41
49
42
50
display: flex;
@@ -52,6 +60,8 @@ const ItemWrapper = styled.div`
52
60
overflow: hidden;
53
61
}
54
62
.module-name {
63
+ //flex-grow: 1;
64
+ //margin-right: 8px;
55
65
line-height: 1.5;
56
66
font-size: 13px;
57
67
overflow: hidden;
@@ -77,8 +87,8 @@ function buildTree(elementRecord: Record<string, Array<ApplicationMeta | FolderM
77
87
const elements = elementRecord [ "" ] ;
78
88
const elementMap : Record < string , NodeType > = { } ;
79
89
let rootNode : NodeType = {
80
- name : "" ,
81
- id : "" ,
90
+ name : "root " ,
91
+ id : "root " ,
82
92
isFolder : true ,
83
93
children : [ ] ,
84
94
rename : val => rootNode . name = val ,
@@ -99,7 +109,7 @@ function buildTree(elementRecord: Record<string, Array<ApplicationMeta | FolderM
99
109
100
110
// Process subapplications inside the folder
101
111
for ( const app of element . subApplications || [ ] ) {
102
- if ( app . applicationType === AppTypeEnum . Module ) {
112
+ if ( ! ! app && app . applicationType === AppTypeEnum . Module ) {
103
113
const appNode : NodeType = {
104
114
name : app . name ,
105
115
id : app . applicationId ,
@@ -142,15 +152,15 @@ function buildTree(elementRecord: Record<string, Array<ApplicationMeta | FolderM
142
152
rootNode . children . push ( elementMap [ element . applicationId ] ) ;
143
153
}
144
154
}
145
- console . log ( rootNode . children . sort ( ( a , b ) => {
155
+ rootNode . children . sort ( ( a , b ) => {
146
156
if ( a . isFolder && ! b . isFolder ) {
147
157
return - 1 ; // a is a isFolder and should come first
148
158
} else if ( ! a . isFolder && b . isFolder ) {
149
159
return 1 ; // b is a folder and should come first
150
160
} else {
151
161
return 0 ; // both are folders or both are not, keep original order
152
162
}
153
- } ) ) ;
163
+ } ) ;
154
164
return rootNode ;
155
165
}
156
166
@@ -168,6 +178,7 @@ function ModuleItem(props: ModuleItemProps) {
168
178
draggable
169
179
onDragStart = { ( e ) => {
170
180
console . log ( meta ) ;
181
+ e . stopPropagation ( ) ;
171
182
e . dataTransfer . setData ( "compType" , compType ) ;
172
183
e . dataTransfer . setDragImage ( TransparentImg , 0 , 0 ) ;
173
184
draggingUtils . setData ( "compType" , compType ) ;
@@ -183,11 +194,13 @@ function ModuleItem(props: ModuleItemProps) {
183
194
props . onDrag ( compType ) ;
184
195
} }
185
196
>
186
- < div className = "module-icon" >
187
- < ModuleDocIcon width = "19px" height = "19px" />
188
- </ div >
189
- < div className = "module-content" >
190
- < div className = "module-name" > { props . meta . name } </ div >
197
+ < div className = "module-container" >
198
+ < div className = "module-icon" >
199
+ < ModuleDocIcon width = "19px" height = "19px" />
200
+ </ div >
201
+ < div className = "module-content" >
202
+ < div className = "module-name" > { props . meta . name } </ div >
203
+ </ div >
191
204
</ div >
192
205
</ ItemWrapper >
193
206
) ;
@@ -372,28 +385,29 @@ function ModuleSidebarItem(props: ModuleSidebarItemProps) {
372
385
< ColumnDiv onClick = { handleClickItem } $color = { isSelected } $isOverlay = { isOverlay } >
373
386
< HighlightBorder $active = { isOver && isFolder } $level = { level } $foldable = { isFolder } >
374
387
{ isFolder && < FoldIconBtn > { ! isFolded ? < FoldedIcon /> : < UnfoldIcon /> } </ FoldIconBtn > }
375
- { isFolder ?
376
- < >
377
- < FileFolderIcon />
378
- < div style = { { flexGrow : 1 , marginRight : "8px" , width : "calc(100% - 62px)" } } >
379
- < EditText
380
- text = { name }
381
- forceClickIcon = { isFolder }
382
- disabled = { ! isSelected || readOnly || isOverlay }
383
- onFinish = { handleFinishRename }
384
- onChange = { handleNameChange }
385
- onEditStateChange = { ( editing ) => setEditing ( editing ) }
386
- />
387
- < PopupCard
388
- editorFocus = { ! ! error && editing }
389
- title = { error ? trans ( "error" ) : "" }
390
- content = { error }
391
- hasError = { ! ! error }
392
- />
393
- </ div > </ > : < ModuleItem onDrag = { onDrag } key = { id } meta = { resComp . module ! } />
394
- }
388
+ { isFolder ?
389
+ < >
390
+ < FileFolderIcon />
391
+ < div style = { { flexGrow : 1 , marginRight : "8px" , width : "calc(100% - 62px)" } } >
392
+ < EditText
393
+ text = { name }
394
+ forceClickIcon = { isFolder }
395
+ disabled = { ! isSelected || readOnly || isOverlay }
396
+ onFinish = { handleFinishRename }
397
+ onChange = { handleNameChange }
398
+ onEditStateChange = { ( editing ) => setEditing ( editing ) }
399
+ />
400
+ < PopupCard
401
+ editorFocus = { ! ! error && editing }
402
+ title = { error ? trans ( "error" ) : "" }
403
+ content = { error }
404
+ hasError = { ! ! error }
405
+ />
406
+ </ div >
407
+ </ > :
408
+ < ModuleItem onDrag = { onDrag } key = { id } meta = { resComp . module ! } /> }
395
409
{ ! readOnly && ! isOverlay && (
396
- < EditPopover copy = { ! isFolder ? onCopy : undefined } del = { onDelete } >
410
+ < EditPopover copy = { ! isFolder ? onCopy : undefined } del = { ( ) => onDelete ( ) } >
397
411
< Icon tabIndex = { - 1 } />
398
412
</ EditPopover >
399
413
) }
@@ -404,9 +418,10 @@ function ModuleSidebarItem(props: ModuleSidebarItemProps) {
404
418
405
419
export default function ModulePanel ( ) {
406
420
const dispatch = useDispatch ( ) ;
407
- const elements = useSelector ( folderElementsSelector ) ;
421
+ let elements = useSelector ( folderElementsSelector ) ;
422
+ // const reload = () => elements = useSelector(folderElementsSelector);
408
423
const { onDrag, searchValue } = useContext ( RightContext ) ;
409
-
424
+ const [ deleteFlag , setDeleteFlag ] = useState ( false ) ;
410
425
useEffect ( ( ) => {
411
426
dispatch ( fetchAllModules ( { } ) ) ;
412
427
} , [ dispatch ] ) ;
@@ -433,9 +448,12 @@ export default function ModulePanel() {
433
448
}
434
449
435
450
const getById = ( id : string ) : NodeType | undefined => getByIdFromNode ( tree , id ) ;
451
+ let popedItem : DraggableTreeNode < any > [ ] = [ ] ;
452
+ let popedItemSourceId = ""
436
453
const convertRefTree = ( treeNode : NodeType ) => {
437
454
const moduleResComp = getById ( treeNode . id ) ;
438
455
const currentNodeType = moduleResComp ?. isFolder ;
456
+
439
457
const childrenItems = treeNode . children
440
458
. map ( ( i ) => convertRefTree ( i as NodeType ) )
441
459
. filter ( ( i ) : i is DraggableTreeNode < NodeType > => ! ! i ) ;
@@ -473,21 +491,73 @@ export default function ModulePanel() {
473
491
data : moduleResComp ,
474
492
addSubItem ( value ) {
475
493
console . log ( "addSubItem" , node . id , value , node ) ;
494
+ // node.items.push(value)
476
495
// const pushAction = node.items.pushAction({ value: value.id() });
477
496
// node.items.dispatch(pushAction);
478
497
} ,
479
498
deleteItem ( index ) {
480
- console . log ( "deleteItem" , node . id , index ) ;
499
+ console . log ( "deleteItem" , node , index ) ;
500
+ popedItemSourceId = node . id ! ;
501
+ if ( ! deleteFlag ) {
502
+ popedItem = node . items . splice ( index , 1 ) ;
503
+ console . log ( popedItem ) ;
504
+ }
505
+
481
506
// const deleteAction = node.children.items.deleteAction(index);
482
507
// node.children.items.dispatch(deleteAction);
483
508
} ,
484
509
addItem ( value ) {
485
- console . log ( "addItem" , node . id , value ) ;
510
+ console . log ( "additem" , "value" , value , node ) ;
511
+ node . items . push ( popedItem [ 0 ] )
512
+ popedItem = [ ] ;
486
513
// const pushAction = node.children.items.pushAction({ value: value.id() });
487
514
// node.children.items.dispatch(pushAction);
515
+ // if (popedItem[0]){
516
+ // dispatch(
517
+ // moveToFolder(
518
+ // {
519
+ // sourceFolderId: popedItemSourceId,
520
+ // sourceId: popedItem[0].id!,
521
+ // folderId: node.id!,
522
+ // moveFlag: true
523
+ // },
524
+ // () => {
525
+ //
526
+ //
527
+ // },
528
+ // () => {}
529
+ // )
530
+ // );
531
+ // node.items.push(popedItem[0]);
532
+ // popedItemSourceId = "";
533
+ // popedItem = [];
534
+ // }
488
535
} ,
489
536
moveItem ( from , to ) {
490
- console . log ( "node" , node ) ;
537
+ console . log ( "moveItem" , node , from , to , node . id ) ;
538
+ if ( popedItem [ 0 ] ) {
539
+ node . items . push ( popedItem [ 0 ] ) ;
540
+
541
+ dispatch (
542
+ moveToFolder (
543
+ {
544
+ sourceFolderId : popedItemSourceId ,
545
+ sourceId : popedItem [ 0 ] . id ! ,
546
+ folderId : node . id ! ,
547
+ moveFlag : true
548
+ } ,
549
+ ( ) => {
550
+
551
+
552
+ } ,
553
+ ( ) => { }
554
+ )
555
+ ) ;
556
+ popedItemSourceId = "" ;
557
+ popedItem = [ ] ;
558
+
559
+ }
560
+ // popedItem = [];
491
561
// const moveAction = node.children.items.arrayMoveAction(from, to);
492
562
// node.children.items.dispatch(moveAction);
493
563
} ,
@@ -505,18 +575,51 @@ export default function ModulePanel() {
505
575
} ;
506
576
507
577
const node = convertRefTree ( tree ) ;
508
-
578
+ console . log ( "started!!!!" , node )
509
579
function onCopy ( type : boolean , id : string ) {
510
580
console . log ( "onCopy" , type , id ) ;
511
581
}
512
582
513
583
function onSelect ( type : boolean , id : string , meta : any ) {
514
584
console . log ( "onSelect" , type , id , meta )
515
- return < ModuleItem onDrag = { onDrag } key = { id } meta = { meta } />
585
+ // return <ModuleItem onDrag={onDrag} key={id} meta={meta} />
516
586
}
517
587
518
588
function onDelete ( type : boolean , id : string ) {
519
- console . log ( "onDelete" , type , id ) ;
589
+ setDeleteFlag ( true ) ;
590
+ console . log ( "1111111111111111111111111" , type , id , node ) ;
591
+ if ( type ) {
592
+ alert ( 1 ) ;
593
+ }
594
+ else {
595
+ CustomModal . confirm ( {
596
+ title : trans ( "home.moveToTrash" ) ,
597
+ content : transToNode ( "home.moveToTrashSubTitle" , {
598
+ type : "" ,
599
+ name : "This file" ,
600
+ } ) ,
601
+ onConfirm : ( ) => {
602
+ dispatch (
603
+ recycleApplication (
604
+ {
605
+ applicationId : id ,
606
+ folderId : popedItemSourceId ,
607
+ } ,
608
+ ( ) => {
609
+ messageInstance . success ( trans ( "success" ) )
610
+
611
+ } ,
612
+ ( ) => {
613
+ }
614
+ )
615
+ )
616
+ setDeleteFlag ( false )
617
+ } ,
618
+ confirmBtnType : "delete" ,
619
+ okText : trans ( "home.moveToTrash" ) ,
620
+ onCancel : ( ) => setDeleteFlag ( false )
621
+ } ) ;
622
+ }
520
623
return true ;
521
624
}
522
625
0 commit comments