chore: extract monitor URL formatting to utils

This commit is contained in:
Deepanshu committed 2025-06-17 17:30:11 +05:30
1 parent e818f1cd61
commit f474d63e88
2 files changed
+10 -6

No files matched your search

@@ -8,6 +8,7 @@ import { formatDurationRounded } from "../../Utils/timeUtils";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useMonitorUtils } from "../../Hooks/useMonitorUtils"; import { useMonitorUtils } from "../../Hooks/useMonitorUtils";
import { formatMonitorUrl } from "../../Utils/utils";
/** /**
* Status component displays the status information of a monitor. * Status component displays the status information of a monitor.
* It includes the monitor's name, URL, and check interval. * It includes the monitor's name, URL, and check interval.
@@ -23,7 +24,6 @@ import { useMonitorUtils } from "../../Hooks/useMonitorUtils";
const Status = ({ monitor }) => { const Status = ({ monitor }) => {
const theme = useTheme(); const theme = useTheme();
const { statusColor, determineState } = useMonitorUtils(); const { statusColor, determineState } = useMonitorUtils();
const URL_TRUNCATION_LENGTH = 55;
return ( return (
<Stack> <Stack>
@@ -38,11 +38,7 @@ const Status = ({ monitor }) => {
variant="monitorUrl" variant="monitorUrl"
noWrap noWrap
> >
{monitor?.url {formatMonitorUrl(monitor?.url)}
? monitor.url?.length > URL_TRUNCATION_LENGTH
? `${monitor.url.replace(/^https?:\/\//, "")?.slice(0, URL_TRUNCATION_LENGTH)}…`
: monitor.url.replace(/^https?:\/\//, "")
: "…"}
</Typography> </Typography>
<Dot /> <Dot />
<Typography> <Typography>
+8
View File
@@ -5,3 +5,11 @@ export const safelyParseFloat = (value) => {
} }
return parsedValue; return parsedValue;
}; };
export const formatMonitorUrl = (url, maxLength = 50) => {
if (!url) return "";
const strippedUrl = url.replace(/^https?:\/\//, "");
return strippedUrl.length > maxLength
? `${strippedUrl.slice(0, maxLength)}…`
: strippedUrl;
};