feat: fixing lots of colors

This commit is contained in:
Caio Cabral committed 2025-01-12 12:28:13 -05:00
1 parent 61aaa8489a
commit 541a5b3f12
33 files changed
+194 -331

No files matched your search

@@ -58,7 +58,7 @@ const DownBarChart = memo(({ stats, type, onBarHover }) => {
hoveredBarIndex === index
? theme.palette.error.main
: chartHovered
? theme.palette.error.light
? theme.palette.error.contrastText
: theme.palette.error.main
}
onMouseEnter={() => {
@@ -29,12 +29,12 @@ const ResponseGaugeChart = ({ avgResponseTime }) => {
? {
category: "Acceptable",
main: theme.palette.warning.main,
bg: theme.palette.warning.dark,
bg: theme.palette.warning.lowContrast,
}
: {
category: "Poor",
main: theme.palette.error.main,
bg: theme.palette.error.light,
bg: theme.palette.error.contrastText,
};
return (
@@ -4,18 +4,28 @@ 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(({ stats, type, onBarHover }) => {
const theme = useTheme();
const [chartHovered, setChartHovered] = useState(false);
const [hoveredBarIndex, setHoveredBarIndex] = useState(null);
const getColorRange = (responseTime) => {
/* const getColorRange = (responseTime) => {
return responseTime < 200
? { main: theme.palette.success.main, light: theme.palette.success.light }
: responseTime < 300
? { main: theme.palette.warning.main, light: theme.palette.warning.light }
: { main: theme.palette.error.main, light: theme.palette.error.light };
};
}; */
return (
<ResponsiveContainer
@@ -59,11 +69,19 @@ const UpBarChart = memo(({ stats, type, onBarHover }) => {
background={{ fill: "transparent" }}
>
{stats.upChecks.map((entry, index) => {
let { main, light } = getColorRange(entry.avgResponseTime);
/* let { main, light } = getColorRange(entry.avgResponseTime); */
const themeColor = getThemeColor(entry.avgResponseTime);
console.log(themeColor);
return (
<Cell
key={`cell-${entry.time}`}
fill={hoveredBarIndex === index ? main : chartHovered ? light : main}
fill={
hoveredBarIndex === index
? theme.palette[themeColor].main
: chartHovered
? theme.palette[themeColor].accent
: theme.palette[themeColor].main
}
onMouseEnter={() => {
setHoveredBarIndex(index);
onBarHover(entry);
+5 -2
View File
@@ -33,7 +33,7 @@ import ResponseGaugeChart from "./Charts/ResponseGaugeChart";
*/
const DetailsPage = () => {
const theme = useTheme();
const { statusColor, statusStyles, statusMsg, determineState } = useUtils();
const { statusColor, statusMsg, determineState } = useUtils();
const isAdmin = useIsAdmin();
const [monitor, setMonitor] = useState({});
const { monitorId } = useParams();
@@ -236,7 +236,10 @@ const DetailsPage = () => {
gap={theme.spacing(8)}
>
<StatBox
sx={statusStyles[determineState(monitor)]}
/* sx={getStatusStyles(determineState(monitor))} */
/* statusStyles[determineState(monitor)] */
gradient={true}
status={determineState(monitor)}
heading={"active for"}
subHeading={splitDuration(monitor?.stats?.timeSinceLastFalseCheck)}
/>
@@ -26,7 +26,12 @@ const CurrentMonitoring = ({ totalMonitors, monitors, isAdmin, handlePause }) =>
alignItems="center"
mb={theme.spacing(8)}
>
<Heading component="h2">Uptime monitors</Heading>
<Heading
component="h2"
style={{ color: theme.palette.primary.contrastTextSecondary }}
>
Uptime monitors
</Heading>
<Box
className="current-monitors-counter"
-39
View File
@@ -72,45 +72,6 @@ const UptimeMonitors = () => {
>
Create new
</Button>
<Button
variant="contained"
color="success"
onClick={() => {
navigate("/uptime/create");
}}
sx={{
fontWeight: 500,
whiteSpace: "nowrap",
}}
>
Create new
</Button>
<Button
variant="contained"
color="warning"
onClick={() => {
navigate("/uptime/create");
}}
sx={{
fontWeight: 500,
whiteSpace: "nowrap",
}}
>
Create new
</Button>
<Button
variant="contained"
color="error"
onClick={() => {
navigate("/uptime/create");
}}
sx={{
fontWeight: 500,
whiteSpace: "nowrap",
}}
>
Create new
</Button>
</>
)}
</Stack>
+29 -24
View File
@@ -32,8 +32,34 @@ const useUtils = () => {
/* This is used on
1) Details > Gradient card */
/* These are rediections. We should do something that maps up to success, down to error, and get the theme by that
See Client\src\Components\Label\index.jsx
*/
const statusToTheme = {
up: "success",
down: "error",
paused: "warning",
pending: "secondary",
"cannot resolve": "tertiary",
};
const getStatusStyles = (status) => {
const themeColor = statusToTheme[status];
return {
backgroundColor: theme.palette[themeColor].lowContrast,
background: `linear-gradient(340deg, ${theme.palette[themeColor].main} -60%, ${theme.palette[themeColor].lowContrast} 35%)`,
borderColor: theme.palette[themeColor].lowContrast,
"& h2": {
color: theme.palette[themeColor].contrastText,
textTransform: "uppercase",
},
"& p": {
color: theme.palette[themeColor].contrastText,
},
};
};
const statusStyles = {
up: {
backgroundColor: theme.palette.success.lowContrast,
@@ -64,36 +90,15 @@ const useUtils = () => {
/* These are rediections. We should do something that maps up to success, down to error, and get the theme by that
*/
const pagespeedStyles = {
up: {
bg: theme.palette.success.dark,
light: theme.palette.success.light,
stroke: theme.palette.success.main,
},
down: {
bg: theme.palette.error.dark,
light: theme.palette.error.light,
stroke: theme.palette.error.main,
},
paused: {
bg: theme.palette.warning.dark,
light: theme.palette.warning.light,
stroke: theme.palette.warning.main,
},
pending: {
bg: theme.palette.warning.dark,
light: theme.palette.warning.light,
stroke: theme.palette.warning.main,
},
};
return {
determineState,
statusColor,
statusMsg,
pagespeedStatusMsg,
pagespeedStyles,
statusStyles,
statusToTheme,
getStatusStyles,
};
};