From 395d7412eb65b466d19943ce171ef57ebad12905 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 21 Feb 2025 15:05:47 -0800 Subject: [PATCH] new DePIN status chart --- .../Charts/DePINStatusPageBarChart/index.jsx | 181 ++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/Components/Charts/DePINStatusPageBarChart/index.jsx diff --git a/src/Components/Charts/DePINStatusPageBarChart/index.jsx b/src/Components/Charts/DePINStatusPageBarChart/index.jsx new file mode 100644 index 000000000..65c6278f1 --- /dev/null +++ b/src/Components/Charts/DePINStatusPageBarChart/index.jsx @@ -0,0 +1,181 @@ +// Components +import { Stack, Box, Tooltip, Typography } from "@mui/material"; + +// Utils +import { useTheme } from "@emotion/react"; +import { useState, useEffect } from "react"; +import PropTypes from "prop-types"; +import { formatDateWithTz } from "../../../Utils/timeUtils"; +import { useSelector } from "react-redux"; + +const PlaceholderCheck = ({ daysToShow }) => { + const theme = useTheme(); + + return ( + + ); +}; + +PlaceholderCheck.propTypes = { + daysToShow: PropTypes.number, +}; + +const Check = ({ check, daysToShow }) => { + const [animate, setAnimate] = useState(false); + + const theme = useTheme(); + useEffect(() => { + setAnimate(true); + }, []); + const uiTimezone = useSelector((state) => state.ui.timezone); + + return ( + + + {formatDateWithTz(check._id, "ddd, MMMM D, YYYY", uiTimezone)} + + + + + Uptime percentage + + + {check.upPercentage.toFixed(2)} + + {" "} + % + + + + + + } + placement="top" + key={`check-${check?._id}`} + slotProps={{ + popper: { + className: "bar-tooltip", + modifiers: [ + { + name: "offset", + options: { + offset: [0, -10], + }, + }, + ], + sx: { + "& .MuiTooltip-tooltip": { + backgroundColor: theme.palette.secondary.main, + border: 1, + borderColor: theme.palette.primary.lowContrast, + borderRadius: theme.shape.borderRadius, + boxShadow: theme.shape.boxShadow, + px: theme.spacing(4), + py: theme.spacing(3), + }, + "& .MuiTooltip-tooltip p": { + /* TODO Font size should point to theme */ + fontSize: 12, + color: theme.palette.secondary.contrastText, + fontWeight: 500, + }, + "& .MuiTooltip-tooltip span": { + /* TODO Font size should point to theme */ + fontSize: 11, + color: theme.palette.secondary.contrastText, + fontWeight: 600, + }, + }, + }, + }} + > + + + + + ); +}; + +Check.propTypes = { + check: PropTypes.object, + daysToShow: PropTypes.number, +}; + +const DePINStatusPageBarChart = ({ checks = [], daysToShow = 30 }) => { + if (checks.length !== daysToShow) { + const placeholders = Array(daysToShow - checks.length).fill("placeholder"); + checks = [...checks, ...placeholders]; + } + return ( + + {checks.map((check) => { + if (check === "placeholder") { + return ( + + ); + } + return ( + + ); + })} + + ); +}; + +DePINStatusPageBarChart.propTypes = { + checks: PropTypes.array, + daysToShow: PropTypes.number, +}; + +export default DePINStatusPageBarChart;