Merge pull request #1248 from bluewave-labs/1229-add-a-placeholder-if-there-are-no-infrastructure-monitors

- Update Falback component to accept ovelStart and enlarge the maxWid…
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-12-02 19:03:31 -08:00
commit 454c12954f
3 files changed
+116 -4

No files matched your search

+5 -4
View File
@@ -16,11 +16,11 @@ import "./index.css";
* @param {string} props.title - The title to be displayed in the fallback UI. * @param {string} props.title - The title to be displayed in the fallback UI.
* @param {Array<string>} props.checks - An array of strings representing the checks to display. * @param {Array<string>} props.checks - An array of strings representing the checks to display.
* @param {string} [props.link="/"] - The link to navigate to. * @param {string} [props.link="/"] - The link to navigate to.
* * @param {boolean} [props.vowelStart=false] - Whether the title starts with a vowel.
* @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, vowelStart = false }) => {
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: {vowelStart ? "An" : "A"} {title} is used to:
</Typography> </Typography>
{checks.map((check, index) => ( {checks.map((check, index) => (
<Check <Check
@@ -86,6 +86,7 @@ Fallback.propTypes = {
checks: PropTypes.arrayOf(PropTypes.string).isRequired, checks: PropTypes.arrayOf(PropTypes.string).isRequired,
link: PropTypes.string, link: PropTypes.string,
isAdmin: PropTypes.bool, isAdmin: PropTypes.bool,
vowelStart: PropTypes.bool,
}; };
export default Fallback; export default Fallback;
+38
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,7 +171,25 @@ function Infrastructure() {
}; };
}); });
let isActuallyLoading = isLoading && monitorState.monitors?.length === 0;
return ( return (
<Box
className="infrastructure-monitor"
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",
},
}}
>
{isActuallyLoading ? (
<SkeletonLayout />
) : monitorState.monitors?.length !== 0 ? (
<Stack gap={theme.spacing(8)}> <Stack gap={theme.spacing(8)}>
<Breadcrumbs list={BREADCRUMBS} /> <Breadcrumbs list={BREADCRUMBS} />
<Stack <Stack
@@ -324,6 +348,20 @@ function Infrastructure() {
/> />
</Stack> </Stack>
</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}
/>
)}
</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;