feat: abstracting table pagination

This commit is contained in:
Caio Cabral committed 2024-11-27 17:38:39 -05:00
1 parent 4bfe522f7d
commit fd278d3a97
8 files changed
+350 -329

No files matched your search

@@ -40,7 +40,7 @@ export const checkInfrastructureEndpointResolution = createAsyncThunk(
const res = await networkService.checkEndpointResolution({ const res = await networkService.checkEndpointResolution({
authToken: authToken, authToken: authToken,
monitorURL: monitorURL, monitorURL: monitorURL,
}) });
return res.data; return res.data;
} catch (error) { } catch (error) {
if (error.response && error.response.data) { if (error.response && error.response.data) {
@@ -53,7 +53,7 @@ export const checkInfrastructureEndpointResolution = createAsyncThunk(
return thunkApi.rejectWithValue(payload); return thunkApi.rejectWithValue(payload);
} }
} }
) );
export const getInfrastructureMonitorById = createAsyncThunk( export const getInfrastructureMonitorById = createAsyncThunk(
"infrastructureMonitors/getMonitorById", "infrastructureMonitors/getMonitorById",
@@ -87,6 +87,7 @@ export const getInfrastructureMonitorsByTeamId = createAsyncThunk(
authToken: token, authToken: token,
teamId: user.teamId, teamId: user.teamId,
types: ["hardware"], types: ["hardware"],
limit: 1,
}); });
return res.data; return res.data;
} catch (error) { } catch (error) {
@@ -112,7 +113,7 @@ export const updateInfrastructureMonitor = createAsyncThunk(
description: monitor.description, description: monitor.description,
interval: monitor.interval, interval: monitor.interval,
notifications: monitor.notifications, notifications: monitor.notifications,
threshold: monitor.threshold threshold: monitor.threshold,
}; };
const res = await networkService.updateMonitor({ const res = await networkService.updateMonitor({
authToken: authToken, authToken: authToken,
@@ -307,7 +308,9 @@ const infrastructureMonitorsSlice = createSlice({
.addCase(getInfrastructureMonitorById.rejected, (state, action) => { .addCase(getInfrastructureMonitorById.rejected, (state, action) => {
state.isLoading = false; state.isLoading = false;
state.success = false; state.success = false;
state.msg = action.payload ? action.payload.msg : "Failed to get infrastructure monitor"; state.msg = action.payload
? action.payload.msg
: "Failed to get infrastructure monitor";
}) })
// ***************************************************** // *****************************************************
// update Monitor // update Monitor
@@ -401,6 +404,7 @@ const infrastructureMonitorsSlice = createSlice({
}, },
}); });
export const { setInfrastructureMonitors, clearInfrastructureMonitorState } = infrastructureMonitorsSlice.actions; export const { setInfrastructureMonitors, clearInfrastructureMonitorState } =
infrastructureMonitorsSlice.actions;
export default infrastructureMonitorsSlice.reducer; export default infrastructureMonitorsSlice.reducer;
@@ -221,6 +221,7 @@ export const addDemoMonitors = createAsyncThunk(
} }
} }
); );
export const deleteAllMonitors = createAsyncThunk( export const deleteAllMonitors = createAsyncThunk(
"monitors/deleteAllMonitors", "monitors/deleteAllMonitors",
async (data, thunkApi) => { async (data, thunkApi) => {
@@ -0,0 +1,80 @@
import PropTypes from "prop-types";
import { Box, Button } from "@mui/material";
import LeftArrowDouble from "../../../../../Assets/icons/left-arrow-double.svg?react";
import RightArrowDouble from "../../../../../Assets/icons/right-arrow-double.svg?react";
import LeftArrow from "../../../../../Assets/icons/left-arrow.svg?react";
import RightArrow from "../../../../../Assets/icons/right-arrow.svg?react";
TablePaginationActions.propTypes = {
count: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
onPageChange: PropTypes.func.isRequired,
};
/**
* Component for pagination actions (first, previous, next, last).
*
* @component
* @param {Object} props
* @param {number} props.count - Total number of items.
* @param {number} props.page - Current page number.
* @param {number} props.rowsPerPage - Number of rows per page.
* @param {function} props.onPageChange - Callback function to handle page change.
*
* @returns {JSX.Element} Pagination actions component.
*/
function TablePaginationActions({ count, page, rowsPerPage, onPageChange }) {
const handleFirstPageButtonClick = (event) => {
onPageChange(event, 0);
};
const handleBackButtonClick = (event) => {
onPageChange(event, page - 1);
};
const handleNextButtonClick = (event) => {
onPageChange(event, page + 1);
};
const handleLastPageButtonClick = (event) => {
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
};
return (
<Box sx={{ flexShrink: 0, ml: "24px" }}>
<Button
variant="group"
onClick={handleFirstPageButtonClick}
disabled={page === 0}
aria-label="first page"
>
<LeftArrowDouble />
</Button>
<Button
variant="group"
onClick={handleBackButtonClick}
disabled={page === 0}
aria-label="previous page"
>
<LeftArrow />
</Button>
<Button
variant="group"
onClick={handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="next page"
>
<RightArrow />
</Button>
<Button
variant="group"
onClick={handleLastPageButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="last page"
>
<RightArrowDouble />
</Button>
</Box>
);
}
export { TablePaginationActions };
@@ -0,0 +1,117 @@
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
import { Stack, TablePagination, Typography } from "@mui/material";
import { TablePaginationActions } from "./Actions";
import SelectorVertical from "../../../../Assets/icons/selector-vertical.svg?react";
Pagination.propTypes = {
monitorCount: PropTypes.number.isRequired, // Total number of items for pagination.
page: PropTypes.number.isRequired, // Current page index.
rowsPerPage: PropTypes.number.isRequired, // Number of rows displayed per page.
handleChangePage: PropTypes.func.isRequired, // Function to handle page changes.
handleChangeRowsPerPage: PropTypes.func.isRequired, // Function to handle changes in rows per page.
};
const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
/**
* Pagination component for table navigation with customized styling and behavior.
*
* @param {object} props - Component properties.
* @param {number} props.monitorCount - Total number of monitors to paginate.
* @param {number} props.page - Current page index (0-based).
* @param {number} props.rowsPerPage - Number of rows to display per page.
* @param {function} props.handleChangePage - Callback for handling page changes.
* @param {function} props.handleChangeRowsPerPage - Callback for handling changes to rows per page.
* @returns {JSX.Element} The Pagination component.
*/
function Pagination({
monitorCount,
page,
rowsPerPage,
handleChangePage,
handleChangeRowsPerPage,
}) {
const theme = useTheme();
const start = page * rowsPerPage + 1;
const end = Math.min(page * rowsPerPage + rowsPerPage, monitorCount);
const range = `${start} - ${end}`;
return (
<Stack
direction="row"
alignItems="center"
justifyContent="space-between"
px={theme.spacing(4)}
marginTop={8}
>
<Typography
px={theme.spacing(2)}
variant="body2"
sx={{ opacity: 0.7 }}
>
Showing {range} of {monitorCount} monitor(s)
</Typography>
<TablePagination
component="div"
count={monitorCount}
page={page}
onPageChange={handleChangePage}
rowsPerPage={rowsPerPage}
rowsPerPageOptions={ROWS_PER_PAGE_OPTIONS}
onRowsPerPageChange={handleChangeRowsPerPage}
ActionsComponent={TablePaginationActions}
labelRowsPerPage="Rows per page"
labelDisplayedRows={({ page, count }) =>
`Page ${page + 1} of ${Math.max(0, Math.ceil(count / rowsPerPage))}`
}
slotProps={{
select: {
MenuProps: {
keepMounted: true,
disableScrollLock: true,
PaperProps: {
className: "pagination-dropdown",
sx: {
mt: 0,
mb: theme.spacing(2),
},
},
transformOrigin: { vertical: "bottom", horizontal: "left" },
anchorOrigin: { vertical: "top", horizontal: "left" },
sx: {
mt: theme.spacing(-2),
},
},
inputProps: { id: "pagination-dropdown" },
IconComponent: SelectorVertical,
sx: {
ml: theme.spacing(4),
mr: theme.spacing(12),
minWidth: theme.spacing(20),
textAlign: "left",
"&.Mui-focused > div": {
backgroundColor: theme.palette.background.main,
},
},
},
}}
sx={{
color: theme.palette.text.secondary,
"& svg path": {
stroke: theme.palette.text.tertiary,
strokeWidth: 1.3,
},
"& .MuiSelect-select": {
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
},
}}
/>
</Stack>
);
}
export { Pagination };
+107 -151
View File
@@ -13,27 +13,22 @@ import {
// TablePagination, // TablePagination,
// Typography, // Typography,
} from "@mui/material"; } from "@mui/material";
import { Heading } from "../../Components/Heading"; import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import Greeting from "../../Utils/greeting"; import Greeting from "../../Utils/greeting";
import Breadcrumbs from "../../Components/Breadcrumbs";
import { StatusLabel } from "../../Components/Label";
import { Gauge } from "../../Components/Charts/Gauge";
import GearIcon from "../../Assets/icons/settings-bold.svg?react"; import GearIcon from "../../Assets/icons/settings-bold.svg?react";
import CPUChipIcon from "../../Assets/icons/cpu-chip.svg?react"; import CPUChipIcon from "../../Assets/icons/cpu-chip.svg?react";
import Breadcrumbs from "../../Components/Breadcrumbs";
import { StatusLabel } from "../../Components/Label";
import { Heading } from "../../Components/Heading";
import { Gauge } from "../../Components/Charts/Gauge";
import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
import useUtils from "../Monitors/utils";
import { Pagination } from "./components/TablePagination";
const mockedData = { // const ROWS = Array.from(Array(20).keys()).map(() => mockedData);
ip: "https://192.168.1.30",
status: "up",
processor: "2Ghz",
cpu: 80,
mem: 50,
disk: 70,
};
const ROWS = Array.from(Array(20).keys()).map(() => mockedData);
console.log(ROWS);
const columns = [ const columns = [
{ label: "Host" }, { label: "Host" },
@@ -69,8 +64,6 @@ Apply to Monitor Table, and Account/Team.
Analyze existing BasicTable Analyze existing BasicTable
*/ */
import { useNavigate } from "react-router-dom";
/** /**
* This is the Infrastructure monitoring page. This is a work in progress * This is the Infrastructure monitoring page. This is a work in progress
* *
@@ -78,9 +71,33 @@ import { useNavigate } from "react-router-dom";
* @returns {JSX.Element} The infrastructure monitoring page. * @returns {JSX.Element} The infrastructure monitoring page.
*/ */
function Infrastructure() { function Infrastructure(/* {isAdmin} */) {
const theme = useTheme(); const theme = useTheme();
const { determineState } = useUtils();
const navigate = useNavigate(); const navigate = useNavigate();
const dispatch = useDispatch();
const { authToken } = useSelector((state) => state.auth);
const { isLoading, monitorsSummary, msg, success, ...rest } = useSelector(
(state) => state.infrastructureMonitors
);
const { monitorCounts = {}, monitors = [] } = monitorsSummary;
const { total: totalMonitors = 0 } = monitorCounts;
console.log({ monitors });
const monitorsAsRows = monitors.map((monitor) => ({
ip: monitor.name,
status: determineState(monitor),
processor: "2Ghz" /* How to retrieve that? */,
cpu: 80 /* How to retrieve that? */,
mem: 50 /* How to retrieve that? */,
disk: 70 /* How to retrieve that? */,
}));
useEffect(() => {
dispatch(getInfrastructureMonitorsByTeamId(authToken));
}, [authToken]);
// console.log({ isLoading, monitorsSummary, msg, success, rest });
return ( return (
<Stack <Stack
component="main" component="main"
@@ -134,7 +151,7 @@ function Infrastructure() {
borderColor={theme.palette.border.light} borderColor={theme.palette.border.light}
backgroundColor={theme.palette.background.accent} backgroundColor={theme.palette.background.accent}
> >
5 {totalMonitors}
</Box> </Box>
</Stack> </Stack>
<TableContainer <TableContainer
@@ -170,142 +187,81 @@ function Infrastructure() {
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{ROWS.map((row, index) => ( {
<TableRow key={index}> /* ROWS */ monitorsAsRows.map((row, index) => (
{/* TODO iterate over column and get column id, applying row[column.id] */} <TableRow key={index}>
<TableCell>{row.ip}</TableCell> {/* TODO iterate over column and get column id, applying row[column.id] */}
<TableCell align="center"> <TableCell>{row.ip}</TableCell>
<StatusLabel <TableCell align="center">
status={row.status} <StatusLabel
text={row.status} status={row.status}
/* Use capitalize inside of Status Label */ text={row.status}
/* Update component so we don't need to pass text and status separately*/ /* Use capitalize inside of Status Label */
customStyles={{ textTransform: "capitalize" }} /* Update component so we don't need to pass text and status separately*/
/> customStyles={{ textTransform: "capitalize" }}
</TableCell>
<TableCell align="center">
<Stack
direction={"row"}
justifyContent={"center"}
alignItems={"center"}
gap=".25rem"
>
<CPUChipIcon
width={20}
height={20}
/> />
{row.processor} </TableCell>
</Stack> <TableCell align="center">
</TableCell> <Stack
<TableCell align="center"> direction={"row"}
<Gauge justifyContent={"center"}
progressValue={row.cpu} alignItems={"center"}
containerWidth={60} gap=".25rem"
/> >
</TableCell> <CPUChipIcon
<TableCell align="center"> width={20}
<Gauge height={20}
progressValue={row.mem} />
containerWidth={60} {row.processor}
/> </Stack>
</TableCell> </TableCell>
<TableCell align="center"> <TableCell align="center">
<Gauge <Gauge
progressValue={row.disk} progressValue={row.cpu}
containerWidth={60} containerWidth={60}
/>
</TableCell>
<TableCell align="center">
{/* Get ActionsMenu from Monitor Table and create a component */}
<IconButton
sx={{
"& svg path": {
stroke: theme.palette.other.icon,
},
}}
>
<GearIcon
width={20}
height={20}
/> />
</IconButton> </TableCell>
</TableCell> <TableCell align="center">
</TableRow> <Gauge
))} progressValue={row.mem}
containerWidth={60}
/>
</TableCell>
<TableCell align="center">
<Gauge
progressValue={row.disk}
containerWidth={60}
/>
</TableCell>
<TableCell align="center">
{/* Get ActionsMenu from Monitor Table and create a component */}
<IconButton
sx={{
"& svg path": {
stroke: theme.palette.other.icon,
},
}}
>
<GearIcon
width={20}
height={20}
/>
</IconButton>
</TableCell>
</TableRow>
))
}
</TableBody> </TableBody>
</Table> </Table>
</TableContainer> </TableContainer>
{/* <Stack {/*
direction="row" TODO continue creating pagination component. It should change the current page, which will trigger refetch?
alignItems="center"
justifyContent="space-between" */}
marginTop={8} {/* <Pagination
> // monitorCount={totalMonitors}
<Typography page={0}
// px={theme.spacing(2)} /> */}
variant="body2"
// sx={{ opacity: 0.7 }}
>
Showing {getRange()} of {monitorCount} monitor(s)
</Typography>
<TablePagination
component="div"
count={monitorCount}
page={page}
onPageChange={handleChangePage}
rowsPerPage={rowsPerPage}
rowsPerPageOptions={[5, 10, 15, 25]}
onRowsPerPageChange={handleChangeRowsPerPage}
ActionsComponent={TablePaginationActions}
labelRowsPerPage="Rows per page"
labelDisplayedRows={({ page, count }) =>
`Page ${page + 1} of ${Math.max(0, Math.ceil(count / rowsPerPage))}`
}
slotProps={{
select: {
MenuProps: {
keepMounted: true,
disableScrollLock: true,
PaperProps: {
className: "pagination-dropdown",
sx: {
mt: 0,
mb: theme.spacing(2),
},
},
transformOrigin: { vertical: "bottom", horizontal: "left" },
anchorOrigin: { vertical: "top", horizontal: "left" },
sx: {
mt: theme.spacing(-2),
},
},
inputProps: { id: "pagination-dropdown" },
IconComponent: SelectorVertical,
sx: {
ml: theme.spacing(4),
mr: theme.spacing(12),
minWidth: theme.spacing(20),
textAlign: "left",
"&.Mui-focused > div": {
backgroundColor: theme.palette.background.main,
},
},
},
}}
sx={{
color: theme.palette.text.secondary,
"& svg path": {
stroke: theme.palette.text.tertiary,
strokeWidth: 1.3,
},
"& .MuiSelect-select": {
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
},
}}
/>
</Stack> */}
</Stack> </Stack>
</Stack> </Stack>
); );
@@ -1,4 +1,15 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useState, useEffect, memo, useCallback, useRef } from "react";
import { useNavigate } from "react-router";
import { useDispatch, useSelector } from "react-redux";
import { useTheme } from "@emotion/react";
import useUtils from "../../utils";
import { setRowsPerPage } from "../../../../Features/UI/uiSlice";
import { logger } from "../../../../Utils/Logger";
import { jwtDecode } from "jwt-decode";
import { networkService } from "../../../../main";
import { import {
TableContainer, TableContainer,
Table, Table,
@@ -8,106 +19,18 @@ import {
TableBody, TableBody,
Paper, Paper,
Box, Box,
TablePagination,
Stack,
Typography,
Button,
CircularProgress, CircularProgress,
} from "@mui/material"; } from "@mui/material";
import ActionsMenu from "../actionsMenu";
import Host from "../host";
import { StatusLabel } from "../../../../Components/Label";
import { TableBodySkeleton } from "./Skeleton";
import BarChart from "../../../../Components/Charts/BarChart";
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded"; import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded"; import ArrowUpwardRoundedIcon from "@mui/icons-material/ArrowUpwardRounded";
import { setRowsPerPage } from "../../../../Features/UI/uiSlice"; import { Pagination } from "../../../Infrastructure/components/TablePagination";
import { useState, useEffect, memo, useCallback, useRef } from "react";
import { useNavigate } from "react-router";
import { logger } from "../../../../Utils/Logger";
import Host from "../host";
import { StatusLabel } from "../../../../Components/Label";
import { jwtDecode } from "jwt-decode";
import { useDispatch, useSelector } from "react-redux";
import { networkService } from "../../../../main";
import { useTheme } from "@emotion/react";
import BarChart from "../../../../Components/Charts/BarChart";
import LeftArrowDouble from "../../../../assets/icons/left-arrow-double.svg?react";
import RightArrowDouble from "../../../../assets/icons/right-arrow-double.svg?react";
import LeftArrow from "../../../../assets/icons/left-arrow.svg?react";
import RightArrow from "../../../../assets/icons/right-arrow.svg?react";
import SelectorVertical from "../../../../assets/icons/selector-vertical.svg?react";
import ActionsMenu from "../actionsMenu";
import useUtils from "../../utils";
import { TableBodySkeleton } from "./Skeleton";
/**
* Component for pagination actions (first, previous, next, last).
*
* @component
* @param {Object} props
* @param {number} props.count - Total number of items.
* @param {number} props.page - Current page number.
* @param {number} props.rowsPerPage - Number of rows per page.
* @param {function} props.onPageChange - Callback function to handle page change.
*
* @returns {JSX.Element} Pagination actions component.
*/
const TablePaginationActions = (props) => {
const { count, page, rowsPerPage, onPageChange } = props;
const handleFirstPageButtonClick = (event) => {
onPageChange(event, 0);
};
const handleBackButtonClick = (event) => {
onPageChange(event, page - 1);
};
const handleNextButtonClick = (event) => {
onPageChange(event, page + 1);
};
const handleLastPageButtonClick = (event) => {
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
};
return (
<Box sx={{ flexShrink: 0, ml: "24px" }}>
<Button
variant="group"
onClick={handleFirstPageButtonClick}
disabled={page === 0}
aria-label="first page"
>
<LeftArrowDouble />
</Button>
<Button
variant="group"
onClick={handleBackButtonClick}
disabled={page === 0}
aria-label="previous page"
>
<LeftArrow />
</Button>
<Button
variant="group"
onClick={handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="next page"
>
<RightArrow />
</Button>
<Button
variant="group"
onClick={handleLastPageButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
aria-label="last page"
>
<RightArrowDouble />
</Button>
</Box>
);
};
TablePaginationActions.propTypes = {
count: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
rowsPerPage: PropTypes.number.isRequired,
onPageChange: PropTypes.func.isRequired,
};
const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => { const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
const theme = useTheme(); const theme = useTheme();
@@ -117,6 +40,7 @@ const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
const { rowsPerPage } = useSelector((state) => state.ui.monitors); const { rowsPerPage } = useSelector((state) => state.ui.monitors);
const authState = useSelector((state) => state.auth); const authState = useSelector((state) => state.auth);
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [monitors, setMonitors] = useState([]); const [monitors, setMonitors] = useState([]);
const [monitorCount, setMonitorCount] = useState(0); const [monitorCount, setMonitorCount] = useState(0);
@@ -195,11 +119,11 @@ const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
* Helper function to calculate the range of displayed rows. * Helper function to calculate the range of displayed rows.
* @returns {string} * @returns {string}
*/ */
const getRange = () => { // const getRange = () => {
let start = page * rowsPerPage + 1; // let start = page * rowsPerPage + 1;
let end = Math.min(page * rowsPerPage + rowsPerPage, monitorCount); // let end = Math.min(page * rowsPerPage + rowsPerPage, monitorCount);
return `${start} - ${end}`; // return `${start} - ${end}`;
}; // };
const handleSort = async (field) => { const handleSort = async (field) => {
let order = ""; let order = "";
@@ -392,78 +316,13 @@ const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
</TableBody> </TableBody>
</Table> </Table>
</TableContainer> </TableContainer>
<Stack <Pagination
direction="row" page={page}
alignItems="center" rowsPerPage={rowsPerPage}
justifyContent="space-between" handleChangePage={handleChangePage}
px={theme.spacing(4)} handleChangeRowsPerPage={handleChangeRowsPerPage}
marginTop={8} monitorCount={monitorCount}
> />
<Typography
px={theme.spacing(2)}
variant="body2"
sx={{ opacity: 0.7 }}
>
Showing {getRange()} of {monitorCount} monitor(s)
</Typography>
<TablePagination
component="div"
count={monitorCount}
page={page}
onPageChange={handleChangePage}
rowsPerPage={rowsPerPage}
rowsPerPageOptions={[5, 10, 15, 25]}
onRowsPerPageChange={handleChangeRowsPerPage}
ActionsComponent={TablePaginationActions}
labelRowsPerPage="Rows per page"
labelDisplayedRows={({ page, count }) =>
`Page ${page + 1} of ${Math.max(0, Math.ceil(count / rowsPerPage))}`
}
slotProps={{
select: {
MenuProps: {
keepMounted: true,
disableScrollLock: true,
PaperProps: {
className: "pagination-dropdown",
sx: {
mt: 0,
mb: theme.spacing(2),
},
},
transformOrigin: { vertical: "bottom", horizontal: "left" },
anchorOrigin: { vertical: "top", horizontal: "left" },
sx: {
mt: theme.spacing(-2),
},
},
inputProps: { id: "pagination-dropdown" },
IconComponent: SelectorVertical,
sx: {
ml: theme.spacing(4),
mr: theme.spacing(12),
minWidth: theme.spacing(20),
textAlign: "left",
"&.Mui-focused > div": {
backgroundColor: theme.palette.background.main,
},
},
},
}}
sx={{
color: theme.palette.text.secondary,
"& svg path": {
stroke: theme.palette.text.tertiary,
strokeWidth: 1.3,
},
"& .MuiSelect-select": {
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
},
}}
/>
</Stack>
</Box> </Box>
); );
}; };
+2
View File
@@ -20,6 +20,8 @@ const Monitors = ({ isAdmin }) => {
const authState = useSelector((state) => state.auth); const authState = useSelector((state) => state.auth);
const dispatch = useDispatch({}); const dispatch = useDispatch({});
console.log({ monitorState });
useEffect(() => { useEffect(() => {
dispatch(getUptimeMonitorsByTeamId(authState.authToken)); dispatch(getUptimeMonitorsByTeamId(authState.authToken));
}, [authState.authToken, dispatch]); }, [authState.authToken, dispatch]);
+3 -1
View File
@@ -1,13 +1,15 @@
import { useTheme } from "@mui/material"; import { useTheme } from "@mui/material";
const useUtils = () => { const useUtils = () => {
const theme = useTheme();
const determineState = (monitor) => { const determineState = (monitor) => {
if (monitor.isActive === false) return "paused"; if (monitor.isActive === false) return "paused";
if (monitor?.status === undefined) return "pending"; if (monitor?.status === undefined) return "pending";
return monitor?.status == true ? "up" : "down"; return monitor?.status == true ? "up" : "down";
}; };
/* TODO Refactor: from here on shouldn't live in a custom hook, but on theme, or constants */
const theme = useTheme();
const statusColor = { const statusColor = {
up: theme.palette.success.main, up: theme.palette.success.main,
down: theme.palette.error.main, down: theme.palette.error.main,