11import styled from "styled-components" ;
22import { EditPopover , PointIcon , Search , TacoButton } from "lowcoder-design" ;
3- import React , { useState } from "react" ;
3+ import React , { useEffect , useState } from "react" ;
44import { useDispatch , useSelector } from "react-redux" ;
55import { getDataSource , getDataSourceLoading , getDataSourceTypesMap } from "../../redux/selectors/datasourceSelectors" ;
66import { deleteDatasource } from "../../redux/reduxActions/datasourceActions" ;
@@ -17,6 +17,10 @@ import { DatasourcePermissionDialog } from "../../components/PermissionDialog/Da
1717import DataSourceIcon from "components/DataSourceIcon" ;
1818import { Helmet } from "react-helmet" ;
1919import 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" ;
2024
2125const DatasourceWrapper = styled . div `
2226 display: flex;
@@ -103,11 +107,41 @@ const StyledTable = styled(Table)`
103107export const DatasourceList = ( ) => {
104108 const dispatch = useDispatch ( ) ;
105109 const [ searchValue , setSearchValue ] = useState ( "" ) ;
110+ const [ searchValues , setSearchValues ] = useState ( "" ) ;
106111 const [ isCreateFormShow , showCreateForm ] = useState ( false ) ;
107112 const [ shareDatasourceId , setShareDatasourceId ] = useState < string | undefined > ( undefined ) ;
108113 const datasource = useSelector ( getDataSource ) ;
114+ const currentUser = useSelector ( getUser ) ;
115+ const orgId = currentUser . currentOrgId ;
109116 const datasourceLoading = useSelector ( getDataSourceLoading ) ;
110117 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+ )
111145
112146 return (
113147 < >
@@ -140,6 +174,7 @@ export const DatasourceList = () => {
140174 placeholder = { trans ( "search" ) }
141175 value = { searchValue }
142176 onChange = { ( e ) => setSearchValue ( e . target . value ) }
177+ onEnterPress = { ( value ) => setSearchValues ( value ) }
143178 style = { { width : "192px" , height : "32px" , margin : "0 12px 0 0" } } />
144179 < AddBtn buttonType = { "primary" } onClick = { ( ) => showCreateForm ( true ) } >
145180 { trans ( "home.newDatasource" ) }
@@ -267,19 +302,7 @@ export const DatasourceList = () => {
267302 ) ,
268303 } ,
269304 ] }
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
283306 . map ( ( info , i ) => ( {
284307 key : i ,
285308 id : info . datasource . id ,
@@ -296,6 +319,13 @@ export const DatasourceList = () => {
296319 creator : info . creatorName ,
297320 edit : info . edit ,
298321 } ) ) } />
322+ < PaginationComp
323+ currentPage = { currentPage }
324+ pageSize = { pageSize }
325+ setPageSize = { setPageSize }
326+ setCurrentPage = { setCurrentPage }
327+ total = { elements . total }
328+ />
299329 </ BodyWrapper >
300330 { shareDatasourceId && (
301331 < DatasourcePermissionDialog
@@ -305,6 +335,8 @@ export const DatasourceList = () => {
305335 ! visible && setShareDatasourceId ( undefined ) ;
306336 } } />
307337 ) }
308- </ DatasourceWrapper > </ >
338+ </ DatasourceWrapper >
339+
340+ </ >
309341 ) ;
310342} ;
0 commit comments