1
1
import styled from "styled-components" ;
2
2
import { EditPopover , PointIcon , Search , TacoButton } from "lowcoder-design" ;
3
- import React , { useState } from "react" ;
3
+ import React , { useEffect , useState } from "react" ;
4
4
import { useDispatch , useSelector } from "react-redux" ;
5
5
import { getDataSource , getDataSourceLoading , getDataSourceTypesMap } from "../../redux/selectors/datasourceSelectors" ;
6
6
import { deleteDatasource } from "../../redux/reduxActions/datasourceActions" ;
@@ -17,6 +17,10 @@ import { DatasourcePermissionDialog } from "../../components/PermissionDialog/Da
17
17
import DataSourceIcon from "components/DataSourceIcon" ;
18
18
import { Helmet } from "react-helmet" ;
19
19
import LoadingOutlined from "@ant-design/icons/LoadingOutlined" ;
20
+ import PaginationComp from "@lowcoder-ee/util/pagination/Pagination" ;
21
+ import { DatasourceInfo } from "@lowcoder-ee/api/datasourceApi" ;
22
+ import { fetchDatasourcePagination } from "@lowcoder-ee/util/pagination/axios" ;
23
+ import { getUser } from "@lowcoder-ee/redux/selectors/usersSelectors" ;
20
24
21
25
const DatasourceWrapper = styled . div `
22
26
display: flex;
@@ -103,11 +107,41 @@ const StyledTable = styled(Table)`
103
107
export const DatasourceList = ( ) => {
104
108
const dispatch = useDispatch ( ) ;
105
109
const [ searchValue , setSearchValue ] = useState ( "" ) ;
110
+ const [ searchValues , setSearchValues ] = useState ( "" ) ;
106
111
const [ isCreateFormShow , showCreateForm ] = useState ( false ) ;
107
112
const [ shareDatasourceId , setShareDatasourceId ] = useState < string | undefined > ( undefined ) ;
108
113
const datasource = useSelector ( getDataSource ) ;
114
+ const currentUser = useSelector ( getUser ) ;
115
+ const orgId = currentUser . currentOrgId ;
109
116
const datasourceLoading = useSelector ( getDataSourceLoading ) ;
110
117
const plugins = useSelector ( getDataSourceTypesMap ) ;
118
+ interface ElementsState {
119
+ elements : DatasourceInfo [ ] ;
120
+ total : number ;
121
+ }
122
+ console . log ( datasource ) ;
123
+
124
+ const [ elements , setElements ] = useState < ElementsState > ( { elements : [ ] , total : 0 } ) ;
125
+ const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
126
+ const [ pageSize , setPageSize ] = useState ( 10 ) ;
127
+
128
+ useEffect ( ( ) => {
129
+ fetchDatasourcePagination (
130
+ {
131
+ orgId : orgId ,
132
+ pageNum : currentPage ,
133
+ pageSize : pageSize ,
134
+ name : searchValues
135
+ }
136
+ ) . then ( result => {
137
+ if ( result . success ) {
138
+ setElements ( { elements : result . data || [ ] , total : result . total || 1 } )
139
+ }
140
+ else
141
+ console . error ( "ERROR: fetchFolderElements" , result . error )
142
+ } )
143
+ } , [ currentPage , pageSize , searchValues ]
144
+ )
111
145
112
146
return (
113
147
< >
@@ -140,6 +174,7 @@ export const DatasourceList = () => {
140
174
placeholder = { trans ( "search" ) }
141
175
value = { searchValue }
142
176
onChange = { ( e ) => setSearchValue ( e . target . value ) }
177
+ onEnterPress = { ( value ) => setSearchValues ( value ) }
143
178
style = { { width : "192px" , height : "32px" , margin : "0 12px 0 0" } } />
144
179
< AddBtn buttonType = { "primary" } onClick = { ( ) => showCreateForm ( true ) } >
145
180
{ trans ( "home.newDatasource" ) }
@@ -267,19 +302,7 @@ export const DatasourceList = () => {
267
302
) ,
268
303
} ,
269
304
] }
270
- dataSource = { datasource
271
- . filter ( ( info ) => {
272
- if ( info . datasource . creationSource === 2 ) {
273
- return false ;
274
- }
275
- if ( ! isEmpty ( searchValue ) ) {
276
- return (
277
- info . datasource . name . toLowerCase ( ) . includes ( searchValue . trim ( ) . toLowerCase ( ) ) ||
278
- info . datasource . type . toLowerCase ( ) . includes ( searchValue . trim ( ) . toLowerCase ( ) )
279
- ) ;
280
- }
281
- return true ;
282
- } )
305
+ dataSource = { elements . elements
283
306
. map ( ( info , i ) => ( {
284
307
key : i ,
285
308
id : info . datasource . id ,
@@ -296,6 +319,13 @@ export const DatasourceList = () => {
296
319
creator : info . creatorName ,
297
320
edit : info . edit ,
298
321
} ) ) } />
322
+ < PaginationComp
323
+ currentPage = { currentPage }
324
+ pageSize = { pageSize }
325
+ setPageSize = { setPageSize }
326
+ setCurrentPage = { setCurrentPage }
327
+ total = { elements . total }
328
+ />
299
329
</ BodyWrapper >
300
330
{ shareDatasourceId && (
301
331
< DatasourcePermissionDialog
@@ -305,6 +335,8 @@ export const DatasourceList = () => {
305
335
! visible && setShareDatasourceId ( undefined ) ;
306
336
} } />
307
337
) }
308
- </ DatasourceWrapper > </ >
338
+ </ DatasourceWrapper >
339
+
340
+ </ >
309
341
) ;
310
342
} ;
0 commit comments