Add Http Status Label to Incident Table
This commit is contained in:
1 parent
8f9fa11b9d
commit
560b7c4a4d
2 files changed
+55
-19
No files matched your search
@@ -58,7 +58,7 @@ const lightenColor = (color, percent) => {
|
|||||||
let r = parseInt(color.substring(1, 3), 16);
|
let r = parseInt(color.substring(1, 3), 16);
|
||||||
let g = parseInt(color.substring(3, 5), 16);
|
let g = parseInt(color.substring(3, 5), 16);
|
||||||
let b = parseInt(color.substring(5, 7), 16);
|
let b = parseInt(color.substring(5, 7), 16);
|
||||||
|
|
||||||
const amt = Math.round((255 * percent) / 100);
|
const amt = Math.round((255 * percent) / 100);
|
||||||
|
|
||||||
r = r + amt <= 255 ? r + amt : 255;
|
r = r + amt <= 255 ? r + amt : 255;
|
||||||
@@ -86,10 +86,7 @@ const lightenColor = (color, percent) => {
|
|||||||
const ColoredLabel = ({ label, color }) => {
|
const ColoredLabel = ({ label, color }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
// If an invalid color is passed, default to the labelGray color
|
// If an invalid color is passed, default to the labelGray color
|
||||||
if (
|
if (typeof color !== "string" || !/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color)) {
|
||||||
typeof color !== "string" ||
|
|
||||||
!/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color)
|
|
||||||
) {
|
|
||||||
color = theme.palette.border.light;
|
color = theme.palette.border.light;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,13 +116,14 @@ ColoredLabel.propTypes = {
|
|||||||
* @param {Object} props
|
* @param {Object} props
|
||||||
* @param { 'up' | 'down' | 'cannot resolve'} props.status - The status for the label
|
* @param { 'up' | 'down' | 'cannot resolve'} props.status - The status for the label
|
||||||
* @param {string} props.text - The text of the label
|
* @param {string} props.text - The text of the label
|
||||||
|
* @param {boolean} props.hasDot - Whether to show a dot or not
|
||||||
* @returns {JSX.Element}
|
* @returns {JSX.Element}
|
||||||
* @example
|
* @example
|
||||||
* // Render an active label
|
* // Render an active label
|
||||||
* <StatusLabel status="up" text="Active" />
|
* <StatusLabel status="up" text="Active" />
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const StatusLabel = ({ status, text, customStyles }) => {
|
const StatusLabel = ({ status, text, hasDot = true, customStyles }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const colors = {
|
const colors = {
|
||||||
up: {
|
up: {
|
||||||
@@ -148,6 +146,16 @@ const StatusLabel = ({ status, text, customStyles }) => {
|
|||||||
bgColor: theme.palette.warning.bg,
|
bgColor: theme.palette.warning.bg,
|
||||||
borderColor: theme.palette.warning.light,
|
borderColor: theme.palette.warning.light,
|
||||||
},
|
},
|
||||||
|
400: {
|
||||||
|
dotColor: theme.palette.warning.main,
|
||||||
|
bgColor: theme.palette.warning.bg,
|
||||||
|
borderColor: theme.palette.warning.light,
|
||||||
|
},
|
||||||
|
500: {
|
||||||
|
dotColor: theme.palette.warning.main,
|
||||||
|
bgColor: theme.palette.warning.bg,
|
||||||
|
borderColor: theme.palette.warning.light,
|
||||||
|
},
|
||||||
"cannot resolve": {
|
"cannot resolve": {
|
||||||
dotColor: theme.palette.unresolved.main,
|
dotColor: theme.palette.unresolved.main,
|
||||||
bgColor: theme.palette.unresolved.bg,
|
bgColor: theme.palette.unresolved.bg,
|
||||||
@@ -156,7 +164,7 @@ const StatusLabel = ({ status, text, customStyles }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Look up the color for the status
|
// Look up the color for the status
|
||||||
const { borderColor, bgColor, dotColor } = colors[status];
|
const { borderColor, bgColor, dotColor } = colors[status] || colors["cannot resolve"];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseLabel
|
<BaseLabel
|
||||||
@@ -168,13 +176,15 @@ const StatusLabel = ({ status, text, customStyles }) => {
|
|||||||
...customStyles,
|
...customStyles,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
{hasDot && (
|
||||||
width={7}
|
<Box
|
||||||
height={7}
|
width={7}
|
||||||
bgcolor={dotColor}
|
height={7}
|
||||||
borderRadius="50%"
|
bgcolor={dotColor}
|
||||||
marginRight="5px"
|
borderRadius="50%"
|
||||||
/>
|
marginRight="5px"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</BaseLabel>
|
</BaseLabel>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -185,9 +195,12 @@ StatusLabel.propTypes = {
|
|||||||
"down",
|
"down",
|
||||||
"paused",
|
"paused",
|
||||||
"pending",
|
"pending",
|
||||||
|
"400",
|
||||||
|
"500",
|
||||||
"cannot resolve",
|
"cannot resolve",
|
||||||
]),
|
]),
|
||||||
text: PropTypes.string,
|
text: PropTypes.string,
|
||||||
|
hasDot: PropTypes.bool,
|
||||||
customStyles: PropTypes.object,
|
customStyles: PropTypes.object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -133,19 +133,31 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
<>
|
<>
|
||||||
{checks?.length === 0 && selectedMonitor === "0" ? (
|
{checks?.length === 0 && selectedMonitor === "0" ? (
|
||||||
<Box sx={{ ...sharedStyles }}>
|
<Box sx={{ ...sharedStyles }}>
|
||||||
<Box textAlign="center" pb={theme.spacing(20)}>
|
<Box
|
||||||
|
textAlign="center"
|
||||||
|
pb={theme.spacing(20)}
|
||||||
|
>
|
||||||
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
||||||
</Box>
|
</Box>
|
||||||
<Typography textAlign="center" color={theme.palette.text.secondary}>
|
<Typography
|
||||||
|
textAlign="center"
|
||||||
|
color={theme.palette.text.secondary}
|
||||||
|
>
|
||||||
No incidents recorded yet.
|
No incidents recorded yet.
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
) : checks?.length === 0 ? (
|
) : checks?.length === 0 ? (
|
||||||
<Box sx={{ ...sharedStyles }}>
|
<Box sx={{ ...sharedStyles }}>
|
||||||
<Box textAlign="center" pb={theme.spacing(20)}>
|
<Box
|
||||||
|
textAlign="center"
|
||||||
|
pb={theme.spacing(20)}
|
||||||
|
>
|
||||||
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
{mode === "light" ? <PlaceholderLight /> : <PlaceholderDark />}
|
||||||
</Box>
|
</Box>
|
||||||
<Typography textAlign="center" color={theme.palette.text.secondary}>
|
<Typography
|
||||||
|
textAlign="center"
|
||||||
|
color={theme.palette.text.secondary}
|
||||||
|
>
|
||||||
The monitor you have selected has no recorded incidents yet.
|
The monitor you have selected has no recorded incidents yet.
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -170,6 +182,12 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
"YYYY-MM-DD HH:mm:ss A",
|
"YYYY-MM-DD HH:mm:ss A",
|
||||||
uiTimezone
|
uiTimezone
|
||||||
);
|
);
|
||||||
|
const getGenericStatus = (status) => {
|
||||||
|
if (typeof status === "number" && status >= 100 && status < 600) {
|
||||||
|
return Math.floor(status / 100) * 100;
|
||||||
|
}
|
||||||
|
return "cannot resolve";
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow key={check._id}>
|
<TableRow key={check._id}>
|
||||||
@@ -183,7 +201,12 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{formattedDate}</TableCell>
|
<TableCell>{formattedDate}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{check.statusCode ? check.statusCode : "N/A"}
|
<StatusLabel
|
||||||
|
status={getGenericStatus(check.statusCode)}
|
||||||
|
text={String(check.statusCode || "N/A")}
|
||||||
|
hasDot={false}
|
||||||
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{check.message}</TableCell>
|
<TableCell>{check.message}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|||||||
Reference in new issue
Block a user