Added placeholder checks
This commit is contained in:
1 parent
8d75c52a72
commit
931d15c451
1 file changed
+96
-70
@@ -6,6 +6,16 @@ import "./index.css";
|
|||||||
const BarChart = ({ checks = [] }) => {
|
const BarChart = ({ checks = [] }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
|
// set responseTime to average if there's only one check
|
||||||
|
if (checks.length === 1) {
|
||||||
|
checks[0] = { ...checks[0], responseTime: 50 };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checks.length !== 25) {
|
||||||
|
const placeholders = Array(25 - checks.length).fill("placeholder");
|
||||||
|
checks = [...checks, ...placeholders];
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -18,90 +28,106 @@ const BarChart = ({ checks = [] }) => {
|
|||||||
cursor: "default",
|
cursor: "default",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{checks.map((check) => (
|
{checks.map((check, index) =>
|
||||||
<Tooltip
|
check === "placeholder" ? (
|
||||||
title={
|
|
||||||
<>
|
|
||||||
<Typography>
|
|
||||||
{formatDate(new Date(check.createdAt), { year: undefined })}
|
|
||||||
</Typography>
|
|
||||||
<Box mt={theme.gap.xs}>
|
|
||||||
<Box
|
|
||||||
display="inline-block"
|
|
||||||
width={theme.gap.small}
|
|
||||||
height={theme.gap.small}
|
|
||||||
backgroundColor={
|
|
||||||
check.status
|
|
||||||
? theme.label.up.dotColor
|
|
||||||
: theme.label.down.dotColor
|
|
||||||
}
|
|
||||||
sx={{ borderRadius: "50%" }}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
display="inline-flex"
|
|
||||||
direction="row"
|
|
||||||
justifyContent="space-between"
|
|
||||||
ml={theme.gap.xs}
|
|
||||||
gap={theme.gap.large}
|
|
||||||
>
|
|
||||||
<Typography component="span" sx={{ opacity: 0.8 }}>
|
|
||||||
Response Time
|
|
||||||
</Typography>
|
|
||||||
<Typography component="span">
|
|
||||||
{check.originalResponseTime}
|
|
||||||
<Typography component="span" sx={{ opacity: 0.8 }}>
|
|
||||||
{" "}
|
|
||||||
ms
|
|
||||||
</Typography>
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
placement="top"
|
|
||||||
key={`check-${check?._id}`}
|
|
||||||
slotProps={{
|
|
||||||
popper: {
|
|
||||||
className: "bar-tooltip",
|
|
||||||
modifiers: [
|
|
||||||
{
|
|
||||||
name: "offset",
|
|
||||||
options: {
|
|
||||||
offset: [0, -10],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Box
|
<Box
|
||||||
|
key={`${check}-${index}`}
|
||||||
position="relative"
|
position="relative"
|
||||||
width="9px"
|
width="9px"
|
||||||
height="100%"
|
height="100%"
|
||||||
backgroundColor={
|
backgroundColor={theme.palette.otherColors.fillGray}
|
||||||
check.status ? theme.label.up.bgColor : theme.label.down.bgColor
|
|
||||||
}
|
|
||||||
sx={{
|
sx={{
|
||||||
borderRadius: "3px",
|
borderRadius: "3px",
|
||||||
}}
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
<>
|
||||||
|
<Typography>
|
||||||
|
{formatDate(new Date(check.createdAt), { year: undefined })}
|
||||||
|
</Typography>
|
||||||
|
<Box mt={theme.gap.xs}>
|
||||||
|
<Box
|
||||||
|
display="inline-block"
|
||||||
|
width={theme.gap.small}
|
||||||
|
height={theme.gap.small}
|
||||||
|
backgroundColor={
|
||||||
|
check.status
|
||||||
|
? theme.label.up.dotColor
|
||||||
|
: theme.label.down.dotColor
|
||||||
|
}
|
||||||
|
sx={{ borderRadius: "50%" }}
|
||||||
|
/>
|
||||||
|
<Stack
|
||||||
|
display="inline-flex"
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
ml={theme.gap.xs}
|
||||||
|
gap={theme.gap.large}
|
||||||
|
>
|
||||||
|
<Typography component="span" sx={{ opacity: 0.8 }}>
|
||||||
|
Response Time
|
||||||
|
</Typography>
|
||||||
|
<Typography component="span">
|
||||||
|
{check.originalResponseTime}
|
||||||
|
<Typography component="span" sx={{ opacity: 0.8 }}>
|
||||||
|
{" "}
|
||||||
|
ms
|
||||||
|
</Typography>
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
placement="top"
|
||||||
|
key={`check-${check?._id}`}
|
||||||
|
slotProps={{
|
||||||
|
popper: {
|
||||||
|
className: "bar-tooltip",
|
||||||
|
modifiers: [
|
||||||
|
{
|
||||||
|
name: "offset",
|
||||||
|
options: {
|
||||||
|
offset: [0, -10],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
position="absolute"
|
position="relative"
|
||||||
bottom={0}
|
width="9px"
|
||||||
width="100%"
|
height="100%"
|
||||||
height={`${check.responseTime}%`}
|
|
||||||
backgroundColor={
|
backgroundColor={
|
||||||
check.status
|
check.status ? theme.label.up.bgColor : theme.label.down.bgColor
|
||||||
? theme.label.up.dotColor
|
|
||||||
: theme.label.down.dotColor
|
|
||||||
}
|
}
|
||||||
sx={{
|
sx={{
|
||||||
borderRadius: "3px",
|
borderRadius: "3px",
|
||||||
|
"&:hover > .MuiBox-root": {
|
||||||
|
filter: "brightness(0.8)",
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
</Box>
|
<Box
|
||||||
</Tooltip>
|
position="absolute"
|
||||||
))}
|
bottom={0}
|
||||||
|
width="100%"
|
||||||
|
height={`${check.responseTime}%`}
|
||||||
|
backgroundColor={
|
||||||
|
check.status
|
||||||
|
? theme.label.up.dotColor
|
||||||
|
: theme.label.down.dotColor
|
||||||
|
}
|
||||||
|
sx={{
|
||||||
|
borderRadius: "3px",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user