import { memo, useState } from "react"; import { useTheme } from "@mui/material"; import { ResponsiveContainer, BarChart, XAxis, Bar, Cell } from "recharts"; import PropTypes from "prop-types"; import CustomLabels from "./CustomLabels"; const getThemeColor = (responseTime) => { if (responseTime < 200) { return "success"; } else if (responseTime < 300) { return "warning"; } else { return "error"; } }; const UpBarChart = memo(({ groupedUpChecks = [], type, onBarHover }) => { const theme = useTheme(); const [chartHovered, setChartHovered] = useState(false); const [hoveredBarIndex, setHoveredBarIndex] = useState(null); return ( { setChartHovered(true); onBarHover({ time: null, totalChecks: 0, originalAvgResponseTime: 0 }); }} onMouseLeave={() => { setChartHovered(false); setHoveredBarIndex(null); onBarHover(null); }} > } /> {groupedUpChecks?.map((entry, index) => { const themeColor = getThemeColor(entry.originalAvgResponseTime); return ( { setHoveredBarIndex(index); onBarHover(entry); }} onMouseLeave={() => { setHoveredBarIndex(null); onBarHover({ time: null, totalChecks: 0, groupUptimePercentage: 0, }); }} /> ); })} ); }); // Add display name for the component UpBarChart.displayName = "UpBarChart"; // Validate props using PropTypes UpBarChart.propTypes = { monitor: PropTypes.shape({ groupedUpChecks: PropTypes.array, }), type: PropTypes.string, onBarHover: PropTypes.func, }; export default UpBarChart;