Files
Checkmate/src/Pages/Uptime/Details/Components/UptimeStatusBoxes/index.jsx
T

87 lines
2.2 KiB
React
Raw Normal View History

import StatusBoxes from "../../../../../Components/StatusBoxes";
2025-01-27 13:18:05 -08:00
import StatBox from "../../../../../Components/StatBox";
2025-03-19 12:15:04 -07:00
import PropTypes from "prop-types";
import { getHumanReadableDuration } from "../../../../../Utils/timeUtils";
2025-01-27 13:18:05 -08:00
import { useTheme } from "@mui/material/styles";
import { Typography } from "@mui/material";
2025-01-28 11:05:06 -08:00
import useUtils from "../../../Monitors/Hooks/useUtils";
2025-03-19 12:15:04 -07:00
const UptimeStatusBoxes = ({
isLoading = false,
monitor,
monitorStats,
certificateExpiry,
}) => {
2025-01-27 14:58:37 -08:00
const theme = useTheme();
const { determineState } = useUtils();
2025-01-29 11:42:02 -08:00
2025-03-19 12:15:04 -07:00
// Determine time since last failure
const timeOfLastFailure = monitorStats?.timeOfLastFailure;
const timeSinceLastFailure = timeOfLastFailure > 0 ? Date.now() - timeOfLastFailure : 0;
2025-01-27 13:18:05 -08:00
2025-03-19 12:15:04 -07:00
// Determine time since last check
const timeOfLastCheck = monitorStats?.lastCheckTimestamp;
const timeSinceLastCheck = Date.now() - timeOfLastCheck;
const { time: streakTime, units: streakUnits } =
getHumanReadableDuration(timeSinceLastFailure);
const { time: lastCheckTime, units: lastCheckUnits } =
getHumanReadableDuration(timeSinceLastCheck);
2025-01-27 13:18:05 -08:00
return (
2025-03-19 12:15:04 -07:00
<StatusBoxes shouldRender={!isLoading}>
2025-01-27 13:18:05 -08:00
<StatBox
gradient={true}
status={determineState(monitor)}
heading={"active for"}
subHeading={
<>
{streakTime}
<Typography component="span">{streakUnits}</Typography>
</>
}
/>
<StatBox
heading="last check"
subHeading={
<>
{lastCheckTime}
<Typography component="span">{lastCheckUnits}</Typography>
<Typography component="span">{"ago"}</Typography>
</>
}
/>
<StatBox
heading="last response time"
subHeading={
<>
2025-03-19 12:15:04 -07:00
{monitorStats?.lastResponseTime}
2025-01-27 13:18:05 -08:00
<Typography component="span">{"ms"}</Typography>
</>
}
/>
<StatBox
heading="certificate expiry"
subHeading={
<Typography
component="span"
fontSize={13}
color={theme.palette.primary.contrastText}
>
{certificateExpiry}
</Typography>
}
/>
</StatusBoxes>
2025-01-27 13:18:05 -08:00
);
};
2025-03-19 12:15:04 -07:00
UptimeStatusBoxes.propTypes = {
shouldRender: PropTypes.bool,
monitor: PropTypes.object,
monitorStats: PropTypes.object,
certificateExpiry: PropTypes.string,
};
export default UptimeStatusBoxes;