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

160 lines
4.4 KiB
React
Raw Normal View History

2025-01-27 13:18:05 -08:00
// Components
import { Stack, Typography, Box } from "@mui/material";
2025-09-27 14:54:55 -07:00
import ChartBox from "@/Components/v1/Charts/ChartBox/index.jsx";
import Icon from "@/Components/v1/Icon";
2025-09-25 10:11:41 -07:00
import UpBarChart from "../Charts/UpBarChart.jsx";
import DownBarChart from "../Charts/DownBarChart.jsx";
import ResponseGaugeChart from "../Charts/ResponseGaugeChart.jsx";
import SkeletonLayout from "./skeleton.jsx";
2025-01-27 13:18:05 -08:00
// Utils
2026-01-12 23:57:39 +00:00
import { formatDateWithTz } from "../../../../../Utils/timeUtils.js";
2025-01-27 13:18:05 -08:00
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
2025-03-19 12:15:04 -07:00
import { useState } from "react";
2025-01-27 13:18:05 -08:00
const ChartBoxes = ({
2025-03-19 12:15:04 -07:00
isLoading = false,
monitorData,
2025-01-27 13:18:05 -08:00
dateRange,
uiTimezone,
dateFormat,
}) => {
2025-03-19 12:15:04 -07:00
// Local state
const [hoveredUptimeData, setHoveredUptimeData] = useState(null);
const [hoveredIncidentsData, setHoveredIncidentsData] = useState(null);
2025-01-27 13:18:05 -08:00
const theme = useTheme();
2025-03-19 12:15:04 -07:00
if (isLoading) {
2025-01-27 14:55:55 -08:00
return <SkeletonLayout />;
}
2025-02-27 11:00:36 +05:30
const noIncidentsMessage = "Great. No Incidents, yet!";
2025-01-27 13:18:05 -08:00
return (
<Stack
direction="row"
flexWrap="wrap"
gap={theme.spacing(8)}
>
<ChartBox
2026-01-15 23:39:26 -05:00
icon={
<Icon
name="Activity"
size={20}
/>
}
2025-01-27 13:18:05 -08:00
header="Uptime"
2025-03-19 12:17:43 -07:00
isEmpty={monitorData?.groupedUpChecks?.length === 0}
2025-01-27 13:18:05 -08:00
>
<Stack
width={"100%"}
justifyContent="space-between"
direction="row"
>
2025-01-27 13:18:05 -08:00
<Box position="relative">
<Typography>Total Checks</Typography>
<Typography component="span">
{hoveredUptimeData !== null
? hoveredUptimeData.totalChecks
2025-03-19 12:15:04 -07:00
: (monitorData?.groupedUpChecks?.reduce((count, checkGroup) => {
2025-01-27 13:18:05 -08:00
return count + checkGroup.totalChecks;
}, 0) ?? 0)}
</Typography>
{hoveredUptimeData !== null && hoveredUptimeData.time !== null && (
<Typography
component="h5"
position="absolute"
top="100%"
fontSize={11}
color={theme.palette.primary.contrastTextTertiary}
>
{formatDateWithTz(hoveredUptimeData._id, dateFormat, uiTimezone)}
</Typography>
)}
</Box>
<Box>
<Typography>
{hoveredUptimeData !== null ? "Avg Response Time" : "Uptime Percentage"}
</Typography>
<Typography component="span">
{hoveredUptimeData !== null
2025-03-19 13:29:38 -07:00
? Math.floor(hoveredUptimeData?.originalAvgResponseTime ?? 0)
2025-05-15 14:20:24 -07:00
: Math.floor((monitorData?.groupedUptimePercentage ?? 0) * 100)}
2025-01-27 13:18:05 -08:00
<Typography component="span">
{hoveredUptimeData !== null ? " ms" : " %"}
</Typography>
</Typography>
</Box>
</Stack>
<UpBarChart
2025-03-19 12:15:04 -07:00
groupedUpChecks={monitorData?.groupedUpChecks}
2025-01-27 13:18:05 -08:00
type={dateRange}
onBarHover={setHoveredUptimeData}
/>
</ChartBox>
<ChartBox
2026-01-15 23:39:26 -05:00
icon={
<Icon
name="AlertTriangle"
size={20}
/>
}
2025-01-27 13:18:05 -08:00
header="Incidents"
2025-02-27 11:00:36 +05:30
noDataMessage={noIncidentsMessage}
2025-03-19 12:15:04 -07:00
isEmpty={monitorData?.groupedDownChecks?.length === 0}
2025-01-27 13:18:05 -08:00
>
<Stack width={"100%"}>
<Box position="relative">
<Typography component="span">
{hoveredIncidentsData !== null
? hoveredIncidentsData.totalChecks
2025-03-19 12:15:04 -07:00
: (monitorData?.groupedDownChecks?.reduce((count, checkGroup) => {
return count + checkGroup.totalChecks;
}, 0) ?? 0)}
2025-01-27 13:18:05 -08:00
</Typography>
{hoveredIncidentsData !== null && hoveredIncidentsData.time !== null && (
<Typography
component="h5"
position="absolute"
top="100%"
fontSize={11}
color={theme.palette.primary.contrastTextTertiary}
>
{formatDateWithTz(hoveredIncidentsData._id, dateFormat, uiTimezone)}
</Typography>
)}
</Box>
</Stack>
2025-01-27 13:18:05 -08:00
<DownBarChart
2025-03-19 12:15:04 -07:00
groupedDownChecks={monitorData?.groupedDownChecks}
2025-01-27 13:18:05 -08:00
type={dateRange}
onBarHover={setHoveredIncidentsData}
/>
</ChartBox>
<ChartBox
2026-01-15 23:39:26 -05:00
icon={
<Icon
name="BarChart3"
size={20}
/>
}
2025-01-27 13:18:05 -08:00
header="Average Response Time"
>
2025-03-19 12:15:04 -07:00
<ResponseGaugeChart avgResponseTime={monitorData?.groupedAvgResponseTime ?? 0} />
2025-01-27 13:18:05 -08:00
</ChartBox>
</Stack>
);
};
export default ChartBoxes;
ChartBoxes.propTypes = {
2025-03-19 12:15:04 -07:00
isLoading: PropTypes.bool,
monitorData: PropTypes.object,
2025-01-27 13:18:05 -08:00
dateRange: PropTypes.string.isRequired,
uiTimezone: PropTypes.string.isRequired,
dateFormat: PropTypes.string.isRequired,
hoveredUptimeData: PropTypes.object,
setHoveredUptimeData: PropTypes.func,
hoveredIncidentsData: PropTypes.object,
setHoveredIncidentsData: PropTypes.func,
};