- Update Falback component to accept ovelStart and enlarge the maxWidth to fit into one line

- Add empty page when there is no infrastructure monitors
This commit is contained in:
Shemy Gan committed 2024-12-02 10:08:41 -05:00
1 parent 8e831bdb65
commit 0e8bccfea1
3 files changed
+261 -150

No files matched your search

+3 -3
View File
@@ -20,7 +20,7 @@ import "./index.css";
* @returns {JSX.Element} The rendered fallback UI. * @returns {JSX.Element} The rendered fallback UI.
*/ */
const Fallback = ({ title, checks, link = "/", isAdmin }) => { const Fallback = ({ title, checks, link = "/", isAdmin, ovalStart }) => {
const theme = useTheme(); const theme = useTheme();
const navigate = useNavigate(); const navigate = useNavigate();
const mode = useSelector((state) => state.ui.mode); const mode = useSelector((state) => state.ui.mode);
@@ -48,7 +48,7 @@ const Fallback = ({ title, checks, link = "/", isAdmin }) => {
</Box> </Box>
<Stack <Stack
gap={theme.spacing(4)} gap={theme.spacing(4)}
maxWidth={"275px"} maxWidth={"300px"}
zIndex={1} zIndex={1}
> >
<Typography <Typography
@@ -56,7 +56,7 @@ const Fallback = ({ title, checks, link = "/", isAdmin }) => {
marginY={theme.spacing(4)} marginY={theme.spacing(4)}
color={theme.palette.text.tertiary} color={theme.palette.text.tertiary}
> >
A {title} is used to: {ovalStart ? "An" : "A"} {title} is used to:
</Typography> </Typography>
{checks.map((check, index) => ( {checks.map((check, index) => (
<Check <Check
+185 -147
View File
@@ -4,6 +4,8 @@ import { /* useDispatch, */ useSelector } from "react-redux";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import useUtils from "../Monitors/utils"; import useUtils from "../Monitors/utils";
import { jwtDecode } from "jwt-decode"; import { jwtDecode } from "jwt-decode";
import SkeletonLayout from "./skeleton";
import Fallback from "../../Components/Fallback";
// 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 { import {
@@ -77,6 +79,7 @@ function Infrastructure() {
/* Adding this custom hook so we can avoid using the HOC approach that can lower performance (we are calling the admin logic N times on initializing the project. using a custom hook will cal it ass needed ) */ /* Adding this custom hook so we can avoid using the HOC approach that can lower performance (we are calling the admin logic N times on initializing the project. using a custom hook will cal it ass needed ) */
const isAdmin = useIsAdmin(); const isAdmin = useIsAdmin();
const theme = useTheme(); const theme = useTheme();
const [isLoading, setIsLoading] = useState(true);
const navigate = useNavigate(); const navigate = useNavigate();
const navigateToCreate = () => navigate("/infrastructure/create"); const navigateToCreate = () => navigate("/infrastructure/create");
@@ -99,6 +102,7 @@ function Infrastructure() {
const fetchMonitors = async () => { const fetchMonitors = async () => {
try { try {
setIsLoading(true);
const response = await networkService.getMonitorsByTeamId({ const response = await networkService.getMonitorsByTeamId({
authToken, authToken,
teamId: user.teamId, teamId: user.teamId,
@@ -116,6 +120,8 @@ function Infrastructure() {
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally {
setIsLoading(false);
} }
}; };
@@ -165,168 +171,200 @@ function Infrastructure() {
}; };
}); });
let isActuallyLoading = isLoading && monitorState.monitors?.length === 0;
return ( return (
<Stack <Box
component="main" className="infrastructure-monitor"
style={{ width: "100%", gap: "1rem" }} sx={{
':has(> [class*="fallback__"])': {
position: "relative",
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
borderStyle: "dashed",
backgroundColor: theme.palette.background.main,
overflow: "hidden",
},
}}
> >
<Breadcrumbs list={BREADCRUMBS} /> {isActuallyLoading ? (
<Stack <SkeletonLayout />
direction="row" ) : monitorState.monitors?.length !== 0 ? (
sx={{ <Stack
justifyContent: "end", component="main"
alignItems: "center", style={{ width: "100%", gap: "1rem" }}
gap: "1rem", >
flexWrap: "wrap", <Breadcrumbs list={BREADCRUMBS} />
marginBottom: "2rem", <Stack
}} direction="row"
> sx={{
{/* justifyContent: "end",
alignItems: "center",
gap: "1rem",
flexWrap: "wrap",
marginBottom: "2rem",
}}
>
{/*
This will be removed from here, but keeping the commented code to remind me to add a max width to the greeting component This will be removed from here, but keeping the commented code to remind me to add a max width to the greeting component
<Box style={{ maxWidth: "65ch" }}> <Box style={{ maxWidth: "65ch" }}>
<Greeting type="uptime" /> <Greeting type="uptime" />
</Box> */} </Box> */}
<Button <Button
variant="contained" variant="contained"
color="primary" color="primary"
onClick={navigateToCreate} onClick={navigateToCreate}
sx={{ fontWeight: 500 }} sx={{ fontWeight: 500 }}
> >
Create infrastructure monitor Create infrastructure monitor
</Button> </Button>
</Stack> </Stack>
<Stack <Stack
sx={{ sx={{
gap: "1rem", gap: "1rem",
}} }}
>
<Stack
direction="row"
sx={{
alignItems: "center",
gap: ".25rem",
flexWrap: "wrap",
}}
>
<Heading component="h2">Infrastructure monitors</Heading>
{/* TODO Correct the class current-monitors-counter, there are some unnecessary things there */}
<Box
component="span"
className="current-monitors-counter"
color={theme.palette.text.primary}
border={1}
borderColor={theme.palette.border.light}
backgroundColor={theme.palette.background.accent}
> >
{totalMonitors} <Stack
</Box> direction="row"
</Stack> sx={{
<TableContainer component={Paper}> alignItems: "center",
<Table stickyHeader> gap: ".25rem",
<TableHead sx={{ backgroundColor: theme.palette.background.accent }}> flexWrap: "wrap",
<TableRow> }}
{columns.map((column, index) => ( >
<TableCell <Heading component="h2">Infrastructure monitors</Heading>
key={index} {/* TODO Correct the class current-monitors-counter, there are some unnecessary things there */}
align={index === 0 ? "left" : "center"} <Box
sx={{ component="span"
backgroundColor: theme.palette.background.accent, className="current-monitors-counter"
}} color={theme.palette.text.primary}
> border={1}
{column.label} borderColor={theme.palette.border.light}
</TableCell> backgroundColor={theme.palette.background.accent}
))} >
</TableRow> {totalMonitors}
</TableHead> </Box>
<TableBody> </Stack>
{monitorsAsRows.map((row) => { <TableContainer component={Paper}>
return ( <Table stickyHeader>
<TableRow <TableHead sx={{ backgroundColor: theme.palette.background.accent }}>
key={row.id} <TableRow>
onClick={() => openDetails(row.id)} {columns.map((column, index) => (
sx={{ <TableCell
cursor: "pointer", key={index}
"&:hover": { align={index === 0 ? "left" : "center"}
backgroundColor: theme.palette.background.accent,
},
}}
>
{/* TODO iterate over column and get column id, applying row[column.id] */}
<TableCell>
<Host
title={row.name}
url={row.url}
percentage={row.uptimePercentage}
percentageColor={row.percentageColor}
/>
</TableCell>
<TableCell align="center">
<StatusLabel
status={row.status}
text={row.status}
/* Use capitalize inside of Status Label */
/* 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}
</Stack>
</TableCell>
<TableCell align="center">
<CustomGauge progress={row.cpu} />
</TableCell>
<TableCell align="center">
<CustomGauge progress={row.mem} />
</TableCell>
<TableCell align="center">
<CustomGauge progress={row.disk} />
</TableCell>
<TableCell align="center">
{/* Get ActionsMenu from Monitor Table and create a component */}
<IconButton
sx={{ sx={{
"& svg path": { backgroundColor: theme.palette.background.accent,
stroke: theme.palette.other.icon, }}
>
{column.label}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{monitorsAsRows.map((row) => {
return (
<TableRow
key={row.id}
onClick={() => openDetails(row.id)}
sx={{
cursor: "pointer",
"&:hover": {
backgroundColor: theme.palette.background.accent,
}, },
}} }}
> >
<InfrastructureMenu {/* TODO iterate over column and get column id, applying row[column.id] */}
monitor={row} <TableCell>
isAdmin={isAdmin} <Host
updateCallback={handleActionMenuDelete} title={row.name}
/> url={row.url}
{/* <GearIcon percentage={row.uptimePercentage}
percentageColor={row.percentageColor}
/>
</TableCell>
<TableCell align="center">
<StatusLabel
status={row.status}
text={row.status}
/* Use capitalize inside of Status Label */
/* 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}
</Stack>
</TableCell>
<TableCell align="center">
<CustomGauge progress={row.cpu} />
</TableCell>
<TableCell align="center">
<CustomGauge progress={row.mem} />
</TableCell>
<TableCell align="center">
<CustomGauge progress={row.disk} />
</TableCell>
<TableCell align="center">
{/* Get ActionsMenu from Monitor Table and create a component */}
<IconButton
sx={{
"& svg path": {
stroke: theme.palette.other.icon,
},
}}
>
<InfrastructureMenu
monitor={row}
isAdmin={isAdmin}
updateCallback={handleActionMenuDelete}
/>
{/* <GearIcon
width={20} width={20}
height={20} height={20}
/> */} /> */}
</IconButton> </IconButton>
</TableCell> </TableCell>
</TableRow> </TableRow>
); );
})} })}
</TableBody> </TableBody>
</Table> </Table>
</TableContainer> </TableContainer>
<Pagination <Pagination
monitorCount={totalMonitors} monitorCount={totalMonitors}
page={page} page={page}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
handleChangePage={handleChangePage} handleChangePage={handleChangePage}
handleChangeRowsPerPage={handleChangeRowsPerPage} handleChangeRowsPerPage={handleChangeRowsPerPage}
/>
</Stack>
</Stack>
) : (
<Fallback
ovalStart={true}
title="infrastructure monitor"
checks={[
"Track the performance of your servers",
"Identify bottlenecks and optimize usage",
"Ensure reliability with real-time monitoring",
]}
link="/infrastructure/create"
isAdmin={isAdmin}
/> />
</Stack> )}
</Stack> </Box>
); );
} }
@@ -0,0 +1,73 @@
import { Box, Skeleton, Stack } from "@mui/material";
import { useTheme } from "@emotion/react";
/**
* Renders a skeleton layout.
*
* @returns {JSX.Element}
*/
const SkeletonLayout = () => {
const theme = useTheme();
return (
<Stack gap={theme.spacing(2)}>
<Stack
direction="row"
justifyContent="space-between"
mb={theme.spacing(12)}
>
<Box width="80%">
<Skeleton
variant="rounded"
width="25%"
height={24}
/>
<Skeleton
variant="rounded"
width="50%"
height={19.5}
sx={{ mt: theme.spacing(2) }}
/>
</Box>
<Skeleton
variant="rounded"
width="20%"
height={34}
sx={{ alignSelf: "flex-end" }}
/>
</Stack>
<Stack
direction="row"
flexWrap="wrap"
gap={theme.spacing(12)}
>
<Skeleton
variant="rounded"
width="100%"
height={120}
sx={{ flex: "35%" }}
/>
<Skeleton
variant="rounded"
width="100%"
height={120}
sx={{ flex: "35%" }}
/>
<Skeleton
variant="rounded"
width="100%"
height={120}
sx={{ flex: "35%" }}
/>
<Skeleton
variant="rounded"
width="100%"
height={120}
sx={{ flex: "35%" }}
/>
</Stack>
</Stack>
);
};
export default SkeletonLayout;