status page pagination

This commit is contained in:
Alex Holliday committed 2025-12-11 18:41:38 +00:00
1 parent b6a3d1e34d
commit fe03451393
8 files changed
+222 -85

No files matched your search

@@ -0,0 +1,128 @@
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { Table, Pagination } from "@/components/design-elements";
import { ActionsMenu } from "@/components/actions-menu";
import type { Header } from "@/components/design-elements/Table";
import { useNavigate } from "react-router";
import type { IStatusPage } from "@/types/status-page";
import type { ActionMenuItem } from "@/components/actions-menu";
import { useTheme } from "@mui/material/styles";
import { useTranslation } from "react-i18next";
export const StatusPageTable = ({
statusPages,
setSelectedStatusPage,
page,
setPage,
rowsPerPage,
setRowsPerPage,
count,
}: {
statusPages: IStatusPage[];
setSelectedStatusPage: (statusPage: IStatusPage) => void;
page: number;
setPage: (page: number) => void;
rowsPerPage: number;
setRowsPerPage: (rowsPerPage: number) => void;
count: number;
}) => {
const theme = useTheme();
const navigate = useNavigate();
const { t } = useTranslation();
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);
};
const getActions = (statusPage: IStatusPage): ActionMenuItem[] => {
return [
{
id: 1,
label: "Configure",
action: () => {
navigate(`/status-pages/${statusPage._id}/configure`);
},
closeMenu: true,
},
{
id: 7,
label: <Typography color={theme.palette.error.main}>Remove</Typography>,
action: async () => {
setSelectedStatusPage(statusPage);
},
closeMenu: true,
},
];
};
const getHeaders = () => {
const headers: Header<IStatusPage>[] = [
{
id: "name",
content: "Name",
render: (row) => {
return <Typography>{row?.name}</Typography>;
},
},
{
id: "published",
content: "Published",
render: (row) => {
const published = row.isPublished ? "Yes" : "No";
return <Typography>{published}</Typography>;
},
},
{
id: "url",
content: "Public URL",
render: (row) => {
return (
<Typography textTransform={"capitalize"}>{row?.url}</Typography>
);
},
},
{
id: "actions",
content: t("actions"),
render: (row) => {
return <ActionsMenu items={getActions(row)} />;
},
},
];
return headers;
};
const headers = getHeaders();
return (
<Box>
<Table
headers={headers}
data={statusPages}
onRowClick={(row) => {
navigate(`/status-pages/${row._id}`);
}}
/>
<Pagination
component="div"
count={count}
page={page}
rowsPerPage={rowsPerPage}
onPageChange={handlePageChange}
onRowsPerPageChange={handleRowsPerPageChange}
/>
</Box>
);
};
+15 -78
View File
@@ -1,96 +1,31 @@
import { HeaderCreate } from "@/components/common";
import Typography from "@mui/material/Typography";
import { BasePageWithStates, InfoBox } from "@/components/design-elements";
import { Table } from "@/components/design-elements";
import { ActionsMenu } from "@/components/actions-menu";
import { Dialog } from "@/components/inputs";
import { StatusPageTable } from "@/pages/status-page/StatusPageTable";
import { useState } from "react";
import { useTheme } from "@mui/material/styles";
import { useNavigate } from "react-router";
import type { ActionMenuItem } from "@/components/actions-menu";
import type { Header } from "@/components/design-elements/Table";
import type { IStatusPage } from "@/types/status-page";
import { useGet, useDelete } from "@/hooks/UseApi";
import type { ApiResponse } from "@/hooks/UseApi";
import { useTranslation } from "react-i18next";
const StatusPages = () => {
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const { t } = useTranslation();
const navigate = useNavigate();
const theme = useTheme();
const [selectedStatusPage, setSelectedStatusPage] =
useState<IStatusPage | null>(null);
const open = Boolean(selectedStatusPage);
const { response, isValidating, error, refetch } = useGet<
ApiResponse<IStatusPage[]>
>("/status-pages", {}, {});
ApiResponse<{ statusPages: IStatusPage[]; count: number }>
>(`/status-pages?page=${page}&rowsPerPage=${rowsPerPage}`, {}, {});
const statusPages = response?.data || [];
const statusPages = response?.data?.statusPages || [];
const count = response?.data?.count || 0;
const { deleteFn, loading: isDeleting } = useDelete<any>();
const getActions = (statusPage: IStatusPage): ActionMenuItem[] => {
return [
{
id: 1,
label: "Configure",
action: () => {
navigate(`/status-pages/${statusPage._id}/configure`);
},
closeMenu: true,
},
{
id: 7,
label: <Typography color={theme.palette.error.main}>Remove</Typography>,
action: async () => {
setSelectedStatusPage(statusPage);
},
closeMenu: true,
},
];
};
const getHeaders = () => {
const headers: Header<IStatusPage>[] = [
{
id: "name",
content: "Name",
render: (row) => {
return <Typography>{row?.name}</Typography>;
},
},
{
id: "published",
content: "Published",
render: (row) => {
const published = row.isPublished ? "Yes" : "No";
return <Typography>{published}</Typography>;
},
},
{
id: "url",
content: "Public URL",
render: (row) => {
return (
<Typography textTransform={"capitalize"}>{row?.url}</Typography>
);
},
},
{
id: "actions",
content: t("actions"),
render: (row) => {
return <ActionsMenu items={getActions(row)} />;
},
},
];
return headers;
};
const headers = getHeaders();
const handleConfirm = async () => {
if (!selectedStatusPage) return;
const res = await deleteFn(`/status-pages/${selectedStatusPage._id}`);
@@ -127,12 +62,14 @@ const StatusPages = () => {
entitlement="statusPagesMax"
entitlementCount={statusPages.length}
/>
<Table
headers={headers}
data={statusPages}
onRowClick={(row) => {
navigate(`/status-pages/${row._id}`);
}}
<StatusPageTable
statusPages={statusPages}
setSelectedStatusPage={setSelectedStatusPage}
page={page}
setPage={setPage}
rowsPerPage={rowsPerPage}
setRowsPerPage={setRowsPerPage}
count={count}
/>
<Dialog
+1 -1
View File
@@ -9,7 +9,7 @@ import { HeaderFilter } from "@/components/monitors";
import { HeaderCreate } from "@/components/common";
import Stack from "@mui/material/Stack";
import { Dialog } from "@/components/inputs";
import { MonitorTable } from "@/pages/uptime/MonitorTable";
import { MonitorTable } from "@/pages/uptime/UptimeMonitorsTable";
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
import { useTranslation } from "react-i18next";