pagination
This commit is contained in:
1 parent
16b68b3d00
commit
86bb28e239
18 files changed
+327
-47
No files matched your search
@@ -0,0 +1,93 @@
|
||||
import { Table, Pagination } from "@/Components/v2/DesignElements";
|
||||
import { StatusLabel } from "@/Components/v2/DesignElements";
|
||||
import Box from "@mui/material/Box";
|
||||
|
||||
import type { Header } from "@/Components/v2/DesignElements/Table";
|
||||
import type { Check } from "@/Types/Check";
|
||||
import type { ApiResponse } from "@/Hooks/v2/UseApi";
|
||||
import type { MonitorStatus } from "@/Types/Monitor";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useGet } from "@/Hooks/v2/UseApi";
|
||||
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
||||
import { useSelector } from "react-redux";
|
||||
const getHeaders = (t: Function, uiTimezone: string) => {
|
||||
const headers: Header<Check>[] = [
|
||||
{
|
||||
id: "status",
|
||||
content: t("status"),
|
||||
render: (row) => {
|
||||
return <StatusLabel status={row.status as MonitorStatus} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "date",
|
||||
content: t("date&Time"),
|
||||
render: (row) => {
|
||||
return formatDateWithTz(row.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "statusCode",
|
||||
content: t("statusCode"),
|
||||
render: (row) => {
|
||||
return row.httpStatusCode || "N/A";
|
||||
},
|
||||
},
|
||||
];
|
||||
return headers;
|
||||
};
|
||||
|
||||
export const CheckTable = ({ monitorId }: { monitorId: string }) => {
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(5);
|
||||
const { t } = useTranslation();
|
||||
const uiTimezone = useSelector((state: any) => state.ui.timezone);
|
||||
const headers = getHeaders(t, uiTimezone);
|
||||
|
||||
const { response, error } = useGet<ApiResponse>(
|
||||
`/monitors/${monitorId}/checks?page=${page}&rowsPerPage=${rowsPerPage}`,
|
||||
{},
|
||||
{ keepPreviousData: true }
|
||||
);
|
||||
|
||||
const checks = response?.data?.checks || [];
|
||||
const count = response?.data?.count || 0;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Table
|
||||
headers={headers}
|
||||
data={checks}
|
||||
/>
|
||||
<Pagination
|
||||
component="div"
|
||||
count={count}
|
||||
page={page}
|
||||
rowsPerPage={rowsPerPage}
|
||||
onPageChange={handlePageChange}
|
||||
onRowsPerPageChange={handleRowsPerPageChange}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -4,7 +4,11 @@ import Stack from "@mui/material/Stack";
|
||||
import { StatBox } from "@/Components/v2/DesignElements";
|
||||
import { HistogramStatus } from "@/Components/v2/Monitors/HistogramStatus";
|
||||
import { ChartAvgResponse } from "@/Components/v2/Monitors/ChartAvgResponse";
|
||||
import { ChartResponseTime } from "@/Components/v2/Monitors/ChartResponseTime";
|
||||
import { HeaderRange } from "@/Components/v2/Monitors/HeaderRange";
|
||||
import { CheckTable } from "@/Pages/v2/Uptime/CheckTable";
|
||||
|
||||
import type { IMonitor } from "@/Types/Monitor";
|
||||
import { useMediaQuery } from "@mui/material";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
import { useParams } from "react-router";
|
||||
@@ -12,8 +16,6 @@ import { useGet, usePatch, type ApiResponse } from "@/Hooks/v2/UseApi";
|
||||
import { useState } from "react";
|
||||
import { getStatusPalette } from "@/Utils/MonitorUtils";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
import { ChartResponseTime } from "@/Components/v2/Monitors/ChartResponseTime";
|
||||
import { HeaderRange } from "@/Components/v2/Monitors/HeaderRange";
|
||||
|
||||
const UptimeDetailsPage = () => {
|
||||
const { id } = useParams();
|
||||
@@ -23,7 +25,7 @@ const UptimeDetailsPage = () => {
|
||||
// Local state
|
||||
const [range, setRange] = useState("2h");
|
||||
|
||||
const { response, loading, error, refetch } = useGet<ApiResponse>(
|
||||
const { response, isValidating, error, refetch } = useGet<ApiResponse>(
|
||||
`/monitors/${id}?embedChecks=true&range=${range}`,
|
||||
|
||||
{},
|
||||
@@ -32,8 +34,8 @@ const UptimeDetailsPage = () => {
|
||||
|
||||
const {
|
||||
response: upResponse,
|
||||
isValidating: upIsValidating,
|
||||
error: upError,
|
||||
loading: upLoading,
|
||||
} = useGet<ApiResponse>(
|
||||
`/monitors/${id}?embedChecks=true&range=${range}&status=up`,
|
||||
{},
|
||||
@@ -43,7 +45,7 @@ const UptimeDetailsPage = () => {
|
||||
const {
|
||||
response: downResponse,
|
||||
error: downError,
|
||||
loading: downLoading,
|
||||
isValidating: downIsValidating,
|
||||
} = useGet<ApiResponse>(
|
||||
`/monitors/${id}?embedChecks=true&range=${range}&status=down`,
|
||||
{},
|
||||
@@ -56,7 +58,8 @@ const UptimeDetailsPage = () => {
|
||||
error: postError,
|
||||
} = usePatch<ApiResponse>(`/monitors/${id}/active`);
|
||||
|
||||
const monitor = response?.data?.monitor || null;
|
||||
const monitor: IMonitor = response?.data?.monitor;
|
||||
|
||||
if (!monitor) {
|
||||
return null;
|
||||
}
|
||||
@@ -79,12 +82,17 @@ const UptimeDetailsPage = () => {
|
||||
? [...downResponse.data.checks].reverse()
|
||||
: [];
|
||||
|
||||
// TODO something with these
|
||||
|
||||
console.log(loading, error, postError, checks, setRange);
|
||||
|
||||
const palette = getStatusPalette(monitor.status);
|
||||
|
||||
if (error || upError || downError || postError) {
|
||||
console.error("Error fetching monitor data:", {
|
||||
error,
|
||||
upError,
|
||||
downError,
|
||||
postError,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<BasePage>
|
||||
<HeaderControls
|
||||
@@ -116,6 +124,7 @@ const UptimeDetailsPage = () => {
|
||||
/>
|
||||
</Stack>
|
||||
<HeaderRange
|
||||
loading={isValidating || upIsValidating || downIsValidating}
|
||||
range={range}
|
||||
setRange={setRange}
|
||||
/>
|
||||
@@ -144,6 +153,7 @@ const UptimeDetailsPage = () => {
|
||||
checks={checks}
|
||||
range={range}
|
||||
/>
|
||||
<CheckTable monitorId={monitor._id} />
|
||||
</BasePage>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Table } from "@/Components/v2/DesignElements";
|
||||
import { HistogramResponseTime } from "@/Components/v2/Monitors/HistogramResponseTime";
|
||||
import type { Header } from "@/Components/v2/DesignElements/Table";
|
||||
import { ActionsMenu } from "@/Components/v2/ActionsMenu";
|
||||
import { StatusLabel } from "@/Components/v2/DesignElements";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMediaQuery } from "@mui/material";
|
||||
@@ -86,7 +87,7 @@ const getHeaders = (theme: any, t: Function, navigate: Function) => {
|
||||
id: "status",
|
||||
content: t("status"),
|
||||
render: (row) => {
|
||||
return row.status;
|
||||
return <StatusLabel status={row.status} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user