Revamped stat boxes and header

This commit is contained in:
Daniel Cojocea committed 2024-09-10 12:39:19 -04:00
1 parent b0fc2023d9
commit bf09a9568a
5 files changed
+145 -113

No files matched your search

@@ -76,6 +76,7 @@ export const StatBox = styled(Box)(({ theme }) => ({
borderColor: theme.palette.border.light, borderColor: theme.palette.border.light,
borderRadius: 4, borderRadius: 4,
backgroundColor: theme.palette.background.main, backgroundColor: theme.palette.background.main,
background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 35%)`,
"& h2": { "& h2": {
fontSize: 13, fontSize: 13,
fontWeight: 500, fontWeight: 500,
+6 -2
View File
@@ -23,22 +23,26 @@ const useUtils = () => {
const statusStyles = { const statusStyles = {
up: { up: {
backgroundColor: theme.palette.success.bg, backgroundColor: theme.palette.success.bg,
background: `linear-gradient(340deg, ${theme.palette.success.light} -60%, ${theme.palette.success.bg} 35%)`,
borderColor: theme.palette.success.light, borderColor: theme.palette.success.light,
"& h2": { color: theme.palette.success.main }, "& h2": { color: theme.palette.success.main },
}, },
down: { down: {
backgroundColor: theme.palette.error.bg, backgroundColor: theme.palette.error.bg,
background: `linear-gradient(340deg, ${theme.palette.error.light} -60%, ${theme.palette.error.bg} 35%)`,
borderColor: theme.palette.error.light, borderColor: theme.palette.error.light,
"& h2": { color: theme.palette.error.main }, "& h2": { color: theme.palette.error.main },
}, },
paused: { paused: {
backgroundColor: theme.palette.warning.light, backgroundColor: theme.palette.warning.light,
borderColor: theme.palette.warning.border, background: `linear-gradient(340deg, ${theme.palette.warning.dark} -60%, ${theme.palette.warning.light} 35%)`,
borderColor: theme.palette.warning.dark,
"& h2": { color: theme.palette.warning.main }, "& h2": { color: theme.palette.warning.main },
}, },
pending: { pending: {
backgroundColor: theme.palette.warning.light, backgroundColor: theme.palette.warning.light,
borderColor: theme.palette.warning.border, background: `linear-gradient(340deg, ${theme.palette.warning.dark} -60%, ${theme.palette.warning.light} 35%)`,
borderColor: theme.palette.warning.dark,
"& h2": { color: theme.palette.warning.main }, "& h2": { color: theme.palette.warning.main },
}, },
}; };
@@ -1,12 +1,7 @@
.page-speed-details h1 {
font-size: var(--env-var-font-size-large-plus);
}
.page-speed-details h2,
.page-speed-details h6 { .page-speed-details h6 {
font-size: var(--env-var-font-size-large); font-size: var(--env-var-font-size-large);
} }
.page-speed-details h4, .page-speed-details h4,
.page-speed-details p,
.page-speed-details p > span { .page-speed-details p > span {
font-size: var(--env-var-font-size-medium); font-size: var(--env-var-font-size-medium);
} }
@@ -17,8 +12,6 @@
.page-speed-details h6 { .page-speed-details h6 {
line-height: 22px; line-height: 22px;
} }
.page-speed-details h1,
.page-speed-details h2,
.page-speed-details h6 { .page-speed-details h6 {
font-weight: 600; font-weight: 600;
} }
+109 -104
View File
@@ -1,5 +1,13 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { Box, Button, Skeleton, Stack, Typography } from "@mui/material"; import {
Box,
Button,
Skeleton,
Stack,
Toolbar,
Tooltip,
Typography,
} from "@mui/material";
import { PieChart } from "@mui/x-charts/PieChart"; import { PieChart } from "@mui/x-charts/PieChart";
import { useDrawingArea } from "@mui/x-charts"; import { useDrawingArea } from "@mui/x-charts";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
@@ -9,7 +17,9 @@ import { useSelector } from "react-redux";
import { import {
formatDuration, formatDuration,
formatDurationRounded, formatDurationRounded,
formatDurationSplit,
} from "../../../Utils/timeUtils"; } from "../../../Utils/timeUtils";
import { StatBox } from "./styled";
import { logger } from "../../../Utils/Logger"; import { logger } from "../../../Utils/Logger";
import { networkService } from "../../../main"; import { networkService } from "../../../main";
import SettingsIcon from "../../../assets/icons/settings-bold.svg?react"; import SettingsIcon from "../../../assets/icons/settings-bold.svg?react";
@@ -21,46 +31,6 @@ import Breadcrumbs from "../../../Components/Breadcrumbs";
import PulseDot from "../../../Components/Animated/PulseDot"; import PulseDot from "../../../Components/Animated/PulseDot";
import "./index.css"; import "./index.css";
const StatBox = ({ icon, title, value }) => {
const theme = useTheme();
return (
<Stack
className="stat-box"
direction="row"
gap={theme.spacing(4)}
pt={theme.spacing(8)}
px={theme.spacing(8)}
pb={theme.spacing(10)}
border={1}
borderColor={theme.palette.border.light}
borderRadius={theme.shape.borderRadius}
backgroundColor={theme.palette.background.main}
minWidth="200px"
>
{icon}
<Box>
<Typography
variant="h6"
color={theme.palette.primary.main}
mb={theme.spacing(6)}
>
{title}
</Typography>
<Typography variant="h4" color={theme.palette.text.secondary}>
{value}
</Typography>
</Box>
</Stack>
);
};
StatBox.propTypes = {
icon: PropTypes.element,
title: PropTypes.string,
value: PropTypes.node,
};
/** /**
* Renders a centered label within a pie chart. * Renders a centered label within a pie chart.
* *
@@ -356,8 +326,21 @@ const PageSpeedDetails = () => {
borderRadius: theme.shape.borderRadius, borderRadius: theme.shape.borderRadius,
backgroundColor: theme.palette.background.main, backgroundColor: theme.palette.background.main,
}; };
console.log(monitor);
const splitDuration = (duration) => {
const { time, format } = formatDurationSplit(duration);
return (
<>
{time}
<Typography component="span">{format}</Typography>
</>
);
};
return ( return (
<Stack className="page-speed-details" gap={theme.spacing(12)}> <Stack className="page-speed-details" gap={theme.spacing(10)}>
{loading ? ( {loading ? (
<SkeletonLayout /> <SkeletonLayout />
) : ( ) : (
@@ -369,32 +352,82 @@ const PageSpeedDetails = () => {
]} ]}
/> />
<Stack direction="row" gap={theme.spacing(2)}> <Stack direction="row" gap={theme.spacing(2)}>
<PulseDot
color={
monitor?.status
? theme.palette.success.main
: theme.palette.error.main
}
/>
<Box> <Box>
<Typography <Typography
component="h1" component="h1"
mb={theme.spacing(2)} fontSize={22}
fontWeight={500}
color={theme.palette.text.primary} color={theme.palette.text.primary}
sx={{ lineHeight: 1 }}
> >
{monitor?.url} {monitor.name}
</Typography> </Typography>
<Typography <Stack
component="span" direction="row"
color={ alignItems="center"
monitor?.status height="fit-content"
? theme.palette.success.main gap={theme.spacing(2)}
: theme.palette.error.text
}
> >
Your pagespeed monitor is live. <Tooltip
</Typography> title={
monitor?.status
? "Your pagespeed monitor is live."
: "Your pagespeed monitor is down."
}
disableInteractive
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -8],
},
},
],
},
}}
>
<Box>
<PulseDot
color={
monitor?.status
? theme.palette.success.main
: theme.palette.error.main
}
/>
</Box>
</Tooltip>
<Typography
component="h2"
fontSize={14.5}
color={theme.palette.text.secondary}
>
{monitor?.url}
</Typography>
<Typography
mt={theme.spacing(1)}
ml={theme.spacing(6)}
fontSize={12}
position="relative"
color={theme.palette.text.tertiary}
sx={{
"&:before": {
position: "absolute",
content: `""`,
width: 4,
height: 4,
borderRadius: "50%",
backgroundColor: theme.palette.text.tertiary,
opacity: 0.8,
left: -9,
top: "50%",
transform: "translateY(-50%)",
},
}}
>
Checking every {formatDurationRounded(monitor?.interval)}.
</Typography>
</Stack>
</Box> </Box>
<Button <Button
variant="contained" variant="contained"
@@ -416,49 +449,21 @@ const PageSpeedDetails = () => {
Configure Configure
</Button> </Button>
</Stack> </Stack>
<Stack <Stack direction="row" gap={theme.spacing(8)}>
direction="row" <StatBox>
justifyContent="space-between" <Typography component="h2">checks since</Typography>
gap={theme.spacing(12)} <Typography>
flexWrap="wrap" {splitDuration(monitor?.uptimeDuration)}
> <Typography component="span">ago</Typography>
<StatBox </Typography>
icon={<LastCheckedIcon />} </StatBox>
title="Last checked" <StatBox>
value={ <Typography component="h2">last check</Typography>
<> <Typography>
{formatDuration(monitor?.lastChecked)}{" "} {splitDuration(monitor?.lastChecked)}
<Typography <Typography component="span">ago</Typography>
component="span" </Typography>
fontStyle="italic" </StatBox>
sx={{ opacity: 0.8 }}
>
ago
</Typography>
</>
}
/>
<StatBox
icon={<ClockIcon />}
title="Checks since"
value={
<>
{formatDuration(monitor?.uptimeDuration)}{" "}
<Typography
component="span"
fontStyle="italic"
sx={{ opacity: 0.8 }}
>
ago
</Typography>
</>
}
></StatBox>
<StatBox
icon={<IntervalCheckIcon />}
title="Checks every"
value={formatDurationRounded(monitor?.interval)}
></StatBox>
</Stack> </Stack>
<Typography component="h2" color={theme.palette.text.secondary}> <Typography component="h2" color={theme.palette.text.secondary}>
Score history Score history
@@ -0,0 +1,29 @@
import { Box, styled } from "@mui/material";
export const StatBox = styled(Box)(({ theme }) => ({
padding: `${theme.spacing(4)} ${theme.spacing(8)}`,
minWidth: 200,
width: 225,
border: 1,
borderStyle: "solid",
borderColor: theme.palette.border.light,
borderRadius: 4,
backgroundColor: theme.palette.background.main,
background: `linear-gradient(340deg, ${theme.palette.background.accent} 20%, ${theme.palette.background.main} 35%)`,
"& h2": {
fontSize: 13,
fontWeight: 500,
color: theme.palette.text.secondary,
textTransform: "uppercase",
},
"& p": {
fontSize: 18,
color: theme.palette.text.primary,
marginTop: theme.spacing(2),
"& span": {
color: theme.palette.text.tertiary,
marginLeft: theme.spacing(2),
fontSize: 15,
},
},
}));