-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fe/uptime details refactor #1648
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94084ac
iniital commit
ajhollid 08d1a85
Add certificate expiry hook
ajhollid 66e61fc
Add Dot component
ajhollid 5622b3b
use dayjs to parse dates
ajhollid 9381429
Use Dot component in host
ajhollid 674c12a
Consistent spacing in home page
ajhollid 671d297
refactor details
ajhollid 36d46c2
Add pagination label to prop types
ajhollid cb0ec0e
finish refactor
ajhollid b209567
Add missing prop validation, cleanup
ajhollid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import PropTypes from "prop-types"; | ||
|
||
const Dot = ({ color = "gray", size = "4px" }) => { | ||
return ( | ||
<span | ||
style={{ | ||
content: '""', | ||
width: size, | ||
height: size, | ||
borderRadius: "50%", | ||
backgroundColor: color, | ||
opacity: 0.8, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
Dot.propTypes = { | ||
color: PropTypes.string, | ||
size: PropTypes.string, | ||
}; | ||
|
||
export default Dot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
Client/src/Pages/Uptime/Details/Components/ChartBoxes/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Components | ||
import { Stack, Typography, Box } from "@mui/material"; | ||
import ChartBox from "../Charts/ChartBox"; | ||
import UptimeIcon from "../../../../../assets/icons/uptime-icon.svg?react"; | ||
import IncidentsIcon from "../../../../../assets/icons/incidents.svg?react"; | ||
import AverageResponseIcon from "../../../../../assets/icons/average-response-icon.svg?react"; | ||
import UpBarChart from "../Charts/UpBarChart"; | ||
import DownBarChart from "../Charts/DownBarChart"; | ||
import ResponseGaugeChart from "../Charts/ResponseGaugeChart"; | ||
import SkeletonLayout from "./skeleton"; | ||
// Utils | ||
import { formatDateWithTz } from "../../../../../Utils/timeUtils"; | ||
import PropTypes from "prop-types"; | ||
import { useTheme } from "@emotion/react"; | ||
|
||
const ChartBoxes = ({ | ||
shouldRender = true, | ||
monitor, | ||
dateRange, | ||
uiTimezone, | ||
dateFormat, | ||
hoveredUptimeData, | ||
setHoveredUptimeData, | ||
hoveredIncidentsData, | ||
setHoveredIncidentsData, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
if (!shouldRender) { | ||
return <SkeletonLayout />; | ||
} | ||
|
||
return ( | ||
<Stack | ||
direction="row" | ||
flexWrap="wrap" | ||
gap={theme.spacing(8)} | ||
> | ||
<ChartBox | ||
icon={<UptimeIcon />} | ||
header="Uptime" | ||
> | ||
<Stack justifyContent="space-between"> | ||
<Box position="relative"> | ||
<Typography>Total Checks</Typography> | ||
<Typography component="span"> | ||
{hoveredUptimeData !== null | ||
? hoveredUptimeData.totalChecks | ||
: (monitor?.groupedUpChecks?.reduce((count, checkGroup) => { | ||
return count + checkGroup.totalChecks; | ||
}, 0) ?? 0)} | ||
</Typography> | ||
{hoveredUptimeData !== null && hoveredUptimeData.time !== null && ( | ||
<Typography | ||
component="h5" | ||
position="absolute" | ||
top="100%" | ||
fontSize={11} | ||
color={theme.palette.primary.contrastTextTertiary} | ||
> | ||
{formatDateWithTz(hoveredUptimeData._id, dateFormat, uiTimezone)} | ||
</Typography> | ||
)} | ||
</Box> | ||
<Box> | ||
<Typography> | ||
{hoveredUptimeData !== null ? "Avg Response Time" : "Uptime Percentage"} | ||
</Typography> | ||
<Typography component="span"> | ||
{hoveredUptimeData !== null | ||
? Math.floor(hoveredUptimeData?.avgResponseTime ?? 0) | ||
: Math.floor( | ||
((monitor?.upChecks?.totalChecks ?? 0) / | ||
(monitor?.totalChecks ?? 1)) * | ||
100 | ||
)} | ||
<Typography component="span"> | ||
{hoveredUptimeData !== null ? " ms" : " %"} | ||
</Typography> | ||
</Typography> | ||
</Box> | ||
</Stack> | ||
<UpBarChart | ||
monitor={monitor} | ||
type={dateRange} | ||
onBarHover={setHoveredUptimeData} | ||
/> | ||
</ChartBox> | ||
<ChartBox | ||
icon={<IncidentsIcon />} | ||
header="Incidents" | ||
> | ||
<Box position="relative"> | ||
<Typography component="span"> | ||
{hoveredIncidentsData !== null | ||
? hoveredIncidentsData.totalChecks | ||
: (monitor?.groupedDownChecks?.reduce((count, checkGroup) => { | ||
return count + checkGroup.totalChecks; | ||
}, 0) ?? 0)} | ||
</Typography> | ||
{hoveredIncidentsData !== null && hoveredIncidentsData.time !== null && ( | ||
<Typography | ||
component="h5" | ||
position="absolute" | ||
top="100%" | ||
fontSize={11} | ||
color={theme.palette.primary.contrastTextTertiary} | ||
> | ||
{formatDateWithTz(hoveredIncidentsData._id, dateFormat, uiTimezone)} | ||
</Typography> | ||
)} | ||
</Box> | ||
<DownBarChart | ||
monitor={monitor} | ||
type={dateRange} | ||
onBarHover={setHoveredIncidentsData} | ||
/> | ||
</ChartBox> | ||
<ChartBox | ||
icon={<AverageResponseIcon />} | ||
header="Average Response Time" | ||
> | ||
<ResponseGaugeChart avgResponseTime={monitor.avgResponseTime ?? 0} /> | ||
</ChartBox> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ChartBoxes; | ||
|
||
ChartBoxes.propTypes = { | ||
monitor: PropTypes.object.isRequired, | ||
dateRange: PropTypes.string.isRequired, | ||
uiTimezone: PropTypes.string.isRequired, | ||
dateFormat: PropTypes.string.isRequired, | ||
hoveredUptimeData: PropTypes.object, | ||
setHoveredUptimeData: PropTypes.func, | ||
hoveredIncidentsData: PropTypes.object, | ||
setHoveredIncidentsData: PropTypes.func, | ||
}; |
30 changes: 30 additions & 0 deletions
30
Client/src/Pages/Uptime/Details/Components/ChartBoxes/skeleton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Skeleton, Stack } from "@mui/material"; | ||
import { useTheme } from "@emotion/react"; | ||
|
||
const SkeletonLayout = () => { | ||
const theme = useTheme(); | ||
return ( | ||
<Stack | ||
direction="row" | ||
gap={theme.spacing(8)} | ||
> | ||
<Skeleton | ||
variant="rounded" | ||
width="100%" | ||
height={300} | ||
/> | ||
<Skeleton | ||
variant="rounded" | ||
width="100%" | ||
height={300} | ||
/> | ||
<Skeleton | ||
variant="rounded" | ||
width="100%" | ||
height={300} | ||
/> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default SkeletonLayout; |
75 changes: 75 additions & 0 deletions
75
Client/src/Pages/Uptime/Details/Components/Charts/ChartBox.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Stack, Typography } from "@mui/material"; | ||
import { useTheme } from "@emotion/react"; | ||
import IconBox from "../../../../../Components/IconBox"; | ||
import PropTypes from "prop-types"; | ||
const ChartBox = ({ children, icon, header, height = "300px" }) => { | ||
const theme = useTheme(); | ||
return ( | ||
<Stack | ||
sx={{ | ||
justifyContent: "space-between", | ||
flex: "1 30%", | ||
gap: theme.spacing(8), | ||
height, | ||
minWidth: 250, | ||
padding: theme.spacing(8), | ||
border: 1, | ||
borderStyle: "solid", | ||
borderColor: theme.palette.primary.lowContrast, | ||
borderRadius: 4, | ||
backgroundColor: theme.palette.primary.main, | ||
"& h2": { | ||
color: theme.palette.primary.contrastTextSecondary, | ||
fontSize: 15, | ||
fontWeight: 500, | ||
}, | ||
"& .MuiBox-root:not(.area-tooltip) p": { | ||
color: theme.palette.primary.contrastTextTertiary, | ||
fontSize: 13, | ||
}, | ||
"& .MuiBox-root > span": { | ||
color: theme.palette.primary.contrastText, | ||
fontSize: 20, | ||
"& span": { | ||
opacity: 0.8, | ||
marginLeft: 2, | ||
fontSize: 15, | ||
}, | ||
}, | ||
"& .MuiStack-root": { | ||
flexDirection: "row", | ||
gap: theme.spacing(6), | ||
}, | ||
"& .MuiStack-root:first-of-type": { | ||
alignItems: "center", | ||
}, | ||
"& tspan, & text": { | ||
fill: theme.palette.primary.contrastTextTertiary, | ||
}, | ||
"& path": { | ||
transition: "fill 300ms ease, stroke-width 400ms ease", | ||
}, | ||
}} | ||
> | ||
<Stack | ||
direction="row" | ||
alignItems="center" | ||
gap={theme.spacing(2)} | ||
> | ||
<IconBox>{icon}</IconBox> | ||
<Typography component="h2">{header}</Typography> | ||
</Stack> | ||
|
||
{children} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ChartBox; | ||
|
||
ChartBox.propTypes = { | ||
children: PropTypes.node, | ||
icon: PropTypes.node.isRequired, | ||
header: PropTypes.string.isRequired, | ||
height: PropTypes.string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
Client/src/Pages/Uptime/Details/Components/Charts/ResponseTimeChart.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import ChartBox from "./ChartBox"; | ||
import MonitorDetailsAreaChart from "../../../../../Components/Charts/MonitorDetailsAreaChart"; | ||
import ResponseTimeIcon from "../../../../../assets/icons/response-time-icon.svg?react"; | ||
import SkeletonLayout from "./ResponseTimeChartSkeleton"; | ||
import PropTypes from "prop-types"; | ||
|
||
const ResponseTImeChart = ({ shouldRender = true, monitor, dateRange }) => { | ||
if (!shouldRender) { | ||
return <SkeletonLayout />; | ||
} | ||
|
||
return ( | ||
<ChartBox | ||
icon={<ResponseTimeIcon />} | ||
header="Response Times" | ||
> | ||
<MonitorDetailsAreaChart | ||
checks={monitor.groupedChecks ?? []} | ||
dateRange={dateRange} | ||
/> | ||
</ChartBox> | ||
); | ||
}; | ||
|
||
ResponseTImeChart.propTypes = { | ||
shouldRender: PropTypes.bool, | ||
monitor: PropTypes.object, | ||
dateRange: PropTypes.string, | ||
}; | ||
|
||
export default ResponseTImeChart; |
12 changes: 12 additions & 0 deletions
12
Client/src/Pages/Uptime/Details/Components/Charts/ResponseTimeChartSkeleton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Skeleton } from "@mui/material"; | ||
const ResponseTimeChartSkeleton = () => { | ||
return ( | ||
<Skeleton | ||
variant="rounded" | ||
width="100%" | ||
height={300} | ||
/> | ||
); | ||
}; | ||
|
||
export default ResponseTimeChartSkeleton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo dawg, there's a typo in your component name!
The component name has "TIme" instead of "Time" - this inconsistency could make it harder to import and use the component correctly.
📝 Committable suggestion