diff --git a/Client/src/Components/BasicTable/index.jsx b/Client/src/Components/BasicTable/index.jsx index 3f89de700..76f1c61c7 100644 --- a/Client/src/Components/BasicTable/index.jsx +++ b/Client/src/Components/BasicTable/index.jsx @@ -9,7 +9,7 @@ import { Pagination, PaginationItem, } from "@mui/material"; -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import PropTypes from "prop-types"; import "./index.css"; import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; @@ -73,6 +73,10 @@ const BasicTable = ({ data, paginated, reversed, rowsPerPage = 5 }) => { const [page, setPage] = useState(0); + useEffect(() => { + setPage(0); + }, [data]); + const handleChangePage = (event, newPage) => { setPage(newPage); }; diff --git a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx index 39aa8dcbf..567de0b68 100644 --- a/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx +++ b/Client/src/Components/Charts/MonitorDetailsAreaChart/index.jsx @@ -1,6 +1,5 @@ import PropTypes from "prop-types"; import { AreaChart, Area, XAxis, Tooltip, ResponsiveContainer } from "recharts"; -import { NormalizeData } from "../ChartUtils"; import "./index.css"; const CustomToolTip = ({ active, payload, label }) => { @@ -28,7 +27,7 @@ const CustomToolTip = ({ active, payload, label }) => { return null; }; -const MonitorDetailsAreaChart = ({ checks, filter }) => { +const MonitorDetailsAreaChart = ({ checks }) => { // SQUASH ERROR, NOT PERMANENT SOLUTION const error = console.error; console.error = (...args) => { @@ -47,45 +46,12 @@ const MonitorDetailsAreaChart = ({ checks, filter }) => { }); }; - const filterChecks = (checks, filter, numToDisplay) => { - const limits = { - day: 24 * 60 * 60 * 1000, - week: 24 * 60 * 60 * 1000 * 7, - month: 24 * 60 * 60 * 1000 * 30, //TODO better monthly calculations - }; - - const now = new Date().getTime(); - let result = []; - for (let i = 0; i < checks.length; i++) { - const checkTime = new Date(checks[i].createdAt).getTime(); - if (now - checkTime < limits[filter]) { - result.push(checks[i]); - } - } - - // If more than numToDisplay checks, pick every nth check - if (result.length > numToDisplay) { - const n = Math.ceil(result.length / numToDisplay); - result = result.filter((_, idx) => { - return idx % n === 0; - }); - } - - return result; - }; - - let normalizedChecks = []; - if (checks && checks.length > 0) { - const filteredChecks = filterChecks(checks, filter, 75); - normalizedChecks = NormalizeData(filteredChecks, 10, 100); - } - return ( { - const normalizedChecks = NormalizeData(checks, 1, 100); return (
- {normalizedChecks.map((check, index) => ( + {checks.map((check, index) => ( { + const theme = useTheme(); + + return ( + <> + + + + + + + + + ); +}; + const Incidents = () => { const theme = useTheme(); const navigate = useNavigate(); const authState = useSelector((state) => state.auth); const [monitors, setMonitors] = useState({}); const [selectedMonitor, setSelectedMonitor] = useState("0"); + const [loading, setLoading] = useState(false); // TODO do something with these filters const [filter, setFilter] = useState("all"); @@ -34,6 +61,7 @@ const Incidents = () => { useEffect(() => { const fetchIncidents = async () => { + setLoading(true); const res = await axiosInstance.get( `/monitors/user/${authState.user._id}?status=false`, { @@ -51,6 +79,7 @@ const Incidents = () => { }, {}); setMonitors(monitorLookup); } + setLoading(false); }; fetchIncidents(); @@ -92,8 +121,8 @@ const Incidents = () => { data: , }, { id: idx + 1, data: new Date(incident.createdAt).toLocaleString() }, - { id: idx + 2, data: incident.statusCode }, - { id: idx + 3, data: monitors[incident.monitorId].name }, + { id: idx + 2, data: monitors[incident.monitorId].name }, + { id: idx + 3, data: incident.statusCode }, ], }; }); @@ -102,7 +131,9 @@ const Incidents = () => { return ( <> - {hasAnyIncidents ? ( + {loading ? ( + + ) : hasAnyIncidents ? ( <> Incident history for: @@ -155,8 +186,7 @@ const Incidents = () => { )} ) : ( - - No incidents, yet. +