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

94 lines
2.8 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 { useTheme } from "@emotion/react";
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
2025-02-05 14:59:08 -08:00
const statusColor = {
up: theme.palette.success.main,
down: theme.palette.error.main,
2025-03-05 11:20:23 -08:00
undefined: theme.palette.warning.main,
2025-02-05 14:59:08 -08:00
};
return (
2025-02-26 15:53:10 -08:00
<ColContainer sx={{ height: "100%" }}>
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" }}
>
2025-03-05 11:20:23 -08:00
{connectionStatus === "up" ? "Connected" : "Connecting..."}
2025-02-05 14:59:08 -08:00
</Typography>
</Stack>
2025-02-26 15:53:10 -08:00
<div
style={{
overflowX: "auto",
maxWidth: "100%",
// Optional: add a max height if you want vertical scrolling too
// maxHeight: '400px',
// overflowY: 'auto'
}}
>
<table style={{ width: "100%" }}>
<thead>
<tr>
<th style={{ textAlign: "left", paddingLeft: theme.spacing(4) }}>
<Typography>COUNTRY</Typography>
</th>
<th style={{ textAlign: "left", paddingLeft: theme.spacing(4) }}>
<Typography>CITY</Typography>
</th>
<th style={{ textAlign: "right", paddingLeft: theme.spacing(4) }}>
<Typography>RESPONSE</Typography>
</th>
<th style={{ textAlign: "right", paddingLeft: theme.spacing(4) }}>
<Typography sx={{ whiteSpace: "nowrap" }}>{"UPT BURNED"}</Typography>
</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={{ paddingLeft: theme.spacing(4) }}>
<Typography>
{flag ? <span className={flag} /> : null}{" "}
{countryCode?.toUpperCase() ?? "N/A"}
</Typography>
</td>
<td style={{ paddingLeft: theme.spacing(4) }}>
<Typography>{city}</Typography>
</td>
<td style={{ textAlign: "right", paddingLeft: theme.spacing(4) }}>
<Typography>{Math.floor(dataPoint.responseTime)} ms</Typography>
</td>
<td style={{ textAlign: "right", paddingLeft: theme.spacing(4) }}>
<Typography color={theme.palette.warning.main}>
+{dataPoint.uptBurnt}
</Typography>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
2025-02-20 19:02:24 -08:00
</ColContainer>
2025-02-05 14:59:08 -08:00
);
};
export default DeviceTicker;