diff --git a/src/Components/Charts/ChartBox/EmptyView.jsx b/src/Components/Charts/ChartBox/EmptyView.jsx new file mode 100644 index 000000000..94b1af7b0 --- /dev/null +++ b/src/Components/Charts/ChartBox/EmptyView.jsx @@ -0,0 +1,108 @@ +// Components +import { Typography, Stack } from "@mui/material"; +import PropTypes from "prop-types"; +import { useTheme } from "@emotion/react"; +import IconBox from "../../IconBox"; + +/** + * `EmptyView` is a functional React component that displays an empty state view with an optional icon, header, and message. + * + * @component + * @param {Object} props - The properties that define the `EmptyView` component. + * @param {React.ReactNode} [props.icon] - An optional icon to display at the top of the empty view. + * @param {string} [props.header] - An optional header text displayed next to the icon. + * @param {string} [props.message="No Data"] - The message to be displayed in the empty view. + * @param {'h1' | 'h2' | 'h3'} [props.headingLevel="h2"] - The heading level for the message text. + * @param {string} [props.justifyContent="flex-start"] - The CSS `justify-content` value to align elements vertically. + * @param {string} [props.height="100%"] - The height of the empty view container. + * + * @example + * // Example usage of EmptyView component: + * } + * header="Average Response Time" + * message="No Response Time Available" + * headingLevel="h2" + * justifyContent="center" + * height="50%" + * /> + * + * @returns {React.Element} The `EmptyView` component with customizable icon, header, and message. + */ + +const EmptyView = ({ + icon, + header, + message = "No Data", + headingLevel = "h2", + justifyContent = "flex-start", + height = "100%" +}) => { + const theme = useTheme(); + return ( + + + + {icon && {icon}} + {header && {header}} + + + + {message} + + + + + ); +}; + +EmptyView.propTypes = { + message: PropTypes.string, + icon: PropTypes.node, + header: PropTypes.string, + headingLevel: PropTypes.oneOf(['h1', 'h2', 'h3']), + justifyContent: PropTypes.string, + height: PropTypes.string +}; + +export default EmptyView; diff --git a/src/Components/Charts/ChartBox/index.jsx b/src/Components/Charts/ChartBox/index.jsx index bd27d4775..4b72fe16a 100644 --- a/src/Components/Charts/ChartBox/index.jsx +++ b/src/Components/Charts/ChartBox/index.jsx @@ -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 = ({ @@ -12,8 +13,13 @@ const ChartBox = ({ Legend, borderRadiusRight = 4, sx, + noDataMessage, + isEmpty = false, }) => { const theme = useTheme(); + if (isEmpty) { + return ; + } return ( 0 ? totalUpChecks + totalDownChecks : 1; const groupedUptimePercentage = (totalUpChecks / denominator) * 100; + const noIncidentsMessage = "Great. No Incidents, yet!"; return ( } header="Uptime" + isEmpty={monitor?.uptimePercentage === 0 && !monitor?.upChecks?.length} > } header="Incidents" + noDataMessage={noIncidentsMessage} + isEmpty={monitor?.groupedDownChecks?.length === 0} >