refactor all call sites

This commit is contained in:
Alex committed 2026-05-07 09:54:58 -07:00
1 parent 0827d4f528
commit 1d90b8d8d9
5 files changed
+78 -137

No files matched your search

@@ -1,21 +1,14 @@
import { import {
Table, Table,
Pagination, Pagination,
ValueLabel,
StatusLabel, StatusLabel,
Tooltip, StatusCodeLabel,
} from "@/Components/design-elements"; } from "@/Components/design-elements";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import type { Header } from "@/Components/design-elements/Table"; import type { Header } from "@/Components/design-elements/Table";
import type { Monitor } from "@/Types/Monitor"; import type { Monitor } from "@/Types/Monitor";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { formatDateWithTz } from "@/Utils/TimeUtils"; import { formatDateWithTz } from "@/Utils/TimeUtils";
import {
formatStatusCode,
getStatusCodeTooltip,
getStatusCodeValueType,
} from "@/Utils/statusCode";
import type { Check } from "@/Types/Check"; import type { Check } from "@/Types/Check";
import type { RootState } from "@/Types/state"; import type { RootState } from "@/Types/state";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
@@ -40,7 +33,7 @@ export const ChecksTable = ({
const { t } = useTranslation(); const { t } = useTranslation();
const uiTimezone = useSelector((state: RootState) => state.ui.timezone); const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
const getHeaders = (t: (key: string) => string, uiTimezone: string) => { const getHeaders = () => {
const headers: Header<Check>[] = [ const headers: Header<Check>[] = [
{ {
id: "monitorName", id: "monitorName",
@@ -74,23 +67,12 @@ export const ChecksTable = ({
id: "statusCode", id: "statusCode",
content: t("pages.checks.table.headers.statusCode"), content: t("pages.checks.table.headers.statusCode"),
render: (row) => { render: (row) => {
const code = row.statusCode; return (
if (!code) return "N/A"; <StatusCodeLabel
const text = formatStatusCode(code, t); statusCode={row.statusCode}
const tooltip = getStatusCodeTooltip(code, row.message, t); message={row.message}
const label = (
<ValueLabel
value={getStatusCodeValueType(code)}
text={text}
/> />
); );
return tooltip ? (
<Tooltip title={tooltip}>
<span>{label}</span>
</Tooltip>
) : (
label
);
}, },
}, },
{ {
@@ -104,7 +86,7 @@ export const ChecksTable = ({
return headers; return headers;
}; };
const headers = getHeaders(t, uiTimezone); const headers = getHeaders();
const handlePageChange = ( const handlePageChange = (
_e: React.MouseEvent<HTMLButtonElement> | null, _e: React.MouseEvent<HTMLButtonElement> | null,
@@ -2,7 +2,7 @@ import Stack from "@mui/material/Stack";
import Grid from "@mui/material/Grid"; import Grid from "@mui/material/Grid";
import Divider from "@mui/material/Divider"; import Divider from "@mui/material/Divider";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import { BaseBox, ValueLabel, Tooltip } from "@/Components/design-elements"; import { BaseBox, ValueLabel, StatusCodeLabel } from "@/Components/design-elements";
import { LAYOUT } from "@/Utils/Theme/constants"; import { LAYOUT } from "@/Utils/Theme/constants";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -13,7 +13,6 @@ import { useSelector } from "react-redux";
import type { RootState } from "@/Types/state"; import type { RootState } from "@/Types/state";
import { formatDateWithTz } from "@/Utils/TimeUtils"; import { formatDateWithTz } from "@/Utils/TimeUtils";
import { getIncidentsDuration } from "@/Pages/Incidents/utils"; import { getIncidentsDuration } from "@/Pages/Incidents/utils";
import { formatStatusCode, getStatusCodeTooltip } from "@/Utils/statusCode";
interface CardDetailsProps { interface CardDetailsProps {
incident: Incident | null; incident: Incident | null;
@@ -48,13 +47,6 @@ export const CardDetails = ({ incident, monitor, sx }: CardDetailsProps) => {
return null; return null;
} }
const statusCodeText = formatStatusCode(incident.statusCode, t);
const statusCodeTooltip = getStatusCodeTooltip(
incident.statusCode,
incident.message,
t
);
return ( return (
<Stack <Stack
gap={theme.spacing(LAYOUT.MD)} gap={theme.spacing(LAYOUT.MD)}
@@ -133,13 +125,10 @@ export const CardDetails = ({ incident, monitor, sx }: CardDetailsProps) => {
</Grid> </Grid>
<Grid size={4}> <Grid size={4}>
<Cell> <Cell>
{statusCodeTooltip ? ( <StatusCodeLabel
<Tooltip title={statusCodeTooltip}> statusCode={incident.statusCode}
<span>{statusCodeText}</span> message={incident.message}
</Tooltip> />
) : (
statusCodeText
)}
</Cell> </Cell>
</Grid> </Grid>
<Grid size={2}> <Grid size={2}>
@@ -1,4 +1,4 @@
import { Table, ValueLabel, Tooltip } from "@/Components/design-elements"; import { Table, ValueLabel, StatusCodeLabel } from "@/Components/design-elements";
import { Pagination } from "@/Components/design-elements/Table"; import { Pagination } from "@/Components/design-elements/Table";
import type { Header } from "@/Components/design-elements/Table"; import type { Header } from "@/Components/design-elements/Table";
import { ActionsMenu } from "@/Components/actions-menu"; import { ActionsMenu } from "@/Components/actions-menu";
@@ -14,11 +14,6 @@ import Typography from "@mui/material/Typography";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import { getMonitorPath } from "@/Utils/MonitorUtils"; import { getMonitorPath } from "@/Utils/MonitorUtils";
import {
formatStatusCode,
getStatusCodeTooltip,
getStatusCodeValueType,
} from "@/Utils/statusCode";
interface IncidentsTableProps { interface IncidentsTableProps {
title?: string; title?: string;
@@ -139,13 +134,12 @@ export const IncidentsTable = ({
return ( return (
<Typography <Typography
variant="body2" variant="body2"
sx={{ color={
textTransform: "capitalize", row.resolutionType === "manual"
color: ? theme.palette.warning.main
row.resolutionType === "manual" : theme.palette.success.main
? theme.palette.warning.main }
: theme.palette.success.main, textTransform={"capitalize"}
}}
> >
{row.resolutionType} {row.resolutionType}
</Typography> </Typography>
@@ -158,23 +152,12 @@ export const IncidentsTable = ({
id: "statusCode", id: "statusCode",
content: t("pages.incidents.table.headers.statusCode"), content: t("pages.incidents.table.headers.statusCode"),
render: (row) => { render: (row) => {
const code = row.statusCode; return (
if (!code) return "N/A"; <StatusCodeLabel
const text = formatStatusCode(code, t); statusCode={row.statusCode}
const tooltip = getStatusCodeTooltip(code, row.message, t); message={row.message}
const label = (
<ValueLabel
value={getStatusCodeValueType(code)}
text={text}
/> />
); );
return tooltip ? (
<Tooltip title={tooltip}>
<span>{label}</span>
</Tooltip>
) : (
label
);
}, },
}, },
{ {
@@ -1,4 +1,9 @@
import { Table, Pagination, StatusLabel, Tooltip } from "@/Components/design-elements"; import {
Table,
Pagination,
StatusLabel,
StatusCodeLabel,
} from "@/Components/design-elements";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import type { Header } from "@/Components/design-elements"; import type { Header } from "@/Components/design-elements";
import type { Check } from "@/Types/Check"; import type { Check } from "@/Types/Check";
@@ -6,11 +11,28 @@ import type { Check } from "@/Types/Check";
import { useNavigate } from "react-router"; import { useNavigate } from "react-router";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { formatDateWithTz } from "@/Utils/TimeUtils"; import { formatDateWithTz } from "@/Utils/TimeUtils";
import { formatStatusCode, getStatusCodeTooltip } from "@/Utils/statusCode";
import type { RootState } from "@/Types/state"; import type { RootState } from "@/Types/state";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
const getHeaders = (t: (key: string) => string, uiTimezone: string) => { export const ChecksTable = ({
checks,
count,
page,
setPage,
rowsPerPage,
setRowsPerPage,
}: {
checks: Check[];
count: number;
page: number;
setPage: (page: number) => void;
rowsPerPage: number;
setRowsPerPage: (rowsPerPage: number) => void;
}) => {
const navigate = useNavigate();
const { t } = useTranslation();
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
const headers: Header<Check>[] = [ const headers: Header<Check>[] = [
{ {
id: "status", id: "status",
@@ -37,41 +59,15 @@ const getHeaders = (t: (key: string) => string, uiTimezone: string) => {
id: "statusCode", id: "statusCode",
content: t("pages.checks.table.headers.statusCode"), content: t("pages.checks.table.headers.statusCode"),
render: (row) => { render: (row) => {
if (!row.statusCode) return "N/A"; return (
const text = formatStatusCode(row.statusCode, t); <StatusCodeLabel
const tooltip = getStatusCodeTooltip(row.statusCode, row.message, t); statusCode={row.statusCode}
return tooltip ? ( message={row.message}
<Tooltip title={tooltip}> />
<span>{text}</span>
</Tooltip>
) : (
text
); );
}, },
}, },
]; ];
return headers;
};
export const ChecksTable = ({
checks,
count,
page,
setPage,
rowsPerPage,
setRowsPerPage,
}: {
checks: Check[];
count: number;
page: number;
setPage: (page: number) => void;
rowsPerPage: number;
setRowsPerPage: (rowsPerPage: number) => void;
}) => {
const navigate = useNavigate();
const { t } = useTranslation();
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
const headers = getHeaders(t, uiTimezone);
const handlePageChange = ( const handlePageChange = (
_e: React.MouseEvent<HTMLButtonElement> | null, _e: React.MouseEvent<HTMLButtonElement> | null,
@@ -1,15 +1,36 @@
import { Table, Pagination, StatusLabel, Tooltip } from "@/Components/design-elements"; import {
Table,
Pagination,
StatusLabel,
StatusCodeLabel,
} from "@/Components/design-elements";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import type { Header } from "@/Components/design-elements"; import type { Header } from "@/Components/design-elements";
import type { FlatGeoCheck } from "@/Types/GeoCheck"; import type { FlatGeoCheck } from "@/Types/GeoCheck";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { formatDateWithTz } from "@/Utils/TimeUtils"; import { formatDateWithTz } from "@/Utils/TimeUtils";
import { formatStatusCode, getStatusCodeTooltip } from "@/Utils/statusCode";
import type { RootState } from "@/Types/state"; import type { RootState } from "@/Types/state";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import prettyMilliseconds from "pretty-ms"; import prettyMilliseconds from "pretty-ms";
const getHeaders = (t: (key: string) => string, uiTimezone: string) => { export const GeoChecksTable = ({
geoChecks,
count,
page,
setPage,
rowsPerPage,
setRowsPerPage,
}: {
geoChecks: FlatGeoCheck[];
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: Header<FlatGeoCheck>[] = [ const headers: Header<FlatGeoCheck>[] = [
{ {
id: "status", id: "status",
@@ -30,16 +51,7 @@ const getHeaders = (t: (key: string) => string, uiTimezone: string) => {
id: "statusCode", id: "statusCode",
content: t("pages.checks.table.headers.statusCode"), content: t("pages.checks.table.headers.statusCode"),
render: (row) => { render: (row) => {
if (!row.statusCode) return "N/A"; return <StatusCodeLabel statusCode={row.statusCode} />;
const text = formatStatusCode(row.statusCode, t);
const tooltip = getStatusCodeTooltip(row.statusCode, undefined, t);
return tooltip ? (
<Tooltip title={tooltip}>
<span>{text}</span>
</Tooltip>
) : (
text
);
}, },
}, },
{ {
@@ -61,27 +73,6 @@ const getHeaders = (t: (key: string) => string, uiTimezone: string) => {
}, },
}, },
]; ];
return headers;
};
export const GeoChecksTable = ({
geoChecks,
count,
page,
setPage,
rowsPerPage,
setRowsPerPage,
}: {
geoChecks: FlatGeoCheck[];
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);
const handlePageChange = ( const handlePageChange = (
_e: React.MouseEvent<HTMLButtonElement> | null, _e: React.MouseEvent<HTMLButtonElement> | null,