fix: unnecessary custom styling and originalResponseTime usage

This commit is contained in:
mannilakash committed 2026-02-17 10:27:22 -05:00
1 parent 566fded55c
commit 7d66bb5668
1 file changed
+15 -41
@@ -17,31 +17,23 @@ interface HistogramResponseTimeProps {
} }
interface ResponseTimeStats { interface ResponseTimeStats {
max: number; max: number | string;
avg: number; avg: number | string;
} }
const DEFAULT_HEIGHT = 50; const DEFAULT_HEIGHT = 50;
const calculateResponseTimeStats = (checks: CheckSnapshot[]): ResponseTimeStats => { const calculateResponseTimeStats = (checks: CheckSnapshot[]): ResponseTimeStats => {
if (!Array.isArray(checks) || checks.length === 0) { if (!Array.isArray(checks) || checks.length === 0) {
return { max: 0, avg: 0 }; return { max: "-", avg: "-" };
} }
const validChecks = checks.filter( const validChecks = checks.filter((check) => check.originalResponseTime != null);
(check) =>
(check as any).status !== "placeholder" &&
(check.originalResponseTime != null || check.responseTime != null)
);
if (validChecks.length === 0) { if (validChecks.length === 0) {
return { max: 0, avg: 0 }; return { max: "-", avg: "-" };
} }
const responseTimes = validChecks.map( const responseTimes = validChecks.map((check) => check.originalResponseTime);
(check) => check.originalResponseTime ?? check.responseTime ?? 0
);
const max = Math.max(...responseTimes); const max = Math.max(...responseTimes);
const avg = Math.round( const avg = Math.round(
responseTimes.reduce((sum, time) => sum + time, 0) / responseTimes.length responseTimes.reduce((sum, time) => sum + time, 0) / responseTimes.length
@@ -72,36 +64,19 @@ export const HistogramResponseTime = ({
const chartHeight = typeof height === "number" ? `${height}px` : height; const chartHeight = typeof height === "number" ? `${height}px` : height;
const gridGap = gap ?? theme.spacing(0.5); const gridGap = gap ?? theme.spacing(0.5);
const statsContent = showStats && (stats.max > 0 || stats.avg > 0) && ( const statsContent = showStats &&
(typeof stats.max === "number" || typeof stats.avg === "number") && (
<Stack <Stack
justifyContent="center" justifyContent="center"
alignItems={statsPosition === "left" ? "flex-end" : "flex-start"} alignItems={statsPosition === "left" ? "flex-end" : "flex-start"}
sx={{ minWidth={70}
minWidth: 70, pr={statsPosition === "left" ? theme.spacing(8) : 0}
pr: statsPosition === "left" ? theme.spacing(8) : 0, pl={statsPosition === "right" ? theme.spacing(8) : 0}
pl: statsPosition === "right" ? theme.spacing(8) : 0,
}}
>
<Typography
variant="caption"
sx={{
color: theme.palette.text.secondary,
fontSize: "0.65rem",
fontWeight: 500,
pt: theme.spacing(2),
}}
> >
<Typography variant="body2">
{t("common.charts.histogram.avg", { value: stats.avg })} {t("common.charts.histogram.avg", { value: stats.avg })}
</Typography> </Typography>
<Typography <Typography variant="body2">
variant="caption"
sx={{
color: theme.palette.text.secondary,
fontSize: "0.65rem",
fontWeight: 500,
pt: theme.spacing(2),
}}
>
{t("common.charts.histogram.max", { value: stats.max })} {t("common.charts.histogram.max", { value: stats.max })}
</Typography> </Typography>
</Stack> </Stack>
@@ -109,11 +84,10 @@ export const HistogramResponseTime = ({
return ( return (
<Stack <Stack
direction="row" direction={statsPosition === "left" ? "row-reverse" : "row"}
alignItems="center" alignItems="center"
sx={{ width: "100%" }} sx={{ width: "100%" }}
> >
{statsPosition === "left" && statsContent}
<Box sx={{ flex: 1 }}> <Box sx={{ flex: 1 }}>
<Box <Box
sx={{ sx={{
@@ -175,7 +149,7 @@ export const HistogramResponseTime = ({
})} })}
</Box> </Box>
</Box> </Box>
{statsPosition === "right" && statsContent} {statsContent}
</Stack> </Stack>
); );
}; };