fix: unnecessary custom styling and originalResponseTime usage
This commit is contained in:
1 parent
566fded55c
commit
7d66bb5668
1 file changed
+24
-50
@@ -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,48 +64,30 @@ 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 &&
|
||||||
<Stack
|
(typeof stats.max === "number" || typeof stats.avg === "number") && (
|
||||||
justifyContent="center"
|
<Stack
|
||||||
alignItems={statsPosition === "left" ? "flex-end" : "flex-start"}
|
justifyContent="center"
|
||||||
sx={{
|
alignItems={statsPosition === "left" ? "flex-end" : "flex-start"}
|
||||||
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),
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{t("common.charts.histogram.avg", { value: stats.avg })}
|
<Typography variant="body2">
|
||||||
</Typography>
|
{t("common.charts.histogram.avg", { value: stats.avg })}
|
||||||
<Typography
|
</Typography>
|
||||||
variant="caption"
|
<Typography variant="body2">
|
||||||
sx={{
|
{t("common.charts.histogram.max", { value: stats.max })}
|
||||||
color: theme.palette.text.secondary,
|
</Typography>
|
||||||
fontSize: "0.65rem",
|
</Stack>
|
||||||
fontWeight: 500,
|
);
|
||||||
pt: theme.spacing(2),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("common.charts.histogram.max", { value: stats.max })}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
|
|
||||||
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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user