Prep monitor details page for better data handling, minor fix to basic table component

This commit is contained in:
Alex Holliday committed 2024-08-07 22:46:21 -07:00
1 parent 288a24e314
commit 901ec29281
2 files changed
+31 -5

No files matched your search

+5 -1
View File
@@ -9,7 +9,7 @@ import {
Pagination, Pagination,
PaginationItem, PaginationItem,
} from "@mui/material"; } from "@mui/material";
import React, { useState } from "react"; import React, { useState, useEffect } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import "./index.css"; import "./index.css";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
@@ -73,6 +73,10 @@ const BasicTable = ({ data, paginated, reversed, rowsPerPage = 5 }) => {
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
useEffect(() => {
setPage(0);
}, [data]);
const handleChangePage = (event, newPage) => { const handleChangePage = (event, newPage) => {
setPage(newPage); setPage(newPage);
}; };
+26 -4
View File
@@ -116,18 +116,18 @@ const DetailsPage = () => {
const { authToken } = useSelector((state) => state.auth); const { authToken } = useSelector((state) => state.auth);
const [filter, setFilter] = useState("day"); const [filter, setFilter] = useState("day");
useEffect(() => { const fetchDataForChart = async () => {
const fetchMonitor = async () => {
try { try {
const limit = 0;
const res = await axiosInstance.get( const res = await axiosInstance.get(
`/monitors/${monitorId}?sortOrder=asc`, `/monitors/${monitorId}?sortOrder=asc&limit=${limit}`,
{ {
headers: { headers: {
Authorization: `Bearer ${authToken}`, Authorization: `Bearer ${authToken}`,
}, },
} }
); );
setMonitor(res.data.data);
const data = { const data = {
cols: [ cols: [
{ id: 1, name: "Status" }, { id: 1, name: "Status" },
@@ -161,14 +161,36 @@ const DetailsPage = () => {
}; };
setData(data); setData(data);
} catch (error) {
console.log(error);
}
};
const fetchMonitor = async () => {
try {
const res = await axiosInstance.get(
`/monitors/${monitorId}?sortOrder=asc`,
{
headers: {
Authorization: `Bearer ${authToken}`,
},
}
);
setMonitor(res.data.data);
} catch (error) { } catch (error) {
console.error("Error fetching monitor of id: " + monitorId); console.error("Error fetching monitor of id: " + monitorId);
navigate("/not-found"); navigate("/not-found");
} }
}; };
useEffect(() => {
fetchMonitor(); fetchMonitor();
}, [monitorId, authToken]); }, [monitorId, authToken]);
useEffect(() => {
fetchDataForChart();
}, [filter]);
const theme = useTheme(); const theme = useTheme();
const navigate = useNavigate(); const navigate = useNavigate();