Files
Checkmate/src/Pages/DistributedUptime/Details/Components/DeviceTicker/index.jsx
T

89 lines
2.5 KiB
React
Raw Normal View History

2025-02-26 11:41:36 -08:00
// Components
2025-02-20 19:02:24 -08:00
import { Stack, Typography } from "@mui/material";
2025-02-05 14:59:08 -08:00
import PulseDot from "../../../../../Components/Animated/PulseDot";
2025-02-09 07:52:31 -08:00
import "flag-icons/css/flag-icons.min.css";
2025-02-20 19:02:24 -08:00
import { ColContainer } from "../../../../../Components/StandardContainer";
2025-02-05 14:59:08 -08:00
2025-02-26 11:41:36 -08:00
// Utils
import { useMediaQuery } from "@mui/material";
import { useTheme } from "@emotion/react";
import { safelyParseFloat } from "../../../../../Utils/utils";
2025-02-05 14:59:08 -08:00
const DeviceTicker = ({ data, width = "100%", connectionStatus }) => {
const theme = useTheme();
2025-02-26 11:41:36 -08:00
const isSmallScreen = useMediaQuery(theme.breakpoints.down("sm"));
2025-02-05 14:59:08 -08:00
const statusColor = {
up: theme.palette.success.main,
down: theme.palette.error.main,
};
return (
2025-02-20 19:02:24 -08:00
<ColContainer>
2025-02-05 14:59:08 -08:00
<Stack
direction="row"
gap={theme.spacing(4)}
>
<PulseDot color={statusColor[connectionStatus]} />
<Typography
variant="h1"
mb={theme.spacing(8)}
sx={{ alignSelf: "center" }}
>
{connectionStatus === "up" ? "Connected" : "No connection"}
</Typography>
</Stack>
2025-02-20 19:02:24 -08:00
<table>
<thead>
<tr>
<th style={{ textAlign: "left" }}>
<Typography>COUNTRY</Typography>
</th>
<th style={{ textAlign: "left" }}>
<Typography>CITY</Typography>
</th>
<th style={{ textAlign: "right" }}>
<Typography>RESPONSE</Typography>
</th>
<th style={{ textAlign: "right" }}>
2025-02-26 11:41:36 -08:00
<Typography>{isSmallScreen ? "UPT" : "UPT BURNED"}</Typography>
2025-02-20 19:02:24 -08:00
</th>
</tr>
</thead>
<tbody>
{data.map((dataPoint) => {
const countryCode = dataPoint?.countryCode?.toLowerCase() ?? null;
const flag = countryCode ? `fi fi-${countryCode}` : null;
const city = dataPoint?.city !== "" ? dataPoint?.city : "Unknown";
return (
<tr key={Math.random()}>
<td style={{ padding: theme.spacing(4) }}>
<Typography>
{flag ? <span className={flag} /> : null}{" "}
{countryCode?.toUpperCase() ?? "N/A"}
</Typography>
</td>
<td>
<Typography>{city}</Typography>
</td>
<td style={{ textAlign: "right" }}>
<Typography>{Math.floor(dataPoint.responseTime)} ms</Typography>
</td>
<td style={{ textAlign: "right" }}>
<Typography color={theme.palette.warning.main}>
2025-02-26 11:41:36 -08:00
+
{isSmallScreen
? safelyParseFloat(dataPoint.uptBurnt).toFixed(4)
: dataPoint.uptBurnt}
2025-02-20 19:02:24 -08:00
</Typography>
</td>
</tr>
);
})}
</tbody>
</table>
</ColContainer>
2025-02-05 14:59:08 -08:00
);
};
export default DeviceTicker;