1
1
import PropTypes from "prop-types" ;
2
- import { Pagination , PaginationItem , Typography , Box } from "@mui/material" ;
2
+ import { Typography , Box } from "@mui/material" ;
3
3
4
- import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded" ;
5
- import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded" ;
6
4
import { useState , useEffect } from "react" ;
7
5
import { useSelector } from "react-redux" ;
8
6
import { networkService } from "../../../main" ;
@@ -16,27 +14,20 @@ import { HttpStatusLabel } from "../../../Components/HttpStatusLabel";
16
14
import { Empty } from "./Empty/Empty" ;
17
15
import { IncidentSkeleton } from "./Skeleton/Skeleton" ;
18
16
import DataTable from "../../../Components/Table" ;
19
- const IncidentTable = ( { monitors, selectedMonitor, filter } ) => {
17
+ import Pagination from "../../../Components/Table/TablePagination" ;
18
+
19
+ const IncidentTable = ( { monitors, selectedMonitor, filter, dateRange } ) => {
20
20
const uiTimezone = useSelector ( ( state ) => state . ui . timezone ) ;
21
21
22
22
const theme = useTheme ( ) ;
23
23
const { authToken, user } = useSelector ( ( state ) => state . auth ) ;
24
24
const mode = useSelector ( ( state ) => state . ui . mode ) ;
25
25
const [ checks , setChecks ] = useState ( [ ] ) ;
26
26
const [ checksCount , setChecksCount ] = useState ( 0 ) ;
27
- const [ paginationController , setPaginationController ] = useState ( {
28
- page : 0 ,
29
- rowsPerPage : 14 ,
30
- } ) ;
27
+ const [ page , setPage ] = useState ( 0 ) ;
28
+ const [ rowsPerPage , setRowsPerPage ] = useState ( 10 ) ;
31
29
const [ isLoading , setIsLoading ] = useState ( false ) ;
32
30
33
- useEffect ( ( ) => {
34
- setPaginationController ( ( prevPaginationController ) => ( {
35
- ...prevPaginationController ,
36
- page : 0 ,
37
- } ) ) ;
38
- } , [ filter , selectedMonitor ] ) ;
39
-
40
31
useEffect ( ( ) => {
41
32
const fetchPage = async ( ) => {
42
33
if ( ! monitors || Object . keys ( monitors ) . length === 0 ) {
@@ -51,23 +42,24 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
51
42
teamId : user . teamId ,
52
43
sortOrder : "desc" ,
53
44
limit : null ,
54
- dateRange : null ,
45
+ dateRange,
55
46
filter : filter ,
56
- page : paginationController . page ,
57
- rowsPerPage : paginationController . rowsPerPage ,
47
+ page : page ,
48
+ rowsPerPage : rowsPerPage ,
58
49
} ) ;
59
50
} else {
60
51
res = await networkService . getChecksByMonitor ( {
61
52
authToken : authToken ,
62
53
monitorId : selectedMonitor ,
63
54
sortOrder : "desc" ,
64
55
limit : null ,
65
- dateRange : null ,
56
+ dateRange,
66
57
filter : filter ,
67
- page : paginationController . page ,
68
- rowsPerPage : paginationController . rowsPerPage ,
58
+ page,
59
+ rowsPerPage,
69
60
} ) ;
70
61
}
62
+
71
63
setChecks ( res . data . data . checks ) ;
72
64
setChecksCount ( res . data . data . checksCount ) ;
73
65
} catch ( error ) {
@@ -77,21 +69,14 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
77
69
}
78
70
} ;
79
71
fetchPage ( ) ;
80
- } , [
81
- authToken ,
82
- user ,
83
- monitors ,
84
- selectedMonitor ,
85
- filter ,
86
- paginationController . page ,
87
- paginationController . rowsPerPage ,
88
- ] ) ;
72
+ } , [ authToken , user , monitors , selectedMonitor , filter , page , rowsPerPage , dateRange ] ) ;
89
73
90
74
const handlePageChange = ( _ , newPage ) => {
91
- setPaginationController ( {
92
- ...paginationController ,
93
- page : newPage - 1 , // 0-indexed
94
- } ) ;
75
+ setPage ( newPage ) ;
76
+ } ;
77
+
78
+ const handleChangeRowsPerPage = ( event ) => {
79
+ setRowsPerPage ( event . target . value ) ;
95
80
} ;
96
81
97
82
const headers = [
@@ -134,28 +119,6 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
134
119
{ id : "message" , content : "Message" , render : ( row ) => row . message } ,
135
120
] ;
136
121
137
- let paginationComponent = < > </ > ;
138
- if ( checksCount > paginationController . rowsPerPage ) {
139
- paginationComponent = (
140
- < Pagination
141
- count = { Math . ceil ( checksCount / paginationController . rowsPerPage ) }
142
- page = { paginationController . page + 1 } //0-indexed
143
- onChange = { handlePageChange }
144
- shape = "rounded"
145
- renderItem = { ( item ) => (
146
- < PaginationItem
147
- slots = { {
148
- previous : ArrowBackRoundedIcon ,
149
- next : ArrowForwardRoundedIcon ,
150
- } }
151
- { ...item }
152
- />
153
- ) }
154
- sx = { { mt : "auto" } }
155
- />
156
- ) ;
157
- }
158
-
159
122
let sharedStyles = {
160
123
border : 1 ,
161
124
borderColor : theme . palette . primary . lowContrast ,
@@ -198,8 +161,14 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
198
161
headers = { headers }
199
162
data = { checks }
200
163
/>
201
-
202
- { paginationComponent }
164
+ < Pagination
165
+ paginationLabel = "incidents"
166
+ itemCount = { checksCount }
167
+ page = { page }
168
+ rowsPerPage = { rowsPerPage }
169
+ handleChangePage = { handlePageChange }
170
+ handleChangeRowsPerPage = { handleChangeRowsPerPage }
171
+ />
203
172
</ >
204
173
) }
205
174
</ >
@@ -210,6 +179,7 @@ IncidentTable.propTypes = {
210
179
monitors : PropTypes . object . isRequired ,
211
180
selectedMonitor : PropTypes . string . isRequired ,
212
181
filter : PropTypes . string . isRequired ,
182
+ dateRange : PropTypes . string . isRequired ,
213
183
} ;
214
184
215
185
export default IncidentTable ;
0 commit comments