import { useTheme } from "@emotion/react"; import { Box, Stack, Tooltip, Typography } from "@mui/material"; import { formatDateWithTz } from "../../../Utils/timeUtils"; import { useEffect, useState } from "react"; import { useSelector } from "react-redux"; /* TODO add prop validation and jsdocs */ const StatusPageBarChart = ({ checks = [] }) => { const theme = useTheme(); const [animate, setAnimate] = useState(false); const uiTimezone = useSelector((state) => state.ui.timezone); useEffect(() => { setAnimate(true); }, []); // set responseTime to average if there's only one check if (checks.length === 1) { checks[0] = { ...checks[0], responseTime: 50 }; } if (checks.length !== 25) { const placeholders = Array(25 - checks.length).fill("placeholder"); checks = [...checks, ...placeholders]; } return ( event.stopPropagation()} sx={{ cursor: "default", }} > {checks.map((check, index) => check === "placeholder" ? ( /* TODO what is the purpose of this box? */ // CAIO_REVIEW the purpose of this box is to make sure there are always at least 25 bars // even if there are less than 25 checks ) : ( {formatDateWithTz( check.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone )} Response Time {check.originalResponseTime} {" "} ms } placement="top" key={`check-${check?._id}`} slotProps={{ popper: { className: "bar-tooltip", modifiers: [ { name: "offset", options: { offset: [0, -10], }, }, ], sx: { "& .MuiTooltip-tooltip": { backgroundColor: theme.palette.secondary.main, border: 1, borderColor: theme.palette.primary.lowContrast, borderRadius: theme.shape.borderRadius, boxShadow: theme.shape.boxShadow, px: theme.spacing(4), py: theme.spacing(3), }, "& .MuiTooltip-tooltip p": { /* TODO Font size should point to theme */ fontSize: 12, color: theme.palette.secondary.contrastText, fontWeight: 500, }, "& .MuiTooltip-tooltip span": { /* TODO Font size should point to theme */ fontSize: 11, color: theme.palette.secondary.contrastText, fontWeight: 600, }, }, }, }} > ) )} ); }; export default StatusPageBarChart;