cleaned up code and refactored code to not have a default sort on load
This commit is contained in:
commit
0e8691b580
15 files changed
+232
-198
No files matched your search
@@ -72,7 +72,7 @@
|
||||
}
|
||||
|
||||
.MuiPaper-root + .MuiPagination-root {
|
||||
margin-top: 35px;
|
||||
margin-top: 24px;
|
||||
border: solid 1px var(--env-var-color-16);
|
||||
border-radius: var(--env-var-radius-1);
|
||||
padding: var(--env-var-spacing-1-plus) var(--env-var-spacing-2);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { BarChart, Bar, Cell, ReferenceLine, Label } from "recharts";
|
||||
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
const MonitorDetails60MinChart = ({ data }) => {
|
||||
const labelStyle = {
|
||||
fontSize: "10px",
|
||||
fill: "#475467",
|
||||
};
|
||||
|
||||
const color = {
|
||||
true: "var(--env-var-color-23)",
|
||||
false: "var(--env-var-color-24)",
|
||||
undefined: "var(--env-var-color-33)",
|
||||
};
|
||||
return (
|
||||
<BarChart
|
||||
width={data.length * 10 + 30}
|
||||
height={35}
|
||||
data={data}
|
||||
margin={{ top: 14, left: 15, right: 15, bottom: 2 }}
|
||||
style={{ alignSelf: "baseline" }}
|
||||
>
|
||||
<Bar dataKey="value" barSize={10}>
|
||||
{data.map((check, index) => (
|
||||
<Cell key={`cell-${index}`} fill={color[check.status]} />
|
||||
))}
|
||||
</Bar>
|
||||
<ReferenceLine x={0} stroke="black" strokeDasharray="3 3">
|
||||
<Label value="60 mins" position="top" style={labelStyle} />
|
||||
</ReferenceLine>
|
||||
<ReferenceLine
|
||||
x={Math.floor(data.length * (2 / 3))}
|
||||
stroke="black"
|
||||
strokeDasharray="3 3"
|
||||
>
|
||||
<Label value="20 mins" position="top" style={labelStyle} />
|
||||
</ReferenceLine>
|
||||
<ReferenceLine x={data.length - 1} stroke="black" strokeDasharray="3 3">
|
||||
<Label value="now" position="top" style={labelStyle} />
|
||||
</ReferenceLine>
|
||||
</BarChart>
|
||||
);
|
||||
};
|
||||
|
||||
MonitorDetails60MinChart.propTypes = {
|
||||
data: PropTypes.array.isRequired,
|
||||
};
|
||||
|
||||
export default MonitorDetails60MinChart;
|
||||
@@ -28,15 +28,6 @@ const CustomToolTip = ({ active, payload, label }) => {
|
||||
};
|
||||
|
||||
const MonitorDetailsAreaChart = ({ checks }) => {
|
||||
// SQUASH ERROR, NOT PERMANENT SOLUTION
|
||||
const error = console.error;
|
||||
console.error = (...args) => {
|
||||
if (/defaultProps/.test(args[0])) return;
|
||||
error(...args);
|
||||
};
|
||||
|
||||
// END SQUASH ERROR, NOT PERMANENT SOLUTION
|
||||
|
||||
const formatDate = (timestamp) => {
|
||||
const date = new Date(timestamp);
|
||||
return date.toLocaleTimeString("en-US", {
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
color: var(--env-var-color-1);
|
||||
font-weight: 600;
|
||||
}
|
||||
.monitor-details h2.MuiTypography-root,
|
||||
.monitor-details h6.MuiTypography-root {
|
||||
.monitor-details h2.MuiTypography-root {
|
||||
font-size: var(--env-var-font-size-large);
|
||||
}
|
||||
.monitor-details h2.MuiTypography-root,
|
||||
.monitor-details h4.MuiTypography-root {
|
||||
.monitor-details h2.MuiTypography-root{
|
||||
font-weight: 600;
|
||||
}
|
||||
.monitor-details h2.MuiTypography-root,
|
||||
@@ -35,15 +33,21 @@
|
||||
}
|
||||
|
||||
.monitor-details .stat-box {
|
||||
flex: 1;
|
||||
flex: 1 20%;
|
||||
min-width: 100px;
|
||||
border: solid 1px;
|
||||
border-radius: var(--env-var-radius-1);
|
||||
padding: var(--env-var-spacing-1) 18px;
|
||||
padding: var(--env-var-spacing-1) 16px;
|
||||
background-color: var(--env-var-color-8);
|
||||
}
|
||||
.monitor-details .stat-box h6.MuiTypography-root {
|
||||
margin-bottom: var(--env-var-spacing-1);
|
||||
.monitor-details h6.MuiTypography-root {
|
||||
font-size: var(--env-var-font-size-medium-plus);
|
||||
}
|
||||
.monitor-details h6.MuiTypography-root span.MuiTypography-root {
|
||||
font-style: italic;
|
||||
font-size: var(--env-var-font-size-medium);
|
||||
color: var(--env-var-color-5);
|
||||
opacity: 0.7;
|
||||
}
|
||||
.monitor-details button.MuiButtonBase-root,
|
||||
.monitor-details .stat-box {
|
||||
|
||||
@@ -17,20 +17,23 @@ import {
|
||||
formatDurationRounded,
|
||||
} from "../../../Utils/timeUtils";
|
||||
import "./index.css";
|
||||
import MonitorDetails60MinChart from "../../../Components/Charts/MonitorDetails60MinChart";
|
||||
|
||||
const StatBox = ({ title, value }) => {
|
||||
return (
|
||||
<Box className="stat-box">
|
||||
<Typography variant="h6" sx={{ fontWeight: 400 }}>
|
||||
<Typography variant="h6" mb={1} fontWeight={500}>
|
||||
{title}
|
||||
</Typography>
|
||||
<Typography variant="h4">{value}</Typography>
|
||||
<Typography variant="h4" fontWeight={500}>
|
||||
{value}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
StatBox.propTypes = {
|
||||
title: PropTypes.string,
|
||||
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
};
|
||||
|
||||
@@ -162,12 +165,12 @@ const DetailsPage = () => {
|
||||
<>
|
||||
<Button
|
||||
level="tertiary"
|
||||
label="Back to Monitors"
|
||||
label="Back"
|
||||
animate="slideLeft"
|
||||
img={<WestRoundedIcon />}
|
||||
onClick={() => navigate("/monitors")}
|
||||
sx={{
|
||||
backgroundColor: "#f4f4f4",
|
||||
backgroundColor: theme.palette.otherColors.fillGray,
|
||||
px: theme.gap.ml,
|
||||
"& svg.MuiSvgIcon-root": {
|
||||
mr: theme.gap.small,
|
||||
@@ -176,12 +179,23 @@ const DetailsPage = () => {
|
||||
}}
|
||||
/>
|
||||
<Stack gap={theme.gap.xl} mt={theme.gap.medium}>
|
||||
<Stack direction="row" gap={theme.gap.small} mt={theme.gap.small}>
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={theme.gap.small}
|
||||
mt={theme.gap.small}
|
||||
alignItems="baseline"
|
||||
>
|
||||
{monitor?.status ? <GreenCheck /> : <RedCheck />}
|
||||
<Box>
|
||||
<Typography component="h1" sx={{ lineHeight: 1 }}>
|
||||
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
||||
</Typography>
|
||||
<Stack direction="row">
|
||||
<Typography
|
||||
component="h1"
|
||||
sx={{ lineHeight: 1, alignSelf: "flex-end" }}
|
||||
>
|
||||
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
|
||||
</Typography>
|
||||
<MonitorDetails60MinChart data={monitor.statusBar} />
|
||||
</Stack>
|
||||
<Typography mt={theme.gap.small}>
|
||||
<Typography
|
||||
component="span"
|
||||
@@ -194,8 +208,6 @@ const DetailsPage = () => {
|
||||
Your site is {monitor?.status ? "up" : "down"}.
|
||||
</Typography>{" "}
|
||||
Checking every {formatDurationRounded(monitor?.interval)}.
|
||||
Last time checked{" "}
|
||||
{formatDurationRounded(monitor?.lastChecked)} ago.
|
||||
</Typography>
|
||||
</Box>
|
||||
<Button
|
||||
@@ -226,41 +238,49 @@ const DetailsPage = () => {
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
gap={theme.gap.large}
|
||||
flexWrap="wrap"
|
||||
>
|
||||
<StatBox
|
||||
title="Currently up for"
|
||||
value={formatDuration(monitor?.uptimeDuration)}
|
||||
/>
|
||||
<StatBox
|
||||
title="Last checked"
|
||||
value={`${formatDuration(monitor?.lastChecked)} ago`}
|
||||
title="Last check"
|
||||
value={`${formatDurationRounded(monitor?.lastChecked)} ago`}
|
||||
/>
|
||||
<StatBox title="Incidents" value={monitor?.incidents} />
|
||||
<StatBox title="Certificate Expiry" value={certificateExpiry} />
|
||||
</Stack>
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="space-between"
|
||||
gap={theme.gap.large}
|
||||
>
|
||||
<StatBox
|
||||
title="Latest response time"
|
||||
value={monitor?.latestResponseTime}
|
||||
/>
|
||||
<StatBox
|
||||
title="Average Repsonse Time (24 hours)"
|
||||
title={
|
||||
<>
|
||||
Avg. Response Time{" "}
|
||||
<Typography component="span">(24-hr)</Typography>
|
||||
</>
|
||||
}
|
||||
value={parseFloat(monitor?.avgResponseTime24hours)
|
||||
.toFixed(2)
|
||||
.replace(/\.?0+$/, "")}
|
||||
/>
|
||||
<StatBox
|
||||
title="Uptime (24 hours)"
|
||||
title={
|
||||
<>
|
||||
Uptime <Typography component="span">(24-hr)</Typography>
|
||||
</>
|
||||
}
|
||||
value={`${parseFloat(monitor?.uptime24Hours)
|
||||
.toFixed(2)
|
||||
.replace(/\.?0+$/, "")}%`}
|
||||
/>
|
||||
<StatBox
|
||||
title="Uptime(30 days)"
|
||||
title={
|
||||
<>
|
||||
Uptime <Typography component="span">(30-day)</Typography>
|
||||
</>
|
||||
}
|
||||
value={`${parseFloat(monitor?.uptime30Days)
|
||||
.toFixed(2)
|
||||
.replace(/\.?0+$/, "")}%`}
|
||||
@@ -272,7 +292,7 @@ const DetailsPage = () => {
|
||||
justifyContent="space-between"
|
||||
mb={theme.gap.ml}
|
||||
>
|
||||
<Typography component="h2" mb={theme.gap.small}>
|
||||
<Typography component="h2" alignSelf="flex-end">
|
||||
Response Times
|
||||
</Typography>
|
||||
<ButtonGroup>
|
||||
@@ -308,7 +328,15 @@ const DetailsPage = () => {
|
||||
/>
|
||||
</ButtonGroup>
|
||||
</Stack>
|
||||
<Box sx={{ height: "200px" }}>
|
||||
<Box
|
||||
p={theme.gap.mlplus}
|
||||
pb={theme.gap.xs}
|
||||
backgroundColor={theme.palette.otherColors.white}
|
||||
border={1}
|
||||
borderColor={theme.palette.otherColors.graishWhite}
|
||||
borderRadius={`${theme.shape.borderRadius}px`}
|
||||
sx={{ height: "250px" }}
|
||||
>
|
||||
<MonitorDetailsAreaChart
|
||||
checks={[...monitor.checks].reverse()}
|
||||
/>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useNavigate } from "react-router-dom";
|
||||
import Button from "../../Components/Button";
|
||||
import ServerStatus from "../../Components/Charts/Servers/ServerStatus";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
|
||||
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
|
||||
import OpenInNewPage from "../../assets/icons/open-in-new-page.svg?react";
|
||||
import Settings from "../../assets/icons/settings-bold.svg?react";
|
||||
@@ -152,17 +153,38 @@ const Monitors = () => {
|
||||
|
||||
const down = monitorState.monitors.length - up;
|
||||
|
||||
// State variable for sorting -> default of 1 for ascending
|
||||
const [sortOrder, setSortOrder] = useState(1);
|
||||
// State variable for updating sorting of default monitors
|
||||
const [sortedMonitors, setSortedMonitors] = useState(monitorState.monitors);
|
||||
// Bool for sorting arrow
|
||||
const [isSorted, setIsSorted] = useState(false);
|
||||
|
||||
|
||||
// Function to handle sorting on click of status text
|
||||
const handleSort = () => {
|
||||
setSortOrder(prevOrder => prevOrder * -1);
|
||||
|
||||
// Sort existing monitors with start of ascending order
|
||||
const monitors = [...monitorState.monitors].sort(a => {
|
||||
return a.status ? -1 * sortOrder : 1 * sortOrder;
|
||||
});
|
||||
|
||||
// Update state of monitors
|
||||
setSortedMonitors(monitors);
|
||||
// Trigger arrow visibility and direction
|
||||
setIsSorted(true);
|
||||
};
|
||||
|
||||
const data = {
|
||||
cols: [
|
||||
{ id: 1, name: "Host" },
|
||||
{
|
||||
id: 2,
|
||||
name: (
|
||||
<Box width="max-content">
|
||||
<Box width="max-content" onClick={handleSort} style={{ cursor: "pointer" }}>
|
||||
Status
|
||||
<span>
|
||||
<ArrowDownwardRoundedIcon />
|
||||
</span>
|
||||
{isSorted ? <span>{sortOrder === -1 ? <ArrowUpwardRoundedIcon /> : <ArrowDownwardRoundedIcon />}</span> : null}
|
||||
</Box>
|
||||
),
|
||||
},
|
||||
@@ -173,7 +195,8 @@ const Monitors = () => {
|
||||
rows: [],
|
||||
};
|
||||
|
||||
data.rows = monitorState.monitors.map((monitor, idx) => {
|
||||
// Render out sorted monitors/default monitors
|
||||
data.rows = sortedMonitors.map((monitor, idx) => {
|
||||
const params = {
|
||||
url: monitor.url,
|
||||
title: monitor.name,
|
||||
|
||||
@@ -299,7 +299,7 @@ const PageSpeedDetails = () => {
|
||||
const [expand, setExpand] = useState(false);
|
||||
|
||||
let loading = Object.keys(monitor).length === 0;
|
||||
|
||||
const data = monitor?.checks ? [...monitor.checks].reverse() : [];
|
||||
return (
|
||||
<Stack className="page-speed-details" gap={theme.gap.large}>
|
||||
{loading ? (
|
||||
@@ -406,7 +406,7 @@ const PageSpeedDetails = () => {
|
||||
</Stack>
|
||||
<Typography component="h2">Score history</Typography>
|
||||
<Box height="300px">
|
||||
<PageSpeedLineChart pageSpeedChecks={monitor?.checks?.reverse()} />
|
||||
<PageSpeedLineChart pageSpeedChecks={data} />
|
||||
</Box>
|
||||
<Typography component="h2">Performance report</Typography>
|
||||
<Stack direction="row" alignItems="center" overflow="hidden" flex={1}>
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
--env-var-color-30: #fcfcfd;
|
||||
--env-var-color-31: #1a1919;
|
||||
--env-var-color-32: #f5f5f5;
|
||||
--env-var-color-33: rgba(83, 83, 83, 0.1);
|
||||
|
||||
--env-var-radius-1: 4px;
|
||||
--env-var-radius-2: 8px;
|
||||
|
||||
Reference in new issue
Block a user