Refactor FE to make proper use of date

This commit is contained in:
Alex Holliday committed 2024-10-16 11:45:05 +08:00
1 parent 7b8e5a1870
commit 6753446387
1 file changed
+37 -32
+37 -32
View File
@@ -13,10 +13,7 @@ import { useSelector } from "react-redux";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { networkService } from "../../../main"; import { networkService } from "../../../main";
import { logger } from "../../../Utils/Logger"; import { logger } from "../../../Utils/Logger";
import { import { formatDurationRounded, formatDurationSplit } from "../../../Utils/timeUtils";
formatDurationRounded,
formatDurationSplit,
} 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";
import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react";
@@ -93,14 +90,9 @@ const DetailsPage = ({ isAdmin }) => {
authToken: authToken, authToken: authToken,
monitorId: monitorId, monitorId: monitorId,
}); });
if (res?.data?.data?.certificateDate) { if (res?.data?.data?.certificateDate) {
let [month, day, year] = res.data.data.certificateDate.split("/"); const date = res.data.data.certificateDate;
const date = new Date(year, month - 1, day); setCertificateExpiry(formatDateWithTz(date, dateFormat, uiTimezone) ?? "N/A");
setCertificateExpiry(
formatDateWithTz(date, dateFormat, uiTimezone) ?? "N/A"
);
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@@ -136,10 +128,19 @@ const DetailsPage = ({ isAdmin }) => {
{ name: "details", path: `/monitors/${monitorId}` }, { name: "details", path: `/monitors/${monitorId}` },
]} ]}
/> />
<Stack gap={theme.spacing(10)} mt={theme.spacing(10)}> <Stack
<Stack direction="row" gap={theme.spacing(2)}> gap={theme.spacing(10)}
mt={theme.spacing(10)}
>
<Stack
direction="row"
gap={theme.spacing(2)}
>
<Box> <Box>
<Typography component="h1" variant="h1"> <Typography
component="h1"
variant="h1"
>
{monitor.name} {monitor.name}
</Typography> </Typography>
<Stack <Stack
@@ -168,7 +169,10 @@ const DetailsPage = ({ isAdmin }) => {
<PulseDot color={statusColor[determineState(monitor)]} /> <PulseDot color={statusColor[determineState(monitor)]} />
</Box> </Box>
</Tooltip> </Tooltip>
<Typography component="h2" variant="h2"> <Typography
component="h2"
variant="h2"
>
{monitor.url?.replace(/^https?:\/\//, "") || "..."} {monitor.url?.replace(/^https?:\/\//, "") || "..."}
</Typography> </Typography>
<Typography <Typography
@@ -273,12 +277,13 @@ const DetailsPage = ({ isAdmin }) => {
)} )}
</Stack> </Stack>
</Stack> </Stack>
<Stack direction="row" gap={theme.spacing(8)}> <Stack
direction="row"
gap={theme.spacing(8)}
>
<StatBox sx={statusStyles[determineState(monitor)]}> <StatBox sx={statusStyles[determineState(monitor)]}>
<Typography component="h2">active for</Typography> <Typography component="h2">active for</Typography>
<Typography> <Typography>{splitDuration(monitor?.uptimeDuration)}</Typography>
{splitDuration(monitor?.uptimeDuration)}
</Typography>
</StatBox> </StatBox>
<StatBox> <StatBox>
<Typography component="h2">last check</Typography> <Typography component="h2">last check</Typography>
@@ -336,7 +341,11 @@ const DetailsPage = ({ isAdmin }) => {
</Button> </Button>
</ButtonGroup> </ButtonGroup>
</Stack> </Stack>
<Stack direction="row" flexWrap="wrap" gap={theme.spacing(8)}> <Stack
direction="row"
flexWrap="wrap"
gap={theme.spacing(8)}
>
<ChartBox> <ChartBox>
<Stack> <Stack>
<IconBox> <IconBox>
@@ -352,8 +361,7 @@ const DetailsPage = ({ isAdmin }) => {
? hoveredUptimeData.totalChecks ? hoveredUptimeData.totalChecks
: monitor?.periodTotalChecks} : monitor?.periodTotalChecks}
</Typography> </Typography>
{hoveredUptimeData !== null && {hoveredUptimeData !== null && hoveredUptimeData.time !== null && (
hoveredUptimeData.time !== null && (
<Typography <Typography
component="h5" component="h5"
position="absolute" position="absolute"
@@ -373,9 +381,7 @@ const DetailsPage = ({ isAdmin }) => {
<Typography>Uptime Percentage</Typography> <Typography>Uptime Percentage</Typography>
<Typography component="span"> <Typography component="span">
{hoveredUptimeData !== null {hoveredUptimeData !== null
? Math.floor( ? Math.floor(hoveredUptimeData.uptimePercentage * 10) / 10
hoveredUptimeData.uptimePercentage * 10
) / 10
: Math.floor(monitor?.periodUptime * 10) / 10} : Math.floor(monitor?.periodUptime * 10) / 10}
<Typography component="span">%</Typography> <Typography component="span">%</Typography>
</Typography> </Typography>
@@ -429,24 +435,23 @@ const DetailsPage = ({ isAdmin }) => {
<IconBox> <IconBox>
<AverageResponseIcon /> <AverageResponseIcon />
</IconBox> </IconBox>
<Typography component="h2"> <Typography component="h2">Average Response Time</Typography>
Average Response Time
</Typography>
</Stack> </Stack>
<ResponseGaugeChart <ResponseGaugeChart
data={[{ response: monitor?.periodAvgResponseTime }]} data={[{ response: monitor?.periodAvgResponseTime }]}
/> />
</ChartBox> </ChartBox>
<ChartBox sx={{ padding: 0 }}> <ChartBox sx={{ padding: 0 }}>
<Stack pt={theme.spacing(8)} pl={theme.spacing(8)}> <Stack
pt={theme.spacing(8)}
pl={theme.spacing(8)}
>
<IconBox> <IconBox>
<ResponseTimeIcon /> <ResponseTimeIcon />
</IconBox> </IconBox>
<Typography component="h2">Response Times</Typography> <Typography component="h2">Response Times</Typography>
</Stack> </Stack>
<MonitorDetailsAreaChart <MonitorDetailsAreaChart checks={[...monitor.checks].reverse()} />
checks={[...monitor.checks].reverse()}
/>
</ChartBox> </ChartBox>
<ChartBox <ChartBox
gap={theme.spacing(8)} gap={theme.spacing(8)}