Skip to content

Commit 19de5b4

Browse files
committed
feat(admin-ui): implement server side pagination on users screen
1 parent 853c551 commit 19de5b4

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

admin-ui/plugins/user-management/components/UserManagement/UserList.js

+41-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState, useContext } from 'react'
22
import MaterialTable from '@material-table/core'
33
import { DeleteOutlined } from '@material-ui/icons'
4-
import { Paper } from '@material-ui/core'
4+
import { Paper, TablePagination } from '@material-ui/core'
55
import UserDetailViewPage from './UserDetailViewPage'
66
import {
77
getUsers,
@@ -40,7 +40,10 @@ function UserList(props) {
4040
dispatch(getAttributes(opt))
4141
dispatch(getRoles())
4242
}, [])
43-
43+
const { totalItems, entriesCount } = useSelector(
44+
(state) => state.userReducer,
45+
)
46+
const [pageNumber, setPageNumber] = useState(0)
4447
const usersList = useSelector((state) => state.userReducer.items)
4548
const redirectToUserListPage = useSelector(
4649
(state) => state.userReducer.redirectToUserListPage,
@@ -62,9 +65,8 @@ function UserList(props) {
6265
SetTitle(t('titles.user_management'))
6366

6467
const myActions = []
65-
const options = []
68+
const options = {}
6669
const userAction = {}
67-
const pageSize = localStorage.getItem('paggingSize') || 10
6870
const navigate =useNavigate()
6971

7072
function handleGoToUserAddPage() {
@@ -75,7 +77,7 @@ function UserList(props) {
7577
dispatch(setSelectedUserData(row))
7678
return navigate(`/user/usermanagement/edit:` + row.tableData.uuid)
7779
}
78-
const [limit, setLimit] = useState(200)
80+
const [limit, setLimit] = useState(10)
7981
const [pattern, setPattern] = useState(null)
8082

8183
let memoLimit = limit
@@ -102,6 +104,7 @@ function UserList(props) {
102104
limit={limit}
103105
pattern={pattern}
104106
handler={handleOptionsChange}
107+
showLimit={false}
105108
/>
106109
),
107110
tooltip: `${t('messages.advanced_search')}`,
@@ -119,8 +122,6 @@ function UserList(props) {
119122
onClick: () => {
120123
setLimit(memoLimit)
121124
setPattern(memoPattern)
122-
console.log('LIMIT', memoLimit)
123-
console.log('PATTERN', memoPattern)
124125
dispatch(getUsers({ limit: memoLimit, pattern: memoPattern }))
125126
},
126127
})
@@ -159,15 +160,47 @@ function UserList(props) {
159160
}))
160161
}
161162

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+
162180
return (
163181
<GluuLoader blocking={loading}>
164182
<Card style={applicationStyle.mainCard}>
165183
<CardBody>
166184
<GluuViewWrapper canShow={hasPermission(permissions, ROLE_READ)}>
167185
{usersList.length > 0 && (
168186
<MaterialTable
187+
key={limit}
169188
components={{
170189
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+
),
171204
}}
172205
columns={[
173206
{
@@ -185,7 +218,7 @@ function UserList(props) {
185218
search: true,
186219
searchFieldAlignment: 'left',
187220
selection: false,
188-
pageSize: pageSize,
221+
pageSize: limit,
189222
rowStyle: (rowData) => ({
190223
backgroundColor: rowData.enabled ? '#33AE9A' : '#FFF',
191224
}),

admin-ui/plugins/user-management/redux/reducers/UserReducer.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const INIT_STATE = {
1818
selectedUserData: null,
1919
loading: true,
2020
redirectToUserListPage: false,
21+
totalItems: 0,
22+
entriesCount: 0,
2123
}
2224
const reducerName = 'userReducer'
2325

@@ -81,6 +83,8 @@ export default function userReducer(state = INIT_STATE, action) {
8183
...state,
8284
loading: false,
8385
items: action.payload ? action.payload.entries : [],
86+
totalItems: action.payload.totalEntriesCount,
87+
entriesCount: action.payload.entriesCount,
8488
}
8589
default:
8690
return handleDefault()

0 commit comments

Comments
 (0)