add loading states, skeletons, fix map tooltip

This commit is contained in:
Alex Holliday committed 2025-02-07 15:54:19 -08:00
1 parent ea1a717ad0
commit d852388202
10 files changed
+205 -129

No files matched your search

@@ -73,9 +73,12 @@ const CustomToolTip = ({ active, payload, label, dateRange }) => {
component="span" component="span"
sx={{ opacity: 0.8 }} sx={{ opacity: 0.8 }}
> >
Response Time Response time:
</Typography>{" "} </Typography>
<Typography component="span"> <Typography
ml={theme.spacing(4)}
component="span"
>
{Math.floor(responseTime)} {Math.floor(responseTime)}
<Typography <Typography
component="span" component="span"
@@ -24,73 +24,70 @@ const CustomToolTip = ({ active, payload, label }) => {
? payload[0]?.payload?.originalAvgResponseTime ? payload[0]?.payload?.originalAvgResponseTime
: (payload[0]?.payload?.avgResponseTime ?? 0); : (payload[0]?.payload?.avgResponseTime ?? 0);
return ( return (
<ChartBox <Box
icon={<ResponseTimeIcon />} className="area-tooltip"
header="Response Times" sx={{
sx={{ padding: 0 }} backgroundColor: theme.palette.primary.main,
border: 1,
borderColor: theme.palette.primary.lowContrast,
borderRadius: theme.shape.borderRadius,
py: theme.spacing(2),
px: theme.spacing(4),
}}
> >
<Box <Typography
className="area-tooltip"
sx={{ sx={{
backgroundColor: theme.palette.background.main, color: theme.palette.text.tertiary,
border: 1, fontSize: 12,
borderColor: theme.palette.primary.lowContrast, fontWeight: 500,
borderRadius: theme.shape.borderRadius,
py: theme.spacing(2),
px: theme.spacing(4),
}} }}
> >
<Typography {formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)}
</Typography>
<Box mt={theme.spacing(1)}>
<Box
display="inline-block"
width={theme.spacing(4)}
height={theme.spacing(4)}
backgroundColor={theme.palette.primary.main}
sx={{ borderRadius: "50%" }}
/>
<Stack
display="inline-flex"
direction="row"
justifyContent="space-between"
ml={theme.spacing(3)}
sx={{ sx={{
color: theme.palette.text.tertiary, "& span": {
fontSize: 12, color: theme.palette.text.tertiary,
fontWeight: 500, fontSize: 11,
fontWeight: 500,
},
}} }}
> >
{formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)} <Typography
</Typography> component="span"
<Box mt={theme.spacing(1)}> sx={{ opacity: 0.8 }}
<Box
display="inline-block"
width={theme.spacing(4)}
height={theme.spacing(4)}
backgroundColor={theme.palette.primary.main}
sx={{ borderRadius: "50%" }}
/>
<Stack
display="inline-flex"
direction="row"
justifyContent="space-between"
ml={theme.spacing(3)}
sx={{
"& span": {
color: theme.palette.text.tertiary,
fontSize: 11,
fontWeight: 500,
},
}}
> >
Response time
</Typography>
<Typography
ml={theme.spacing(4)}
component="span"
>
{Math.floor(responseTime)}
<Typography <Typography
component="span" component="span"
sx={{ opacity: 0.8 }} sx={{ opacity: 0.8 }}
> >
Response Time {" "}
</Typography>{" "} ms
<Typography component="span">
{Math.floor(responseTime)}
<Typography
component="span"
sx={{ opacity: 0.8 }}
>
{" "}
ms
</Typography>
</Typography> </Typography>
</Stack> </Typography>
</Box> </Stack>
{/* Display original value */}
</Box> </Box>
</ChartBox> {/* Display original value */}
</Box>
); );
} }
return null; return null;
@@ -143,75 +140,81 @@ const DistributedUptimeResponseChart = ({ checks }) => {
if (checks.length === 0) return null; if (checks.length === 0) return null;
return ( return (
<ResponsiveContainer <ChartBox
width="100%" icon={<ResponseTimeIcon />}
minWidth={25} header="Response Times"
height={220} sx={{ padding: 0 }}
> >
<AreaChart <ResponsiveContainer
width="100%" width="100%"
height="100%" minWidth={25}
data={checks} height={220}
margin={{
top: 10,
right: 0,
left: 0,
bottom: 0,
}}
onMouseMove={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
> >
<CartesianGrid <AreaChart
stroke={theme.palette.primary.lowContrast} width="100%"
strokeWidth={1} height="100%"
strokeOpacity={1} data={checks}
fill="transparent" margin={{
vertical={false} top: 10,
/> right: 0,
<defs> left: 0,
<linearGradient bottom: 0,
id="colorUv" }}
x1="0" onMouseMove={() => setIsHovered(true)}
y1="0" onMouseLeave={() => setIsHovered(false)}
x2="0" >
y2="1" <CartesianGrid
> stroke={theme.palette.primary.lowContrast}
<stop strokeWidth={1}
offset="0%" strokeOpacity={1}
stopColor={theme.palette.accent.darker} fill="transparent"
stopOpacity={0.8} vertical={false}
/> />
<stop <defs>
offset="100%" <linearGradient
stopColor={theme.palette.accent.main} id="colorUv"
stopOpacity={0} x1="0"
/> y1="0"
</linearGradient> x2="0"
</defs> y2="1"
<XAxis >
stroke={theme.palette.primary.lowContrast} <stop
dataKey="_id" offset="0%"
tick={<CustomTick />} stopColor={theme.palette.accent.darker}
minTickGap={0} stopOpacity={0.8}
axisLine={false} />
tickLine={false} <stop
height={20} offset="100%"
/> stopColor={theme.palette.accent.main}
<Tooltip stopOpacity={0}
cursor={{ stroke: theme.palette.primary.lowContrast }} />
content={<CustomToolTip />} </linearGradient>
wrapperStyle={{ pointerEvents: "none" }} </defs>
/> <XAxis
<Area stroke={theme.palette.primary.lowContrast}
type="monotone" dataKey="_id"
dataKey="avgResponseTime" tick={<CustomTick />}
stroke={theme.palette.primary.accent} minTickGap={0}
fill="url(#colorUv)" axisLine={false}
strokeWidth={isHovered ? 2.5 : 1.5} tickLine={false}
activeDot={{ stroke: theme.palette.background.main, r: 5 }} height={20}
/> />
</AreaChart> <Tooltip
</ResponsiveContainer> cursor={{ stroke: theme.palette.primary.lowContrast }}
content={<CustomToolTip />}
wrapperStyle={{ pointerEvents: "none" }}
/>
<Area
type="monotone"
dataKey="avgResponseTime"
stroke={theme.palette.primary.accent}
fill="url(#colorUv)"
strokeWidth={isHovered ? 2.5 : 1.5}
activeDot={{ stroke: theme.palette.background.main, r: 5 }}
/>
</AreaChart>
</ResponsiveContainer>
</ChartBox>
); );
}; };
@@ -0,0 +1,14 @@
import { Stack, Skeleton } from "@mui/material";
export const SkeletonLayout = () => {
return (
<Stack>
<Skeleton
variant="rectangular"
height={"90vh"}
/>
</Stack>
);
};
export default SkeletonLayout;
@@ -68,6 +68,9 @@ const useSubscribeToDetails = ({ monitorId, dateRange }) => {
dateRange: dateRange, dateRange: dateRange,
normalize: true, normalize: true,
onUpdate: (data) => { onUpdate: (data) => {
if (isLoading === true) {
setIsLoading(false);
}
if (networkError === true) { if (networkError === true) {
setNetworkError(false); setNetworkError(false);
} }
@@ -87,6 +90,7 @@ const useSubscribeToDetails = ({ monitorId, dateRange }) => {
setRetryCount(0); // Reset retry count on successful connection setRetryCount(0); // Reset retry count on successful connection
}, },
onError: () => { onError: () => {
setIsLoading(false);
setNetworkError(true); setNetworkError(true);
setConnectionStatus("down"); setConnectionStatus("down");
}, },
@@ -94,8 +98,6 @@ const useSubscribeToDetails = ({ monitorId, dateRange }) => {
return cleanup; return cleanup;
} catch (error) { } catch (error) {
setNetworkError(true); setNetworkError(true);
} finally {
setIsLoading(false);
} }
}, [ }, [
authToken, authToken,
@@ -105,6 +107,7 @@ const useSubscribeToDetails = ({ monitorId, dateRange }) => {
setConnectionStatus, setConnectionStatus,
networkError, networkError,
devices, devices,
isLoading,
]); ]);
useEffect(() => { useEffect(() => {
@@ -11,7 +11,7 @@ import MonitorHeader from "./Components/MonitorHeader";
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader"; import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
import GenericFallback from "../../../Components/GenericFallback"; import GenericFallback from "../../../Components/GenericFallback";
import MonitorCreateHeader from "../../../Components/MonitorCreateHeader"; import MonitorCreateHeader from "../../../Components/MonitorCreateHeader";
import SkeletonLayout from "./Components/Skeleton";
//Utils //Utils
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { useState } from "react"; import { useState } from "react";
@@ -35,6 +35,10 @@ const DistributedUptimeDetails = () => {
{ name: "Details", path: `/distributed-uptime/${monitorId}` }, { name: "Details", path: `/distributed-uptime/${monitorId}` },
]; ];
if (isLoading) {
return <SkeletonLayout />;
}
if (networkError) { if (networkError) {
return ( return (
<GenericFallback> <GenericFallback>
@@ -0,0 +1,14 @@
import { Stack, Skeleton } from "@mui/material";
export const SkeletonLayout = () => {
return (
<Stack>
<Skeleton
variant="rectangular"
height={"90vh"}
/>
</Stack>
);
};
export default SkeletonLayout;
@@ -32,6 +32,10 @@ const useSubscribeToMonitors = () => {
field: null, field: null,
order: null, order: null,
onUpdate: (data) => { onUpdate: (data) => {
if (isLoading === true) {
setIsLoading(false);
}
const res = data.monitors; const res = data.monitors;
const { monitors, filteredMonitors, summary } = res; const { monitors, filteredMonitors, summary } = res;
const mappedMonitors = filteredMonitors.map((monitor) => const mappedMonitors = filteredMonitors.map((monitor) =>
@@ -41,6 +45,9 @@ const useSubscribeToMonitors = () => {
setMonitorsSummary(summary); setMonitorsSummary(summary);
setFilteredMonitors(mappedMonitors); setFilteredMonitors(mappedMonitors);
}, },
onError: () => {
setIsLoading(false);
},
}); });
return cleanup; return cleanup;
@@ -49,8 +56,6 @@ const useSubscribeToMonitors = () => {
body: error.message, body: error.message,
}); });
setNetworkError(true); setNetworkError(true);
} finally {
setIsLoading(false);
} }
}, [authToken, user, getMonitorWithPercentage, theme]); }, [authToken, user, getMonitorWithPercentage, theme]);
return [isLoading, networkError, monitors, monitorsSummary, filteredMonitors]; return [isLoading, networkError, monitors, monitorsSummary, filteredMonitors];
@@ -10,6 +10,7 @@ import GenericFallback from "../../../Components/GenericFallback";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import { useSubscribeToMonitors } from "./Hooks/useSubscribeToMonitors"; import { useSubscribeToMonitors } from "./Hooks/useSubscribeToMonitors";
import SkeletonLayout from "./Components/Skeleton";
// Constants // Constants
const BREADCRUMBS = [{ name: `Distributed Uptime`, path: "/distributed-uptime" }]; const BREADCRUMBS = [{ name: `Distributed Uptime`, path: "/distributed-uptime" }];
@@ -21,6 +22,10 @@ const DistributedUptimeMonitors = () => {
const [isLoading, networkError, monitors, monitorsSummary, filteredMonitors] = const [isLoading, networkError, monitors, monitorsSummary, filteredMonitors] =
useSubscribeToMonitors(); useSubscribeToMonitors();
if (isLoading) {
return <SkeletonLayout />;
}
if (networkError) { if (networkError) {
return ( return (
<GenericFallback> <GenericFallback>
@@ -0,0 +1,14 @@
import { Stack, Skeleton } from "@mui/material";
export const SkeletonLayout = () => {
return (
<Stack>
<Skeleton
variant="rectangular"
height={"90vh"}
/>
</Stack>
);
};
export default SkeletonLayout;
@@ -11,6 +11,7 @@ import ControlsHeader from "../../StatusPage/Status/Components/ControlsHeader";
import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader"; import MonitorTimeFrameHeader from "../../../Components/MonitorTimeFrameHeader";
import GenericFallback from "../../../Components/GenericFallback"; import GenericFallback from "../../../Components/GenericFallback";
import Dialog from "../../../Components/Dialog"; import Dialog from "../../../Components/Dialog";
import SkeletonLayout from "./Components/Skeleton";
//Utils //Utils
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { useState } from "react"; import { useState } from "react";
@@ -46,6 +47,7 @@ const DistributedUptimeStatus = () => {
// Constants // Constants
const BREADCRUMBS = [ const BREADCRUMBS = [
{ name: "Distributed Uptime", path: "/distributed-uptime" }, { name: "Distributed Uptime", path: "/distributed-uptime" },
{ name: "details", path: `/distributed-uptime/${monitorId}` },
{ name: "status", path: `` }, { name: "status", path: `` },
]; ];
@@ -59,7 +61,11 @@ const DistributedUptimeStatus = () => {
}; };
} }
if (networkError) { if (isLoading || statusPageIsLoading) {
return <SkeletonLayout />;
}
if (networkError || statusPageNetworkError) {
return ( return (
<GenericFallback> <GenericFallback>
<Typography <Typography
@@ -74,7 +80,11 @@ const DistributedUptimeStatus = () => {
); );
} }
if (typeof monitor === "undefined" || monitor.totalChecks === 0) { if (
typeof statusPage === "undefined" ||
typeof monitor === "undefined" ||
monitor.totalChecks === 0
) {
return ( return (
<Stack gap={theme.spacing(10)}> <Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} /> <Breadcrumbs list={BREADCRUMBS} />
@@ -93,6 +103,7 @@ const DistributedUptimeStatus = () => {
> >
{!isPublic && <Breadcrumbs list={BREADCRUMBS} />} {!isPublic && <Breadcrumbs list={BREADCRUMBS} />}
<ControlsHeader <ControlsHeader
shouldShow={!isPublic}
statusPage={statusPage} statusPage={statusPage}
isDeleting={isDeleting} isDeleting={isDeleting}
isDeleteOpen={isDeleteOpen} isDeleteOpen={isDeleteOpen}