feat: adding skeleton to table body
This commit is contained in:
1 parent
478a8b7f13
commit
a517edfea3
3 files changed
+415
-379
No files matched your search
@@ -0,0 +1,31 @@
|
|||||||
|
import { Skeleton, TableBody, TableCell, TableRow } from "@mui/material";
|
||||||
|
const ROWS_NUMBER = 7;
|
||||||
|
const ROWS_ARRAY = Array.from({ length: ROWS_NUMBER }, (_, i) => i);
|
||||||
|
|
||||||
|
const TableBodySkeleton = () => {
|
||||||
|
return (
|
||||||
|
<TableBody>
|
||||||
|
{ROWS_ARRAY.map((row) => (
|
||||||
|
<TableRow key={row}>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Skeleton />
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { TableBodySkeleton };
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import {
|
import {
|
||||||
TableContainer,
|
TableContainer,
|
||||||
Table,
|
Table,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableRow,
|
TableRow,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableBody,
|
TableBody,
|
||||||
Paper,
|
Paper,
|
||||||
Box,
|
Box,
|
||||||
TablePagination,
|
TablePagination,
|
||||||
Stack,
|
Stack,
|
||||||
Typography,
|
Typography,
|
||||||
Button,
|
Button,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
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";
|
||||||
@@ -34,6 +34,7 @@ import RightArrow from "../../../../assets/icons/right-arrow.svg?react";
|
|||||||
import SelectorVertical from "../../../../assets/icons/selector-vertical.svg?react";
|
import SelectorVertical from "../../../../assets/icons/selector-vertical.svg?react";
|
||||||
import ActionsMenu from "../actionsMenu";
|
import ActionsMenu from "../actionsMenu";
|
||||||
import useUtils from "../../utils";
|
import useUtils from "../../utils";
|
||||||
|
import { TableBodySkeleton } from "./Skeleton";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component for pagination actions (first, previous, next, last).
|
* Component for pagination actions (first, previous, next, last).
|
||||||
@@ -48,386 +49,385 @@ import useUtils from "../../utils";
|
|||||||
* @returns {JSX.Element} Pagination actions component.
|
* @returns {JSX.Element} Pagination actions component.
|
||||||
*/
|
*/
|
||||||
const TablePaginationActions = (props) => {
|
const TablePaginationActions = (props) => {
|
||||||
const { count, page, rowsPerPage, onPageChange } = props;
|
const { count, page, rowsPerPage, onPageChange } = props;
|
||||||
const handleFirstPageButtonClick = (event) => {
|
const handleFirstPageButtonClick = (event) => {
|
||||||
onPageChange(event, 0);
|
onPageChange(event, 0);
|
||||||
};
|
};
|
||||||
const handleBackButtonClick = (event) => {
|
const handleBackButtonClick = (event) => {
|
||||||
onPageChange(event, page - 1);
|
onPageChange(event, page - 1);
|
||||||
};
|
};
|
||||||
const handleNextButtonClick = (event) => {
|
const handleNextButtonClick = (event) => {
|
||||||
onPageChange(event, page + 1);
|
onPageChange(event, page + 1);
|
||||||
};
|
};
|
||||||
const handleLastPageButtonClick = (event) => {
|
const handleLastPageButtonClick = (event) => {
|
||||||
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
|
onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ flexShrink: 0, ml: "24px" }}>
|
<Box sx={{ flexShrink: 0, ml: "24px" }}>
|
||||||
<Button
|
<Button
|
||||||
variant="group"
|
variant="group"
|
||||||
onClick={handleFirstPageButtonClick}
|
onClick={handleFirstPageButtonClick}
|
||||||
disabled={page === 0}
|
disabled={page === 0}
|
||||||
aria-label="first page"
|
aria-label="first page"
|
||||||
>
|
>
|
||||||
<LeftArrowDouble />
|
<LeftArrowDouble />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="group"
|
variant="group"
|
||||||
onClick={handleBackButtonClick}
|
onClick={handleBackButtonClick}
|
||||||
disabled={page === 0}
|
disabled={page === 0}
|
||||||
aria-label="previous page"
|
aria-label="previous page"
|
||||||
>
|
>
|
||||||
<LeftArrow />
|
<LeftArrow />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="group"
|
variant="group"
|
||||||
onClick={handleNextButtonClick}
|
onClick={handleNextButtonClick}
|
||||||
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
|
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
|
||||||
aria-label="next page"
|
aria-label="next page"
|
||||||
>
|
>
|
||||||
<RightArrow />
|
<RightArrow />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="group"
|
variant="group"
|
||||||
onClick={handleLastPageButtonClick}
|
onClick={handleLastPageButtonClick}
|
||||||
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
|
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
|
||||||
aria-label="last page"
|
aria-label="last page"
|
||||||
>
|
>
|
||||||
<RightArrowDouble />
|
<RightArrowDouble />
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
TablePaginationActions.propTypes = {
|
TablePaginationActions.propTypes = {
|
||||||
count: PropTypes.number.isRequired,
|
count: PropTypes.number.isRequired,
|
||||||
page: PropTypes.number.isRequired,
|
page: PropTypes.number.isRequired,
|
||||||
rowsPerPage: PropTypes.number.isRequired,
|
rowsPerPage: PropTypes.number.isRequired,
|
||||||
onPageChange: PropTypes.func.isRequired,
|
onPageChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
const MonitorTable = ({ isAdmin, filter, setLoading }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { determineState } = useUtils();
|
const { determineState } = useUtils();
|
||||||
|
|
||||||
const { rowsPerPage } = useSelector((state) => state.ui.monitors);
|
const { rowsPerPage } = useSelector((state) => state.ui.monitors);
|
||||||
const [page, setPage] = useState(0);
|
const authState = useSelector((state) => state.auth);
|
||||||
const [monitors, setMonitors] = useState([]);
|
const [page, setPage] = useState(0);
|
||||||
const [monitorCount, setMonitorCount] = useState(0);
|
const [monitors, setMonitors] = useState([]);
|
||||||
const authState = useSelector((state) => state.auth);
|
const [monitorCount, setMonitorCount] = useState(0);
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
const [sort, setSort] = useState({});
|
const [sort, setSort] = useState({});
|
||||||
const prevFilter = useRef(filter);
|
const prevFilter = useRef(filter);
|
||||||
|
|
||||||
const handleActionMenuDelete = () => {
|
const handleActionMenuDelete = () => {
|
||||||
setUpdateTrigger((prev) => !prev);
|
setUpdateTrigger((prev) => !prev);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangePage = (event, newPage) => {
|
const handleChangePage = (event, newPage) => {
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeRowsPerPage = (event) => {
|
const handleChangeRowsPerPage = (event) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
setRowsPerPage({
|
setRowsPerPage({
|
||||||
value: parseInt(event.target.value, 10),
|
value: parseInt(event.target.value, 10),
|
||||||
table: "monitors",
|
table: "monitors",
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchPage = useCallback(async () => {
|
const fetchPage = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const { authToken } = authState;
|
const { authToken } = authState;
|
||||||
const user = jwtDecode(authToken);
|
const user = jwtDecode(authToken);
|
||||||
const res = await networkService.getMonitorsByTeamId({
|
const res = await networkService.getMonitorsByTeamId({
|
||||||
authToken,
|
authToken,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
types: ["http", "ping"],
|
types: ["http", "ping"],
|
||||||
status: null,
|
status: null,
|
||||||
checkOrder: "desc",
|
checkOrder: "desc",
|
||||||
normalize: true,
|
normalize: true,
|
||||||
page: page,
|
page: page,
|
||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
field: sort.field,
|
field: sort.field,
|
||||||
order: sort.order,
|
order: sort.order,
|
||||||
});
|
});
|
||||||
setMonitors(res?.data?.data?.monitors ?? []);
|
setMonitors(res?.data?.data?.monitors ?? []);
|
||||||
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
}
|
}
|
||||||
}, [authState, page, rowsPerPage, filter, sort, setLoading]);
|
}, [authState, page, rowsPerPage, filter, sort, setLoading]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchPage();
|
fetchPage();
|
||||||
}, [
|
}, [updateTrigger, authState, page, rowsPerPage, filter, sort, setLoading, fetchPage]);
|
||||||
updateTrigger,
|
|
||||||
authState,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
filter,
|
|
||||||
sort,
|
|
||||||
setLoading,
|
|
||||||
fetchPage,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Listen for changes in filter, if new value reset the page
|
// Listen for changes in filter, if new value reset the page
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (prevFilter.current !== filter) {
|
if (prevFilter.current !== filter) {
|
||||||
setPage(0);
|
setPage(0);
|
||||||
fetchPage();
|
fetchPage();
|
||||||
}
|
}
|
||||||
prevFilter.current = filter;
|
prevFilter.current = filter;
|
||||||
}, [filter, fetchPage]);
|
}, [filter, fetchPage]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 = "";
|
||||||
if (sort.field !== field) {
|
if (sort.field !== field) {
|
||||||
order = "desc";
|
order = "desc";
|
||||||
} else {
|
} else {
|
||||||
order = sort.order === "asc" ? "desc" : "asc";
|
order = sort.order === "asc" ? "desc" : "asc";
|
||||||
}
|
}
|
||||||
setSort({ field, order });
|
setSort({ field, order });
|
||||||
|
|
||||||
const { authToken } = authState;
|
const { authToken } = authState;
|
||||||
const user = jwtDecode(authToken);
|
const user = jwtDecode(authToken);
|
||||||
|
|
||||||
const res = await networkService.getMonitorsByTeamId({
|
const res = await networkService.getMonitorsByTeamId({
|
||||||
authToken,
|
authToken,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
types: ["http", "ping"],
|
types: ["http", "ping"],
|
||||||
status: null,
|
status: null,
|
||||||
checkOrder: "desc",
|
checkOrder: "desc",
|
||||||
normalize: true,
|
normalize: true,
|
||||||
page: page,
|
page: page,
|
||||||
rowsPerPage: rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
filter: null,
|
filter: null,
|
||||||
field: field,
|
field: field,
|
||||||
order: order,
|
order: order,
|
||||||
});
|
});
|
||||||
setMonitors(res?.data?.data?.monitors ?? []);
|
setMonitors(res?.data?.data?.monitors ?? []);
|
||||||
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
setMonitorCount(res?.data?.data?.monitorCount ?? 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
<Table>
|
<Table>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell
|
<TableCell
|
||||||
sx={{ cursor: "pointer" }}
|
sx={{ cursor: "pointer" }}
|
||||||
onClick={() => handleSort("name")}
|
onClick={() => handleSort("name")}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
Host
|
Host
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
visibility: sort.field === "name" ? "visible" : "hidden",
|
visibility: sort.field === "name" ? "visible" : "hidden",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{sort.order === "asc" ? (
|
{sort.order === "asc" ? (
|
||||||
<ArrowUpwardRoundedIcon />
|
<ArrowUpwardRoundedIcon />
|
||||||
) : (
|
) : (
|
||||||
<ArrowDownwardRoundedIcon />
|
<ArrowDownwardRoundedIcon />
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</Box>
|
</Box>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell
|
<TableCell
|
||||||
sx={{ cursor: "pointer" }}
|
sx={{ cursor: "pointer" }}
|
||||||
onClick={() => handleSort("status")}
|
onClick={() => handleSort("status")}
|
||||||
>
|
>
|
||||||
{" "}
|
{" "}
|
||||||
<Box width="max-content">
|
<Box width="max-content">
|
||||||
{" "}
|
{" "}
|
||||||
Status
|
Status
|
||||||
<span
|
<span
|
||||||
style={{
|
style={{
|
||||||
visibility:
|
visibility: sort.field === "status" ? "visible" : "hidden",
|
||||||
sort.field === "status" ? "visible" : "hidden",
|
}}
|
||||||
}}
|
>
|
||||||
>
|
{sort.order === "asc" ? (
|
||||||
{sort.order === "asc" ? (
|
<ArrowUpwardRoundedIcon />
|
||||||
<ArrowUpwardRoundedIcon />
|
) : (
|
||||||
) : (
|
<ArrowDownwardRoundedIcon />
|
||||||
<ArrowDownwardRoundedIcon />
|
)}
|
||||||
)}
|
</span>
|
||||||
</span>
|
</Box>
|
||||||
</Box>
|
</TableCell>
|
||||||
</TableCell>
|
<TableCell>Response Time</TableCell>
|
||||||
<TableCell>Response Time</TableCell>
|
<TableCell>Type</TableCell>
|
||||||
<TableCell>Type</TableCell>
|
<TableCell>Actions</TableCell>
|
||||||
<TableCell>Actions</TableCell>
|
</TableRow>
|
||||||
</TableRow>
|
</TableHead>
|
||||||
</TableHead>
|
{monitors.length > 0 ? (
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{monitors.map((monitor) => {
|
{monitors.map((monitor) => {
|
||||||
let uptimePercentage = "";
|
let uptimePercentage = "";
|
||||||
let percentageColor = theme.palette.percentage.uptimeExcellent;
|
let percentageColor = theme.palette.percentage.uptimeExcellent;
|
||||||
|
|
||||||
// Determine uptime percentage and color based on the monitor's uptimePercentage value
|
// Determine uptime percentage and color based on the monitor's uptimePercentage value
|
||||||
if (monitor.uptimePercentage !== undefined) {
|
if (monitor.uptimePercentage !== undefined) {
|
||||||
uptimePercentage =
|
uptimePercentage =
|
||||||
monitor.uptimePercentage === 0
|
monitor.uptimePercentage === 0
|
||||||
? "0"
|
? "0"
|
||||||
: (monitor.uptimePercentage * 100).toFixed(2);
|
: (monitor.uptimePercentage * 100).toFixed(2);
|
||||||
|
|
||||||
percentageColor =
|
percentageColor =
|
||||||
monitor.uptimePercentage < 0.25
|
monitor.uptimePercentage < 0.25
|
||||||
? theme.palette.percentage.uptimePoor
|
? theme.palette.percentage.uptimePoor
|
||||||
: monitor.uptimePercentage < 0.5
|
: monitor.uptimePercentage < 0.5
|
||||||
? theme.palette.percentage.uptimeFair
|
? theme.palette.percentage.uptimeFair
|
||||||
: monitor.uptimePercentage < 0.75
|
: monitor.uptimePercentage < 0.75
|
||||||
? theme.palette.percentage.uptimeGood
|
? theme.palette.percentage.uptimeGood
|
||||||
: theme.palette.percentage.uptimeExcellent;
|
: theme.palette.percentage.uptimeExcellent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
url: monitor.url,
|
url: monitor.url,
|
||||||
title: monitor.name,
|
title: monitor.name,
|
||||||
percentage: uptimePercentage,
|
percentage: uptimePercentage,
|
||||||
percentageColor,
|
percentageColor,
|
||||||
status: determineState(monitor),
|
status: determineState(monitor),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={monitor._id}
|
key={monitor._id}
|
||||||
sx={{
|
sx={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
backgroundColor: theme.palette.background.accent,
|
backgroundColor: theme.palette.background.accent,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
navigate(`/monitors/${monitor._id}`);
|
navigate(`/monitors/${monitor._id}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Host key={monitor._id} params={params} />
|
<Host
|
||||||
</TableCell>
|
key={monitor._id}
|
||||||
<TableCell>
|
params={params}
|
||||||
<StatusLabel
|
/>
|
||||||
status={params.status}
|
</TableCell>
|
||||||
text={params.status}
|
<TableCell>
|
||||||
customStyles={{ textTransform: "capitalize" }}
|
<StatusLabel
|
||||||
/>
|
status={params.status}
|
||||||
</TableCell>
|
text={params.status}
|
||||||
<TableCell>
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
<BarChart checks={monitor.checks.slice().reverse()} />
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<span style={{ textTransform: "uppercase" }}>
|
<BarChart checks={monitor.checks.slice().reverse()} />
|
||||||
{monitor.type}
|
</TableCell>
|
||||||
</span>
|
<TableCell>
|
||||||
</TableCell>
|
<span style={{ textTransform: "uppercase" }}>{monitor.type}</span>
|
||||||
<TableCell>
|
</TableCell>
|
||||||
<ActionsMenu
|
<TableCell>
|
||||||
monitor={monitor}
|
<ActionsMenu
|
||||||
isAdmin={isAdmin}
|
monitor={monitor}
|
||||||
updateCallback={handleActionMenuDelete}
|
isAdmin={isAdmin}
|
||||||
/>
|
updateCallback={handleActionMenuDelete}
|
||||||
</TableCell>
|
/>
|
||||||
</TableRow>
|
</TableCell>
|
||||||
);
|
</TableRow>
|
||||||
})}
|
);
|
||||||
</TableBody>
|
})}
|
||||||
</Table>
|
</TableBody>
|
||||||
</TableContainer>
|
) : (
|
||||||
<Stack
|
<TableBodySkeleton />
|
||||||
direction="row"
|
)}
|
||||||
alignItems="center"
|
</Table>
|
||||||
justifyContent="space-between"
|
</TableContainer>
|
||||||
px={theme.spacing(4)}
|
<Stack
|
||||||
>
|
direction="row"
|
||||||
<Typography px={theme.spacing(2)} variant="body2" sx={{ opacity: 0.7 }}>
|
alignItems="center"
|
||||||
Showing {getRange()} of {monitorCount} monitor(s)
|
justifyContent="space-between"
|
||||||
</Typography>
|
px={theme.spacing(4)}
|
||||||
<TablePagination
|
>
|
||||||
component="div"
|
<Typography
|
||||||
count={monitorCount}
|
px={theme.spacing(2)}
|
||||||
page={page}
|
variant="body2"
|
||||||
onPageChange={handleChangePage}
|
sx={{ opacity: 0.7 }}
|
||||||
rowsPerPage={rowsPerPage}
|
>
|
||||||
rowsPerPageOptions={[5, 10, 15, 25]}
|
Showing {getRange()} of {monitorCount} monitor(s)
|
||||||
onRowsPerPageChange={handleChangeRowsPerPage}
|
</Typography>
|
||||||
ActionsComponent={TablePaginationActions}
|
<TablePagination
|
||||||
labelRowsPerPage="Rows per page"
|
component="div"
|
||||||
labelDisplayedRows={({ page, count }) =>
|
count={monitorCount}
|
||||||
`Page ${page + 1} of ${Math.max(0, Math.ceil(count / rowsPerPage))}`
|
page={page}
|
||||||
}
|
onPageChange={handleChangePage}
|
||||||
slotProps={{
|
rowsPerPage={rowsPerPage}
|
||||||
select: {
|
rowsPerPageOptions={[5, 10, 15, 25]}
|
||||||
MenuProps: {
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
||||||
keepMounted: true,
|
ActionsComponent={TablePaginationActions}
|
||||||
disableScrollLock: true,
|
labelRowsPerPage="Rows per page"
|
||||||
PaperProps: {
|
labelDisplayedRows={({ page, count }) =>
|
||||||
className: "pagination-dropdown",
|
`Page ${page + 1} of ${Math.max(0, Math.ceil(count / rowsPerPage))}`
|
||||||
sx: {
|
}
|
||||||
mt: 0,
|
slotProps={{
|
||||||
mb: theme.spacing(2),
|
select: {
|
||||||
},
|
MenuProps: {
|
||||||
},
|
keepMounted: true,
|
||||||
transformOrigin: { vertical: "bottom", horizontal: "left" },
|
disableScrollLock: true,
|
||||||
anchorOrigin: { vertical: "top", horizontal: "left" },
|
PaperProps: {
|
||||||
sx: { mt: theme.spacing(-2) },
|
className: "pagination-dropdown",
|
||||||
},
|
sx: {
|
||||||
inputProps: { id: "pagination-dropdown" },
|
mt: 0,
|
||||||
IconComponent: SelectorVertical,
|
mb: theme.spacing(2),
|
||||||
sx: {
|
},
|
||||||
ml: theme.spacing(4),
|
},
|
||||||
mr: theme.spacing(12),
|
transformOrigin: { vertical: "bottom", horizontal: "left" },
|
||||||
minWidth: theme.spacing(20),
|
anchorOrigin: { vertical: "top", horizontal: "left" },
|
||||||
textAlign: "left",
|
sx: { mt: theme.spacing(-2) },
|
||||||
"&.Mui-focused > div": {
|
},
|
||||||
backgroundColor: theme.palette.background.main,
|
inputProps: { id: "pagination-dropdown" },
|
||||||
},
|
IconComponent: SelectorVertical,
|
||||||
},
|
sx: {
|
||||||
},
|
ml: theme.spacing(4),
|
||||||
}}
|
mr: theme.spacing(12),
|
||||||
sx={{
|
minWidth: theme.spacing(20),
|
||||||
mt: theme.spacing(6),
|
textAlign: "left",
|
||||||
color: theme.palette.text.secondary,
|
"&.Mui-focused > div": {
|
||||||
"& svg path": {
|
backgroundColor: theme.palette.background.main,
|
||||||
stroke: theme.palette.text.tertiary,
|
},
|
||||||
strokeWidth: 1.3,
|
},
|
||||||
},
|
},
|
||||||
"& .MuiSelect-select": {
|
}}
|
||||||
border: 1,
|
sx={{
|
||||||
borderColor: theme.palette.border.light,
|
mt: theme.spacing(6),
|
||||||
borderRadius: theme.shape.borderRadius,
|
color: theme.palette.text.secondary,
|
||||||
},
|
"& svg path": {
|
||||||
}}
|
stroke: theme.palette.text.tertiary,
|
||||||
/>
|
strokeWidth: 1.3,
|
||||||
</Stack>
|
},
|
||||||
</>
|
"& .MuiSelect-select": {
|
||||||
);
|
border: 1,
|
||||||
|
borderColor: theme.palette.border.light,
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MonitorTable.propTypes = {
|
MonitorTable.propTypes = {
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
filter: PropTypes.string,
|
filter: PropTypes.string,
|
||||||
setLoading: PropTypes.func,
|
setLoading: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MemoizedMonitorTable = memo(MonitorTable);
|
const MemoizedMonitorTable = memo(MonitorTable);
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const monitorState = useSelector((state) => state.uptimeMonitors);
|
const monitorState = useSelector((state) => state.uptimeMonitors);
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
|
const dispatch = useDispatch({});
|
||||||
|
|
||||||
|
//TODO create components, and lower these states.
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
const dispatch = useDispatch({});
|
|
||||||
const debouncedFilter = useDebounce(search, 500);
|
const debouncedFilter = useDebounce(search, 500);
|
||||||
|
|
||||||
const handleSearch = (value) => {
|
const handleSearch = (value) => {
|
||||||
@@ -34,13 +36,17 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch]);
|
||||||
|
|
||||||
console.log(monitorState);
|
//Why are we tying loading to monitors length?
|
||||||
const loading = true;
|
const loading =
|
||||||
/* monitorState?.isLoading &&
|
monitorState?.isLoading; /* && monitorState?.monitorsSummary?.monitors?.length === 0 */
|
||||||
monitorState?.monitorsSummary?.monitors?.length === 0; */
|
|
||||||
const canCreateMonitor =
|
|
||||||
isAdmin && monitorState?.monitorsSummary?.monitors?.length !== 0;
|
|
||||||
|
|
||||||
|
const hasMonitors = monitorState?.monitorsSummary?.monitors?.length !== 0;
|
||||||
|
const noMonitors = monitorState?.monitorsSummary?.monitors?.length === 0;
|
||||||
|
const canAddMonitor = isAdmin && hasMonitors;
|
||||||
|
const needsAdmin = !isAdmin && noMonitors;
|
||||||
|
|
||||||
|
/* console.log({ loading });
|
||||||
|
console.log({ monitorState }); */
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
className="monitors"
|
className="monitors"
|
||||||
@@ -56,7 +62,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
gap={theme.spacing(6)}
|
gap={theme.spacing(6)}
|
||||||
>
|
>
|
||||||
<Greeting type="uptime" />
|
<Greeting type="uptime" />
|
||||||
{canCreateMonitor && (
|
{canAddMonitor && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
@@ -70,15 +76,13 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
{noMonitors && <Fallback isAdmin={isAdmin} />}
|
||||||
|
{needsAdmin && <p>Wait for an admin to add some monitors!</p>}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<SkeletonLayout />
|
<SkeletonLayout />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{isAdmin && monitorState?.monitorsSummary?.monitors?.length === 0 && (
|
{hasMonitors && (
|
||||||
<Fallback isAdmin={isAdmin} />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{monitorState?.monitorsSummary?.monitors?.length !== 0 && (
|
|
||||||
<>
|
<>
|
||||||
<Stack
|
<Stack
|
||||||
gap={theme.spacing(8)}
|
gap={theme.spacing(8)}
|
||||||
@@ -127,6 +131,7 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
borderColor={theme.palette.border.light}
|
borderColor={theme.palette.border.light}
|
||||||
backgroundColor={theme.palette.background.accent}
|
backgroundColor={theme.palette.background.accent}
|
||||||
>
|
>
|
||||||
|
{/* TODO maybe we dont need the conditional here, since we already check for monitors before */}
|
||||||
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
{monitorState?.monitorsSummary?.monitorCounts?.total || 0}
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
|
|||||||
Reference in new issue
Block a user