Merge pull request #1843 from bluewave-labs/feat/DePIN-monitors-pagination
feat: add pagination to DePIN Monitors
This commit is contained in:
3 files changed
+28
-5
No files matched your search
@@ -5,7 +5,7 @@ import { useTheme } from "@emotion/react";
|
|||||||
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
|
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
|
||||||
import { createToast } from "../../../../Utils/toastUtils";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
|
|
||||||
const useSubscribeToMonitors = () => {
|
const useSubscribeToMonitors = (page, rowsPerPage) => {
|
||||||
// Redux
|
// Redux
|
||||||
const { user } = useSelector((state) => state.auth);
|
const { user } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ const useSubscribeToMonitors = () => {
|
|||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
types: ["distributed_http"],
|
types: ["distributed_http"],
|
||||||
page: 0,
|
page,
|
||||||
rowsPerPage: 10,
|
rowsPerPage,
|
||||||
filter: null,
|
filter: null,
|
||||||
field: null,
|
field: null,
|
||||||
order: null,
|
order: null,
|
||||||
@@ -56,7 +56,7 @@ const useSubscribeToMonitors = () => {
|
|||||||
});
|
});
|
||||||
setNetworkError(true);
|
setNetworkError(true);
|
||||||
}
|
}
|
||||||
}, [user, getMonitorWithPercentage, theme, isLoading]);
|
}, [user, getMonitorWithPercentage, theme, isLoading, page, rowsPerPage]);
|
||||||
return [isLoading, networkError, monitors, monitorsSummary, filteredMonitors];
|
return [isLoading, networkError, monitors, monitorsSummary, filteredMonitors];
|
||||||
};
|
};
|
||||||
export { useSubscribeToMonitors };
|
export { useSubscribeToMonitors };
|
||||||
@@ -3,10 +3,12 @@ import { Stack, Typography } from "@mui/material";
|
|||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import CreateMonitorHeader from "../../../Components/MonitorCreateHeader";
|
import CreateMonitorHeader from "../../../Components/MonitorCreateHeader";
|
||||||
import MonitorTable from "./Components/MonitorTable";
|
import MonitorTable from "./Components/MonitorTable";
|
||||||
|
import Pagination from "../../../Components/Table/TablePagination";
|
||||||
import Fallback from "../../../Components/Fallback";
|
import Fallback from "../../../Components/Fallback";
|
||||||
import GenericFallback from "../../../Components/GenericFallback";
|
import GenericFallback from "../../../Components/GenericFallback";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
|
import { useState } from "react";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
import { useIsAdmin } from "../../../Hooks/useIsAdmin";
|
||||||
import { useSubscribeToMonitors } from "./Hooks/useSubscribeToMonitors";
|
import { useSubscribeToMonitors } from "./Hooks/useSubscribeToMonitors";
|
||||||
@@ -16,11 +18,23 @@ const BREADCRUMBS = [{ name: `Distributed Uptime`, path: "/distributed-uptime" }
|
|||||||
|
|
||||||
const DistributedUptimeMonitors = () => {
|
const DistributedUptimeMonitors = () => {
|
||||||
// Local state
|
// Local state
|
||||||
|
const [page, setPage] = useState(0);
|
||||||
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const [isLoading, networkError, monitors, monitorsSummary, filteredMonitors] =
|
const [isLoading, networkError, monitors, monitorsSummary, filteredMonitors] =
|
||||||
useSubscribeToMonitors();
|
useSubscribeToMonitors(page, rowsPerPage);
|
||||||
|
// Handlers
|
||||||
|
const handleChangePage = (event, newPage) => {
|
||||||
|
setPage(newPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeRowsPerPage = (event) => {
|
||||||
|
setRowsPerPage(event.target.value);
|
||||||
|
setPage(0);
|
||||||
|
};
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <SkeletonLayout />;
|
return <SkeletonLayout />;
|
||||||
@@ -69,6 +83,14 @@ const DistributedUptimeMonitors = () => {
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
monitors={filteredMonitors}
|
monitors={filteredMonitors}
|
||||||
/>
|
/>
|
||||||
|
<Pagination
|
||||||
|
itemCount={monitorsSummary?.totalMonitors ?? 0}
|
||||||
|
paginationLabel="monitors"
|
||||||
|
page={page}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
handleChangePage={handleChangePage}
|
||||||
|
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ const StatusPages = () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(10)}>
|
<Stack gap={theme.spacing(10)}>
|
||||||
<Breadcrumbs list={BREADCRUMBS} />
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
|
|||||||
Reference in new issue
Block a user