Status label refactor (#478)

* Refactored status label

* Updated colors and replaced old components

* Updated docs
This commit is contained in:
Daniel C authored and GitHub committed 2024-07-29 22:59:58 -07:00
1 parent 0611051c5f
commit 5fe92f2b31
6 files changed
+47 -84

No files matched your search

+17 -26
View File
@@ -117,34 +117,32 @@ ColoredLabel.propTypes = {
/** /**
* @component * @component
* @param {Object} props * @param {Object} props
* @param {'Seen' | 'Waiting' | 'New' | 'Active'} props.status - The status for the label * @param { 'up' | 'down' | 'cannot resolve'} props.status - The status for the label
* @param {string} props.dot - The color of the dot * @param {string} props.text - The text of the label
* @returns {JSX.Element} * @returns {JSX.Element}
* @example * @example
* // Render an active label * // Render an active label
* <StatusLabel status="Active" /> * <StatusLabel status="up" text="Active" />
*/ */
const StatusLabel = ({ status, dot, customStyles }) => { const StatusLabel = ({ status, text, customStyles }) => {
const theme = useTheme(); const theme = useTheme();
// Look up the color for the status
const colorLookup = { const { borderColor, bgColor, dotColor } = theme.label[status];
Seen: theme.palette.labelGray.color,
Waiting: theme.palette.labelRed.color,
New: theme.palette.labelOrange.color,
Active: theme.palette.labelGreen.color,
Down: theme.palette.error.main, // Assuming theme.palette.error.main is red
};
// Look up the color for the status, default to labelGray if not found
const color = colorLookup[status] || theme.palette.labelGray.color;
return ( return (
<BaseLabel label={status} styles={customStyles}> <BaseLabel
label={text}
styles={{
backgroundColor: bgColor,
borderColor: borderColor,
...customStyles,
}}
>
<Box <Box
width={7} width={7}
height={7} height={7}
bgcolor={dot || color} bgcolor={dotColor}
borderRadius="50%" borderRadius="50%"
marginRight="5px" marginRight="5px"
/> />
@@ -153,15 +151,8 @@ const StatusLabel = ({ status, dot, customStyles }) => {
}; };
StatusLabel.propTypes = { StatusLabel.propTypes = {
status: PropTypes.oneOf([ status: PropTypes.oneOf(["up", "down", "cannot resolve"]),
"Seen", text: PropTypes.string,
"Waiting",
"New",
"Active",
"Up",
"Down",
"Cannot resolve",
]),
customStyles: PropTypes.object, customStyles: PropTypes.object,
}; };
+1 -13
View File
@@ -76,24 +76,12 @@ const Incidents = () => {
else if (filter === "down") return incident.status === false; else if (filter === "down") return incident.status === false;
}) })
.map((incident, idx) => { .map((incident, idx) => {
const params = {
status: "Down",
backgroundColor: "var(--env-var-color-21)",
statusDotColor: "var(--env-var-color-19)",
};
return { return {
id: idx, id: idx,
data: [ data: [
{ {
id: idx + 0, id: idx + 0,
data: ( data: <StatusLabel status="down" text="Down" />,
<StatusLabel
status={params.status}
dot={params.statusDotColor}
customStyles={{ backgroundColor: params.backgroundColor }}
/>
),
}, },
{ id: idx + 1, data: new Date(incident.createdAt).toLocaleString() }, { id: idx + 1, data: new Date(incident.createdAt).toLocaleString() },
{ id: idx + 2, data: incident.statusCode }, { id: idx + 2, data: incident.statusCode },
+6 -21
View File
@@ -13,7 +13,10 @@ import WestRoundedIcon from "@mui/icons-material/WestRounded";
import GreenCheck from "../../../assets/icons/checkbox-green.svg?react"; import GreenCheck from "../../../assets/icons/checkbox-green.svg?react";
import RedCheck from "../../../assets/icons/checkbox-red.svg?react"; import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
import SettingsIcon from "../../../assets/icons/settings.svg?react"; import SettingsIcon from "../../../assets/icons/settings.svg?react";
import { formatDuration, formatDurationRounded } from "../../../Utils/timeUtils"; import {
formatDuration,
formatDurationRounded,
} from "../../../Utils/timeUtils";
import "./index.css"; import "./index.css";
const StatBox = ({ title, value }) => { const StatBox = ({ title, value }) => {
@@ -54,32 +57,14 @@ const DetailsPage = () => {
{ id: 3, name: "Message" }, { id: 3, name: "Message" },
], ],
rows: res.data.data.checks.map((check, idx) => { rows: res.data.data.checks.map((check, idx) => {
const params = { const status = check.status === true ? "up" : "down";
status: check.status === true ? "Up" : "Down",
backgroundColor:
check.status === true
? "var(--env-var-color-20)"
: "var(--env-var-color-21)",
statusDotColor:
check.status === true
? "var(--env-var-color-17)"
: "var(--env-var-color-19)",
};
return { return {
id: check._id, id: check._id,
data: [ data: [
{ {
id: idx, id: idx,
data: ( data: <StatusLabel status={status} text={status} />,
<StatusLabel
status={params.status}
dot={params.statusDotColor}
customStyles={{
backgroundColor: params.backgroundColor,
}}
/>
),
}, },
{ id: idx + 1, data: new Date(check.createdAt).toLocaleString() }, { id: idx + 1, data: new Date(check.createdAt).toLocaleString() },
{ id: idx + 2, data: check.statusCode }, { id: idx + 2, data: check.statusCode },
+3 -13
View File
@@ -89,15 +89,7 @@ const Monitors = () => {
monitor.status === true monitor.status === true
? "var(--env-var-color-17)" ? "var(--env-var-color-17)"
: "var(--env-var-color-19)", : "var(--env-var-color-19)",
status: monitor.status === true ? "Up" : "Down", status: monitor.status === true ? "up" : "down",
backgroundColor:
monitor.status === true
? "var(--env-var-color-20)"
: "var(--env-var-color-21)",
statusDotColor:
monitor.status === true
? "var(--env-var-color-17)"
: "var(--env-var-color-19)",
}; };
// Reverse checks so latest check is on the right // Reverse checks so latest check is on the right
@@ -113,10 +105,8 @@ const Monitors = () => {
data: ( data: (
<StatusLabel <StatusLabel
status={params.status} status={params.status}
dot={params.statusDotColor} text={params.status}
customStyles={{ customStyles={{ textTransform: "capitalize" }}
backgroundColor: params.backgroundColor,
}}
/> />
), ),
}, },
+2 -11
View File
@@ -39,17 +39,8 @@ const Card = ({ data }) => {
</Typography> </Typography>
{/* TODO - fix prop-type error */} {/* TODO - fix prop-type error */}
<StatusLabel <StatusLabel
status={data.isActive ? "Live (collecting data)" : "Inactive"} status={data.isActive ? "up" : "cannot resolve"}
dot={ text={data.isActive ? "Live (collecting data)" : "Inactive"}
data.isActive
? "var(--env-var-color-17)"
: "var(--env-var-color-19)"
}
customStyles={{
backgroundColor: data.isActive
? "var(--env-var-color-20)"
: "var(--env-var-color-21)",
}}
/> />
</Stack> </Stack>
<Typography>{data.url}</Typography> <Typography>{data.url}</Typography>
+18
View File
@@ -118,6 +118,24 @@ const theme = createTheme({
border: "#fec84b", border: "#fec84b",
}, },
}, },
//add more as needed
label: {
up: {
borderColor: sectionBorder,
bgColor: "#ecfdf3",
dotColor: "#17B26A",
},
down: {
borderColor: sectionBorder,
bgColor: "#f9eced",
dotColor: labelRed,
},
"cannot resolve": {
borderColor: sectionBorder,
bgColor: "#f2f4f7",
dotColor: labelGray,
},
},
}); });
export default theme; export default theme;