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

81 lines
2.0 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-06-12 12:44:46 +08:00
import { useMonitorUtils } from "../../../../../Hooks/useMonitorUtils";
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();
2025-06-12 12:44:46 +08:00
const { determineState } = useMonitorUtils();
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;
2025-06-17 13:41:25 +08:00
const streakTime = getHumanReadableDuration(timeSinceLastFailure);
2025-03-19 12:15:04 -07:00
2025-06-17 13:41:25 +08:00
const lastCheckTime = 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"}
2025-06-17 13:41:25 +08:00
subHeading={streakTime}
2025-01-27 13:18:05 -08:00
/>
<StatBox
heading="last check"
subHeading={
<>
{lastCheckTime}
<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>
</>
}
/>
{monitor?.type === "http" && (
<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 = {
2025-06-17 11:32:35 +08:00
isLoading: PropTypes.bool,
2025-03-19 12:15:04 -07:00
monitor: PropTypes.object,
monitorStats: PropTypes.object,
certificateExpiry: PropTypes.string,
};
export default UptimeStatusBoxes;