Skip to content

Commit 027b331

Browse files
authored
Merge pull request #1607 from bluewave-labs/fix/be/incidents
fix: be/incidents, resolves #1567
2 parents e4f2cfb + 1b31f9a commit 027b331

File tree

19 files changed

+347
-243
lines changed

19 files changed

+347
-243
lines changed

Client/src/Components/HttpStatusLabel/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { BaseLabel } from "../Label";
1616
const DEFAULT_CODE = 9999; // Default code for unknown status
1717

1818
const handleStatusCode = (status) => {
19-
if (status >= 100 && status < 600) {
19+
if (status) {
2020
return status;
2121
}
2222
return DEFAULT_CODE;

Client/src/Components/Table/TablePagination/index.jsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { TablePaginationActions } from "./Actions";
55
import SelectorVertical from "../../../assets/icons/selector-vertical.svg?react";
66

77
Pagination.propTypes = {
8-
monitorCount: PropTypes.number.isRequired, // Total number of items for pagination.
8+
itemCount: PropTypes.number.isRequired, // Total number of items for pagination.
99
page: PropTypes.number.isRequired, // Current page index.
1010
rowsPerPage: PropTypes.number.isRequired, // Number of rows displayed per page.
1111
handleChangePage: PropTypes.func.isRequired, // Function to handle page changes.
12-
handleChangeRowsPerPage: PropTypes.func.isRequired, // Function to handle changes in rows per page.
12+
handleChangeRowsPerPage: PropTypes.func, // Function to handle changes in rows per page.
1313
};
1414

1515
const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
@@ -18,6 +18,7 @@ const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
1818
* Pagination component for table navigation with customized styling and behavior.
1919
*
2020
* @param {object} props - Component properties.
21+
* @param {string} props.paginationLabel - Label for the pagination.
2122
* @param {number} props.monitorCount - Total number of monitors to paginate.
2223
* @param {number} props.page - Current page index (0-based).
2324
* @param {number} props.rowsPerPage - Number of rows to display per page.
@@ -26,7 +27,8 @@ const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
2627
* @returns {JSX.Element} The Pagination component.
2728
*/
2829
function Pagination({
29-
monitorCount,
30+
paginationLabel,
31+
itemCount,
3032
page,
3133
rowsPerPage,
3234
handleChangePage,
@@ -35,7 +37,7 @@ function Pagination({
3537
const theme = useTheme();
3638

3739
const start = page * rowsPerPage + 1;
38-
const end = Math.min(page * rowsPerPage + rowsPerPage, monitorCount);
40+
const end = Math.min(page * rowsPerPage + rowsPerPage, itemCount);
3941
const range = `${start} - ${end}`;
4042

4143
return (
@@ -51,11 +53,11 @@ function Pagination({
5153
variant="body2"
5254
sx={{ opacity: 0.7 }}
5355
>
54-
Showing {range} of {monitorCount} monitor(s)
56+
Showing {range} of {itemCount} {paginationLabel}
5557
</Typography>
5658
<TablePagination
5759
component="div"
58-
count={monitorCount}
60+
count={itemCount}
5961
page={page}
6062
onPageChange={handleChangePage}
6163
rowsPerPage={rowsPerPage}
@@ -121,4 +123,4 @@ function Pagination({
121123
);
122124
}
123125

124-
export { Pagination };
126+
export default Pagination;

Client/src/Components/Table/index.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ const DataTable = ({ headers, data, config = { emptyView: "No data" } }) => {
8282
</TableRow>
8383
) : (
8484
data.map((row) => {
85+
const key = row.id || row._id || Math.random();
8586
return (
8687
<TableRow
87-
key={row.id}
88+
key={key}
8889
sx={config?.rowSX ?? {}}
8990
onClick={() => config?.onRowClick(row)}
9091
>

Client/src/Pages/Incidents/IncidentTable/index.jsx

+28-58
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import PropTypes from "prop-types";
2-
import { Pagination, PaginationItem, Typography, Box } from "@mui/material";
2+
import { Typography, Box } from "@mui/material";
33

4-
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
5-
import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
64
import { useState, useEffect } from "react";
75
import { useSelector } from "react-redux";
86
import { networkService } from "../../../main";
@@ -16,27 +14,20 @@ import { HttpStatusLabel } from "../../../Components/HttpStatusLabel";
1614
import { Empty } from "./Empty/Empty";
1715
import { IncidentSkeleton } from "./Skeleton/Skeleton";
1816
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 }) => {
2020
const uiTimezone = useSelector((state) => state.ui.timezone);
2121

2222
const theme = useTheme();
2323
const { authToken, user } = useSelector((state) => state.auth);
2424
const mode = useSelector((state) => state.ui.mode);
2525
const [checks, setChecks] = useState([]);
2626
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);
3129
const [isLoading, setIsLoading] = useState(false);
3230

33-
useEffect(() => {
34-
setPaginationController((prevPaginationController) => ({
35-
...prevPaginationController,
36-
page: 0,
37-
}));
38-
}, [filter, selectedMonitor]);
39-
4031
useEffect(() => {
4132
const fetchPage = async () => {
4233
if (!monitors || Object.keys(monitors).length === 0) {
@@ -51,23 +42,24 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
5142
teamId: user.teamId,
5243
sortOrder: "desc",
5344
limit: null,
54-
dateRange: null,
45+
dateRange,
5546
filter: filter,
56-
page: paginationController.page,
57-
rowsPerPage: paginationController.rowsPerPage,
47+
page: page,
48+
rowsPerPage: rowsPerPage,
5849
});
5950
} else {
6051
res = await networkService.getChecksByMonitor({
6152
authToken: authToken,
6253
monitorId: selectedMonitor,
6354
sortOrder: "desc",
6455
limit: null,
65-
dateRange: null,
56+
dateRange,
6657
filter: filter,
67-
page: paginationController.page,
68-
rowsPerPage: paginationController.rowsPerPage,
58+
page,
59+
rowsPerPage,
6960
});
7061
}
62+
7163
setChecks(res.data.data.checks);
7264
setChecksCount(res.data.data.checksCount);
7365
} catch (error) {
@@ -77,21 +69,14 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
7769
}
7870
};
7971
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]);
8973

9074
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);
9580
};
9681

9782
const headers = [
@@ -134,28 +119,6 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
134119
{ id: "message", content: "Message", render: (row) => row.message },
135120
];
136121

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-
159122
let sharedStyles = {
160123
border: 1,
161124
borderColor: theme.palette.primary.lowContrast,
@@ -198,8 +161,14 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
198161
headers={headers}
199162
data={checks}
200163
/>
201-
202-
{paginationComponent}
164+
<Pagination
165+
paginationLabel="incidents"
166+
itemCount={checksCount}
167+
page={page}
168+
rowsPerPage={rowsPerPage}
169+
handleChangePage={handlePageChange}
170+
handleChangeRowsPerPage={handleChangeRowsPerPage}
171+
/>
203172
</>
204173
)}
205174
</>
@@ -210,6 +179,7 @@ IncidentTable.propTypes = {
210179
monitors: PropTypes.object.isRequired,
211180
selectedMonitor: PropTypes.string.isRequired,
212181
filter: PropTypes.string.isRequired,
182+
dateRange: PropTypes.string.isRequired,
213183
};
214184

215185
export default IncidentTable;

Client/src/Pages/Incidents/index.css

-11
This file was deleted.

0 commit comments

Comments
 (0)