Merge pull request #568 from bluewave-labs/feat/monitor-details-performance
Prep monitor details page for #567
This commit is contained in:
commit
7928bd7822
5 files changed
+102
-84
No files matched your search
@@ -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);
|
||||
};
|
||||
|
||||
@@ -47,37 +47,9 @@ 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);
|
||||
normalizedChecks = NormalizeData(checks, 10, 100);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user