Skip to content

Commit

Permalink
Feat: Empty View Low Level Component
Browse files Browse the repository at this point in the history
  • Loading branch information
Br0wnHammer committed Feb 19, 2025
1 parent e5246e8 commit 2879126
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/Components/Charts/ChartBox/EmptyView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Components
import { Typography, Stack } from "@mui/material";
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
import IconBox from "../../IconBox";

const EmptyView = ({
icon,
header,
message = "No Data",
size = "h2",
borderRadiusRight = 4,
justifyContent = "flex-start",
height = "300px"
}) => {
const theme = useTheme();
return (
<Stack
flex={1}
direction="row"
sx={{
backgroundColor: theme.palette.primary.main,

border: 1,
borderStyle: "solid",
borderColor: theme.palette.primary.lowContrast,
borderRadius: 2,
borderTopRightRadius: borderRadiusRight,
borderBottomRightRadius: borderRadiusRight,
}}
>
<Stack
flex={1}
alignItems="center"
sx={{
padding: theme.spacing(8),
justifyContent,
gap: theme.spacing(8),
height,
minWidth: 250,
"& h2": {
color: theme.palette.primary.contrastTextSecondary,
fontSize: 15,
fontWeight: 500,
},

"& tspan, & text": {
fill: theme.palette.primary.contrastTextTertiary,
},
}}
>
<Stack
alignSelf="flex-start"
direction="row"
alignItems="center"
gap={theme.spacing(6)}
>
{icon && <IconBox>{icon}</IconBox>}
{header && <Typography component="h2">{header}</Typography>}
</Stack>
<Stack
flex={1}
justifyContent="center"
alignItems="center"
>
<Typography component={size}>
{message}
</Typography>
</Stack>
</Stack>
</Stack>
);
};

EmptyView.propTypes = {
message: PropTypes.string,
icon: PropTypes.node,
header: PropTypes.string,
size: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'body1', 'body2'])
};

export default EmptyView;
8 changes: 8 additions & 0 deletions src/Components/Charts/ChartBox/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react";
import IconBox from "../../IconBox";
import EmptyView from "./EmptyView";
import PropTypes from "prop-types";

const ChartBox = ({
Expand All @@ -12,8 +13,13 @@ const ChartBox = ({
Legend,
borderRadiusRight = 4,
sx,
noDataMessage,
isEmpty = false,
}) => {
const theme = useTheme();
if (isEmpty) {
return <EmptyView icon={icon} header={header} message={noDataMessage} />;
}
return (
<Stack
flex={1}
Expand Down Expand Up @@ -88,4 +94,6 @@ ChartBox.propTypes = {
icon: PropTypes.node,
header: PropTypes.string,
height: PropTypes.string,
noDataMessage: PropTypes.string,
isEmpty: PropTypes.bool
};
3 changes: 3 additions & 0 deletions src/Pages/Uptime/Details/Components/ChartBoxes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ChartBoxes = ({
<ChartBox
icon={<UptimeIcon />}
header="Uptime"
isEmpty={monitor?.uptimePercentage === 0 && !monitor?.upChecks?.length}
>
<Stack
width={"100%"}
Expand Down Expand Up @@ -95,6 +96,8 @@ const ChartBoxes = ({
<ChartBox
icon={<IncidentsIcon />}
header="Incidents"
noDataMessage="Great. No Incidents, yet!"
isEmpty={!monitor?.groupedDownChecks?.length}
>
<Stack width={"100%"}>
<Box position="relative">
Expand Down

0 comments on commit 2879126

Please sign in to comment.