1
1
import CreateAppButton from "components/CreateAppButton" ;
2
2
import { EmptyContent } from "components/EmptyContent" ;
3
- import { ApplicationMeta , AppTypeEnum } from "constants/applicationConstants" ;
3
+ import { ApplicationMeta , AppTypeEnum , FolderMeta } from "constants/applicationConstants" ;
4
4
import { APPLICATION_VIEW_URL } from "constants/routesURL" ;
5
5
import {
6
6
ActiveTextColor ,
7
7
BorderActiveShadowColor ,
8
8
BorderColor ,
9
9
GreyTextColor ,
10
10
} from "constants/style" ;
11
- import { ModuleDocIcon } from "lowcoder-design" ;
11
+ import { FolderIcon , ModuleDocIcon } from "lowcoder-design" ;
12
12
import { trans } from "i18n" ;
13
13
import { draggingUtils } from "layout/draggingUtils" ;
14
- import { useContext , useEffect } from "react" ;
14
+ import { useContext , useEffect , useState } from "react" ;
15
15
import { useDispatch , useSelector } from "react-redux" ;
16
16
import { fetchAllModules } from "redux/reduxActions/applicationActions" ;
17
17
import styled from "styled-components" ;
@@ -21,6 +21,7 @@ import { formatTimestamp } from "util/dateTimeUtils";
21
21
import { RightContext } from "./rightContext" ;
22
22
import { modulesSelector } from "../../../redux/selectors/applicationSelector" ;
23
23
import { ComListTitle , ExtensionContentWrapper } from "./styledComponent" ;
24
+ import { foldersSelector } from "@lowcoder-ee/redux/selectors/folderSelector" ;
24
25
25
26
const ItemWrapper = styled . div `
26
27
display: flex;
@@ -72,11 +73,62 @@ const ItemWrapper = styled.div`
72
73
}
73
74
` ;
74
75
76
+ const FolderWrapper = styled . div `
77
+ display: flex;
78
+ flex-direction: row;
79
+ margin-bottom: 12px;
80
+ &:last-child {
81
+ margin-bottom: 0;
82
+ }
83
+ &:hover {
84
+ box-shadow: 0 0 5px 0 rgba(49, 94, 251, 0.15);
85
+ border-color: ${ BorderActiveShadowColor } ;
86
+ cursor: pointer;
87
+ transform: scale(1.03);
88
+ .folder-name {
89
+ color: ${ ActiveTextColor } ;
90
+ }
91
+ }
92
+ .folder-icon {
93
+ transition: all 200ms linear;
94
+ margin-right: 8px;
95
+ width: 40px;
96
+ height: 40px;
97
+ display: flex;
98
+ justify-content: center;
99
+ align-items: center;
100
+ border-radius: 4px;
101
+ }
102
+ .folder-content {
103
+ flex: 1;
104
+ display: flex;
105
+ flex-direction: column;
106
+ justify-content: space-around;
107
+ overflow: hidden;
108
+ }
109
+ .folder-name {
110
+ line-height: 1.5;
111
+ font-size: 13px;
112
+ overflow: hidden;
113
+ white-space: nowrap;
114
+ text-overflow: ellipsis;
115
+ }
116
+ .folder-desc {
117
+ line-height: 1.5;
118
+ font-size: 12px;
119
+ color: ${ GreyTextColor } ;
120
+ }
121
+ ` ;
122
+
75
123
interface ModuleItemProps {
76
124
meta : ApplicationMeta ;
77
125
onDrag : ( type : string ) => void ;
78
126
}
79
127
128
+ interface FolderItemProps {
129
+ meta : FolderMeta ;
130
+ }
131
+
80
132
function ModuleItem ( props : ModuleItemProps ) {
81
133
const compType = "module" ;
82
134
const { meta } = props ;
@@ -113,23 +165,74 @@ function ModuleItem(props: ModuleItemProps) {
113
165
export default function ModulePanel ( ) {
114
166
const dispatch = useDispatch ( ) ;
115
167
const modules = useSelector ( modulesSelector ) ;
168
+ const folders = useSelector ( foldersSelector ) ;
116
169
const { onDrag, searchValue } = useContext ( RightContext ) ;
117
170
const { applicationId } = useContext ( ExternalEditorContext ) ;
171
+ const [ isSubItems , setIsSubItems ] = useState ( false ) ;
172
+ // const [subApplications : ApplicationMeta[], setSubApplications] = useState([]);
173
+ const [ subModuleApp , setSubModuleApp ] = useState < ApplicationMeta [ ] > ( [ ] ) ;
174
+
175
+ const appArray = ( ) => {
176
+ const appIdArray : any [ ] = [ ] ;
177
+ folders . map ( i => ( i . subApplications ?. map ( p => ( appIdArray . push ( p . applicationId ) ) ) ) )
178
+ return appIdArray ;
179
+ }
180
+ function FolderItem ( props : FolderItemProps ) {
181
+ const { meta } = props ;
182
+
183
+ const handleClick = ( ) => {
184
+ setIsSubItems ( true ) ;
185
+ setSubModuleApp ( meta . subApplications || [ ] ) ;
186
+ console . log ( meta . subApplications ) ;
187
+ } ;
188
+ return (
189
+ < FolderWrapper onClick = { handleClick } >
190
+ < div className = "folder-icon" >
191
+ < FolderIcon width = "35px" />
192
+ </ div >
193
+ < div className = "folder-content" >
194
+ < div className = "folder-name" > { meta . name } </ div >
195
+ </ div >
196
+ </ FolderWrapper >
197
+ ) ;
198
+ }
199
+
200
+
201
+ const appIdArray = appArray ( ) ;
118
202
119
203
useEffect ( ( ) => {
120
204
dispatch ( fetchAllModules ( { } ) ) ;
121
205
} , [ dispatch ] ) ;
122
206
123
207
const filteredModules = modules . filter ( ( i ) => {
208
+ if ( appIdArray . includes ( i . applicationId ) )
209
+ return false ;
124
210
if ( i . applicationId === applicationId || i . applicationType !== AppTypeEnum . Module ) {
125
211
return false ;
126
212
}
127
213
return i . name ?. toLowerCase ( ) ?. includes ( searchValue . trim ( ) ?. toLowerCase ( ) ) || ! searchValue ?. trim ( ) ;
128
214
} ) ;
129
215
216
+ const subModules = ( apps : ApplicationMeta [ ] | undefined ) => apps ?. filter ( ( i ) => {
217
+ if ( i . applicationId === applicationId || i . applicationType !== AppTypeEnum . Module ) {
218
+ return false ;
219
+ }
220
+ return i . name ?. toLowerCase ( ) ?. includes ( searchValue . trim ( ) ?. toLowerCase ( ) ) || ! searchValue ?. trim ( ) ;
221
+ } ) ;
222
+
223
+
224
+ // @ts -ignore
225
+ const subItems = subModules ( subModuleApp ) . map ( ( i ) => (
226
+ < ModuleItem onDrag = { onDrag } key = { i . applicationId } meta = { i } />
227
+ ) ) ;
228
+
130
229
const items = filteredModules . map ( ( i ) => (
131
230
< ModuleItem onDrag = { onDrag } key = { i . applicationId } meta = { i } />
132
231
) ) ;
232
+
233
+ const folderItems = folders . map ( ( i ) => {
234
+ return < FolderItem key = { i . folderId } meta = { i } />
235
+ } ) ;
133
236
const empty = (
134
237
< EmptyContent
135
238
text = {
@@ -149,8 +252,28 @@ export default function ModulePanel() {
149
252
) ;
150
253
return (
151
254
< >
152
- < ComListTitle > { trans ( "rightPanel.moduleListTitle" ) } </ ComListTitle >
153
- < ExtensionContentWrapper > { items . length > 0 ? items : empty } </ ExtensionContentWrapper >
255
+ {
256
+ isSubItems ? < >
257
+ < ComListTitle > { trans ( "rightPanel.moduleListTitle" ) } </ ComListTitle >
258
+ < FolderWrapper onClick = { ( ) => ( setIsSubItems ( false ) ) } >
259
+ < div className = "folder-icon" >
260
+ < FolderIcon width = "35px" />
261
+ </ div >
262
+ < div className = "folder-content" >
263
+ < div className = "folder-name" > . . .</ div >
264
+ </ div >
265
+ </ FolderWrapper >
266
+ < ExtensionContentWrapper > { subItems . length > 0 ? subItems : null } </ ExtensionContentWrapper >
267
+ </ > :
268
+ < ExtensionContentWrapper >
269
+ { folderItems . length > 0 ? < >
270
+ < ComListTitle > { trans ( "rightPanel.folderListTitle" ) } </ ComListTitle >
271
+ { folderItems }
272
+ </ > : null }
273
+ < ComListTitle > { trans ( "rightPanel.moduleListTitle" ) } </ ComListTitle >
274
+ { items . length > 0 ? items : empty }
275
+ </ ExtensionContentWrapper >
276
+ }
154
277
</ >
155
278
) ;
156
279
}
0 commit comments