1
1
import React , { useEffect , useState , useContext } from 'react'
2
2
import MaterialTable from '@material-table/core'
3
3
import { DeleteOutlined } from '@material-ui/icons'
4
- import { Paper } from '@material-ui/core'
4
+ import { Paper , TablePagination } from '@material-ui/core'
5
5
import UserDetailViewPage from './UserDetailViewPage'
6
6
import {
7
7
getUsers ,
@@ -40,7 +40,10 @@ function UserList(props) {
40
40
dispatch ( getAttributes ( opt ) )
41
41
dispatch ( getRoles ( ) )
42
42
} , [ ] )
43
-
43
+ const { totalItems, entriesCount } = useSelector (
44
+ ( state ) => state . userReducer ,
45
+ )
46
+ const [ pageNumber , setPageNumber ] = useState ( 0 )
44
47
const usersList = useSelector ( ( state ) => state . userReducer . items )
45
48
const redirectToUserListPage = useSelector (
46
49
( state ) => state . userReducer . redirectToUserListPage ,
@@ -62,9 +65,8 @@ function UserList(props) {
62
65
SetTitle ( t ( 'titles.user_management' ) )
63
66
64
67
const myActions = [ ]
65
- const options = [ ]
68
+ const options = { }
66
69
const userAction = { }
67
- const pageSize = localStorage . getItem ( 'paggingSize' ) || 10
68
70
const navigate = useNavigate ( )
69
71
70
72
function handleGoToUserAddPage ( ) {
@@ -75,7 +77,7 @@ function UserList(props) {
75
77
dispatch ( setSelectedUserData ( row ) )
76
78
return navigate ( `/user/usermanagement/edit:` + row . tableData . uuid )
77
79
}
78
- const [ limit , setLimit ] = useState ( 200 )
80
+ const [ limit , setLimit ] = useState ( 10 )
79
81
const [ pattern , setPattern ] = useState ( null )
80
82
81
83
let memoLimit = limit
@@ -102,6 +104,7 @@ function UserList(props) {
102
104
limit = { limit }
103
105
pattern = { pattern }
104
106
handler = { handleOptionsChange }
107
+ showLimit = { false }
105
108
/>
106
109
) ,
107
110
tooltip : `${ t ( 'messages.advanced_search' ) } ` ,
@@ -119,8 +122,6 @@ function UserList(props) {
119
122
onClick : ( ) => {
120
123
setLimit ( memoLimit )
121
124
setPattern ( memoPattern )
122
- console . log ( 'LIMIT' , memoLimit )
123
- console . log ( 'PATTERN' , memoPattern )
124
125
dispatch ( getUsers ( { limit : memoLimit , pattern : memoPattern } ) )
125
126
} ,
126
127
} )
@@ -159,15 +160,47 @@ function UserList(props) {
159
160
} ) )
160
161
}
161
162
163
+ const onPageChangeClick = ( page ) => {
164
+ let startCount = page * limit
165
+ options [ 'startIndex' ] = parseInt ( startCount ) + 1
166
+ options [ 'limit' ] = limit
167
+ options [ 'pattern' ] = pattern
168
+ setPageNumber ( page )
169
+ dispatch ( getUsers ( options ) )
170
+ }
171
+ const onRowCountChangeClick = ( count ) => {
172
+
173
+ options [ 'limit' ] = count
174
+ options [ 'pattern' ] = pattern
175
+ setPageNumber ( 0 )
176
+ setLimit ( count )
177
+ dispatch ( getUsers ( options ) )
178
+ }
179
+
162
180
return (
163
181
< GluuLoader blocking = { loading } >
164
182
< Card style = { applicationStyle . mainCard } >
165
183
< CardBody >
166
184
< GluuViewWrapper canShow = { hasPermission ( permissions , ROLE_READ ) } >
167
185
{ usersList . length > 0 && (
168
186
< MaterialTable
187
+ key = { limit }
169
188
components = { {
170
189
Container : ( props ) => < Paper { ...props } elevation = { 0 } /> ,
190
+ Pagination : ( props ) => (
191
+ < TablePagination
192
+ component = "div"
193
+ count = { totalItems }
194
+ page = { pageNumber }
195
+ onPageChange = { ( prop , page ) => {
196
+ onPageChangeClick ( page )
197
+ } }
198
+ rowsPerPage = { limit }
199
+ onRowsPerPageChange = { ( prop , count ) =>
200
+ onRowCountChangeClick ( count . props . value )
201
+ }
202
+ />
203
+ ) ,
171
204
} }
172
205
columns = { [
173
206
{
@@ -185,7 +218,7 @@ function UserList(props) {
185
218
search : true ,
186
219
searchFieldAlignment : 'left' ,
187
220
selection : false ,
188
- pageSize : pageSize ,
221
+ pageSize : limit ,
189
222
rowStyle : ( rowData ) => ( {
190
223
backgroundColor : rowData . enabled ? '#33AE9A' : '#FFF' ,
191
224
} ) ,
0 commit comments