2026-02-24 23:20:36 +00:00
|
|
|
import { Table, Pagination, StatusLabel } from "@/Components/design-elements";
|
|
|
|
|
import Box from "@mui/material/Box";
|
|
|
|
|
import type { Header } from "@/Components/design-elements";
|
|
|
|
|
import type { GeoCheck } from "@/Types/GeoCheck";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
|
|
|
|
import type { RootState } from "@/Types/state";
|
|
|
|
|
import { useSelector } from "react-redux";
|
|
|
|
|
import prettyMilliseconds from "pretty-ms";
|
|
|
|
|
|
2026-02-25 18:43:12 +00:00
|
|
|
// Flatten geo check results - each location becomes a separate row
|
|
|
|
|
interface FlattenedGeoCheckResult {
|
|
|
|
|
id: string;
|
|
|
|
|
monitorId: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
location: {
|
|
|
|
|
continent: string;
|
|
|
|
|
country: string;
|
|
|
|
|
city: string;
|
|
|
|
|
};
|
|
|
|
|
status: boolean;
|
|
|
|
|
statusCode: number;
|
|
|
|
|
timings: {
|
|
|
|
|
total: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const flattenGeoChecks = (geoChecks: GeoCheck[]): FlattenedGeoCheckResult[] => {
|
|
|
|
|
const flattened: FlattenedGeoCheckResult[] = [];
|
|
|
|
|
for (const check of geoChecks) {
|
|
|
|
|
for (const result of check.results) {
|
|
|
|
|
flattened.push({
|
|
|
|
|
id: `${check.id}-${result.location.continent}-${result.location.city}`,
|
|
|
|
|
monitorId: check.metadata.monitorId,
|
|
|
|
|
createdAt: check.createdAt,
|
|
|
|
|
location: result.location,
|
|
|
|
|
status: result.status,
|
|
|
|
|
statusCode: result.statusCode,
|
|
|
|
|
timings: result.timings,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return flattened;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-24 23:20:36 +00:00
|
|
|
const getHeaders = (t: Function, uiTimezone: string) => {
|
2026-02-25 18:43:12 +00:00
|
|
|
const headers: Header<FlattenedGeoCheckResult>[] = [
|
2026-02-24 23:20:36 +00:00
|
|
|
{
|
|
|
|
|
id: "status",
|
|
|
|
|
content: t("common.table.headers.status"),
|
|
|
|
|
render: (row) => {
|
2026-02-25 18:43:12 +00:00
|
|
|
const status = row.status ? "up" : "down";
|
2026-02-24 23:20:36 +00:00
|
|
|
return <StatusLabel status={status} />;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "date",
|
|
|
|
|
content: t("common.table.headers.dateTime"),
|
|
|
|
|
render: (row) => {
|
|
|
|
|
return formatDateWithTz(row.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "statusCode",
|
|
|
|
|
content: t("pages.checks.table.headers.statusCode"),
|
|
|
|
|
render: (row) => {
|
2026-02-25 18:43:12 +00:00
|
|
|
return row.statusCode || "N/A";
|
2026-02-24 23:20:36 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "location",
|
|
|
|
|
content: t("pages.checks.table.headers.location"),
|
|
|
|
|
render: (row) => {
|
2026-02-25 18:43:12 +00:00
|
|
|
const { continent, country, city } = row.location;
|
2026-02-24 23:20:36 +00:00
|
|
|
return `${continent} - ${country}, ${city}`;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "responseTime",
|
|
|
|
|
content: t("common.table.headers.responseTime"),
|
|
|
|
|
render: (row) => {
|
2026-02-25 18:43:12 +00:00
|
|
|
if (!row.timings?.total) return "N/A";
|
|
|
|
|
return prettyMilliseconds(row.timings.total, { compact: true });
|
2026-02-24 23:20:36 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
return headers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const GeoChecksTable = ({
|
|
|
|
|
geoChecks,
|
|
|
|
|
count,
|
|
|
|
|
page,
|
|
|
|
|
setPage,
|
|
|
|
|
rowsPerPage,
|
|
|
|
|
setRowsPerPage,
|
|
|
|
|
}: {
|
|
|
|
|
geoChecks: GeoCheck[];
|
|
|
|
|
count: number;
|
|
|
|
|
page: number;
|
|
|
|
|
setPage: (page: number) => void;
|
|
|
|
|
rowsPerPage: number;
|
|
|
|
|
setRowsPerPage: (rowsPerPage: number) => void;
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
|
|
|
|
|
const headers = getHeaders(t, uiTimezone);
|
2026-02-25 18:43:12 +00:00
|
|
|
const flattenedData = flattenGeoChecks(geoChecks);
|
2026-02-24 23:20:36 +00:00
|
|
|
|
|
|
|
|
const handlePageChange = (
|
|
|
|
|
_e: React.MouseEvent<HTMLButtonElement> | null,
|
|
|
|
|
newPage: number
|
|
|
|
|
) => {
|
|
|
|
|
setPage(newPage);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleRowsPerPageChange = (
|
|
|
|
|
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
|
|
|
|
) => {
|
|
|
|
|
const value = Number(e.target.value);
|
|
|
|
|
setPage(0);
|
|
|
|
|
setRowsPerPage(value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
|
|
|
|
<Table
|
|
|
|
|
headers={headers}
|
2026-02-25 18:43:12 +00:00
|
|
|
data={flattenedData}
|
2026-02-24 23:20:36 +00:00
|
|
|
/>
|
|
|
|
|
<Pagination
|
|
|
|
|
component="div"
|
|
|
|
|
count={count}
|
|
|
|
|
page={page}
|
|
|
|
|
rowsPerPage={rowsPerPage}
|
|
|
|
|
onPageChange={handlePageChange}
|
|
|
|
|
onRowsPerPageChange={handleRowsPerPageChange}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|