Added format function that returns a split duration

This commit is contained in:
Daniel Cojocea committed 2024-09-02 20:05:02 -04:00
1 parent 0aa2c795fb
commit 9ae8c93cb0
3 files changed
+47 -16

No files matched your search

+25 -11
View File
@@ -18,6 +18,7 @@ import {
formatDate, formatDate,
formatDuration, formatDuration,
formatDurationRounded, formatDurationRounded,
formatDurationSplit,
} from "../../../Utils/timeUtils"; } from "../../../Utils/timeUtils";
import MonitorDetailsAreaChart from "../../../Components/Charts/MonitorDetailsAreaChart"; import MonitorDetailsAreaChart from "../../../Components/Charts/MonitorDetailsAreaChart";
import ButtonGroup from "@mui/material/ButtonGroup"; import ButtonGroup from "@mui/material/ButtonGroup";
@@ -31,8 +32,8 @@ import HistoryIcon from "../../../assets/icons/history-icon.svg?react";
import PaginationTable from "./PaginationTable"; import PaginationTable from "./PaginationTable";
import Breadcrumbs from "../../../Components/Breadcrumbs"; import Breadcrumbs from "../../../Components/Breadcrumbs";
import PulseDot from "../../../Components/Animated/PulseDot"; import PulseDot from "../../../Components/Animated/PulseDot";
import { StatBox, ChartBox, IconBox } from "./styled";
import "./index.css"; import "./index.css";
import { AlertBox, ChartBox, IconBox } from "./styled";
/** /**
* Renders a skeleton layout. * Renders a skeleton layout.
@@ -174,6 +175,16 @@ const DetailsPage = ({ isAdmin }) => {
fetchCertificate(); fetchCertificate();
}, [authToken, monitorId, monitor]); }, [authToken, monitorId, monitor]);
const splitDuration = (duration) => {
const { time, format } = formatDurationSplit(duration);
return (
<>
{time}
<Typography component="span">{format}</Typography>
</>
);
};
let loading = Object.keys(monitor).length === 0; let loading = Object.keys(monitor).length === 0;
return ( return (
<Box className="monitor-details"> <Box className="monitor-details">
@@ -187,7 +198,7 @@ const DetailsPage = ({ isAdmin }) => {
{ name: "details", path: `/monitors/${monitorId}` }, { name: "details", path: `/monitors/${monitorId}` },
]} ]}
/> />
<Stack gap={theme.spacing(12)} mt={theme.spacing(10)}> <Stack gap={theme.spacing(10)} mt={theme.spacing(10)}>
<Stack direction="row" gap={theme.spacing(2)}> <Stack direction="row" gap={theme.spacing(2)}>
<Box> <Box>
<Typography <Typography
@@ -281,6 +292,9 @@ const DetailsPage = ({ isAdmin }) => {
anchorEl={anchorEl} anchorEl={anchorEl}
open={Boolean(anchorEl)} open={Boolean(anchorEl)}
onClose={closeCertificate} onClose={closeCertificate}
disableScrollLock
marginThreshold={null}
anchorReference={anchorEl}
anchorOrigin={{ anchorOrigin={{
vertical: "bottom", vertical: "bottom",
horizontal: "center", horizontal: "center",
@@ -332,27 +346,27 @@ const DetailsPage = ({ isAdmin }) => {
)} )}
</Stack> </Stack>
</Stack> </Stack>
<Stack direction="row" gap={theme.spacing(8)}> <Stack direction="row" gap={theme.spacing(8)} maxWidth={712}>
<AlertBox> <StatBox>
<Typography component="h2">up for</Typography> <Typography component="h2">up for</Typography>
<Typography> <Typography>
{formatDurationRounded(monitor?.uptimeDuration)} {splitDuration(monitor?.uptimeDuration)}
</Typography> </Typography>
</AlertBox> </StatBox>
<AlertBox> <StatBox>
<Typography component="h2">last check</Typography> <Typography component="h2">last check</Typography>
<Typography> <Typography>
{formatDurationRounded(monitor?.lastChecked)} {splitDuration(monitor?.lastChecked)}
<Typography component="span">ago</Typography> <Typography component="span">ago</Typography>
</Typography> </Typography>
</AlertBox> </StatBox>
<AlertBox> <StatBox>
<Typography component="h2">last response time</Typography> <Typography component="h2">last response time</Typography>
<Typography> <Typography>
{monitor?.latestResponseTime} {monitor?.latestResponseTime}
<Typography component="span">ms</Typography> <Typography component="span">ms</Typography>
</Typography> </Typography>
</AlertBox> </StatBox>
</Stack> </Stack>
<Box> <Box>
<Stack <Stack
+4 -4
View File
@@ -61,10 +61,10 @@ export const IconBox = styled(Box)(({ theme }) => ({
}, },
})); }));
export const AlertBox = styled(Box)(({ theme }) => ({ export const StatBox = styled(Box)(({ theme }) => ({
padding: `${theme.spacing(4)} ${theme.spacing(8)}`, padding: `${theme.spacing(4)} ${theme.spacing(8)}`,
minWidth: 200, minWidth: 200,
width: 225, flex: 1,
border: 1, border: 1,
borderStyle: "solid", borderStyle: "solid",
borderColor: theme.palette.border.light, borderColor: theme.palette.border.light,
@@ -81,8 +81,8 @@ export const AlertBox = styled(Box)(({ theme }) => ({
color: theme.palette.text.primary, color: theme.palette.text.primary,
marginTop: theme.spacing(2), marginTop: theme.spacing(2),
"& span": { "& span": {
opacity: 0.8, color: theme.palette.text.tertiary,
marginLeft: theme.spacing(3), marginLeft: theme.spacing(2),
fontSize: 15, fontSize: 15,
}, },
}, },
+18 -1
View File
@@ -43,6 +43,23 @@ export const formatDurationRounded = (ms) => {
return time; return time;
}; };
export const formatDurationSplit = (ms) => {
const seconds = Math.floor(ms / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
return days > 0
? { time: days, format: days === 1 ? "day" : "days" }
: hours > 0
? { time: hours, format: hours === 1 ? "hour" : "hours" }
: minutes > 0
? { time: minutes, format: minutes === 1 ? "minute" : "minutes" }
: seconds > 0
? { time: seconds, format: seconds === 1 ? "second" : "seconds" }
: { time: 0, format: "seconds" };
};
export const formatDate = (date, customOptions) => { export const formatDate = (date, customOptions) => {
const options = { const options = {
year: "numeric", year: "numeric",
@@ -51,7 +68,7 @@ export const formatDate = (date, customOptions) => {
hour: "numeric", hour: "numeric",
minute: "numeric", minute: "numeric",
hour12: true, hour12: true,
...customOptions ...customOptions,
}; };
// Return the date using the specified options // Return the date using the specified options