Merge pull request #1234 from peterpardo/feat/create-monitor-display-name-v2
feat: Create monitor display name v2, resolves #992
This commit is contained in:
4 files changed
+54
-1
No files matched your search
@@ -3,6 +3,7 @@ import { Box, Stack, Typography } from "@mui/material";
|
|||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { infrastructureMonitorValidation } from "../../../Validation/validation";
|
import { infrastructureMonitorValidation } from "../../../Validation/validation";
|
||||||
|
import { parseDomainName } from "../../../Utils/monitorUtils";
|
||||||
import {
|
import {
|
||||||
createInfrastructureMonitor,
|
createInfrastructureMonitor,
|
||||||
checkInfrastructureEndpointResolution,
|
checkInfrastructureEndpointResolution,
|
||||||
@@ -79,6 +80,15 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
const handleBlur = (event, appendID) => {
|
const handleBlur = (event, appendID) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
|
|
||||||
|
let name = idMap[id] ?? id;
|
||||||
|
if (name === "url" && infrastructureMonitor.name === "") {
|
||||||
|
setInfrastructureMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
|
name: parseDomainName(value),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (id?.startsWith("notify-email-")) return;
|
if (id?.startsWith("notify-email-")) return;
|
||||||
const { error } = infrastructureMonitorValidation.validate(
|
const { error } = infrastructureMonitorValidation.validate(
|
||||||
{ [id ?? appendID]: value },
|
{ [id ?? appendID]: value },
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import Checkbox from "../../../Components/Inputs/Checkbox";
|
|||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import { getUptimeMonitorById } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { getUptimeMonitorById } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import { parseDomainName } from "../../../Utils/monitorUtils";
|
||||||
|
|
||||||
const CreateMonitor = () => {
|
const CreateMonitor = () => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
@@ -91,7 +92,7 @@ const CreateMonitor = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
}, [monitorId, authToken, monitors]);
|
}, [monitorId, authToken, monitors, dispatch, navigate]);
|
||||||
|
|
||||||
const handleChange = (event, name) => {
|
const handleChange = (event, name) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
@@ -141,6 +142,14 @@ const CreateMonitor = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onUrlBlur = (event) => {
|
||||||
|
const { value } = event.target;
|
||||||
|
setMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
|
name: parseDomainName(value),
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
const handleCreateMonitor = async (event) => {
|
const handleCreateMonitor = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
//obj to submit
|
//obj to submit
|
||||||
@@ -259,6 +268,7 @@ const CreateMonitor = () => {
|
|||||||
placeholder={monitorTypeMaps[monitor.type].placeholder || ""}
|
placeholder={monitorTypeMaps[monitor.type].placeholder || ""}
|
||||||
value={monitor.url}
|
value={monitor.url}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
onBlur={onUrlBlur}
|
||||||
error={errors["url"] ? true : false}
|
error={errors["url"] ? true : false}
|
||||||
helperText={errors["url"]}
|
helperText={errors["url"]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
|||||||
import Select from "../../../Components/Inputs/Select";
|
import Select from "../../../Components/Inputs/Select";
|
||||||
import Checkbox from "../../../Components/Inputs/Checkbox";
|
import Checkbox from "../../../Components/Inputs/Checkbox";
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
|
import { parseDomainName } from "../../../Utils/monitorUtils";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const CreatePageSpeed = () => {
|
const CreatePageSpeed = () => {
|
||||||
@@ -95,6 +96,16 @@ const CreatePageSpeed = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onUrlBlur = (event) => {
|
||||||
|
const { value } = event.target;
|
||||||
|
if (monitor.name === "") {
|
||||||
|
setMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
|
name: parseDomainName(value),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleCreateMonitor = async (event) => {
|
const handleCreateMonitor = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
//obj to submit
|
//obj to submit
|
||||||
@@ -214,6 +225,7 @@ const CreatePageSpeed = () => {
|
|||||||
placeholder="google.com"
|
placeholder="google.com"
|
||||||
value={monitor.url}
|
value={monitor.url}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
|
onBlur={onUrlBlur}
|
||||||
error={errors["url"] ? true : false}
|
error={errors["url"] ? true : false}
|
||||||
helperText={errors["url"]}
|
helperText={errors["url"]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { capitalizeFirstLetter } from "./stringUtils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get duration since last check or the last date checked
|
* Helper function to get duration since last check or the last date checked
|
||||||
* @param {Array} checks Array of check objects.
|
* @param {Array} checks Array of check objects.
|
||||||
@@ -15,3 +17,22 @@ export const getLastChecked = (checks, duration = true) => {
|
|||||||
}
|
}
|
||||||
return new Date() - new Date(checks[0].createdAt);
|
return new Date() - new Date(checks[0].createdAt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const parseDomainName = (url) => {
|
||||||
|
url = url.replace(/^https?:\/\//, "");
|
||||||
|
// Remove leading/trailing dots
|
||||||
|
url = url.replace(/^\.+|\.+$/g, "");
|
||||||
|
// Split by dots
|
||||||
|
const parts = url.split(".");
|
||||||
|
// Remove common prefixes and empty parts and exclude the last element of the array (the last element should be the TLD)
|
||||||
|
const cleanParts = parts.filter((part) => part !== "www" && part !== "").slice(0, -1);
|
||||||
|
// If there's more than one part, append the two words and capitalize the first letters (e.g. ["api", "test"] -> "Api Test")
|
||||||
|
const domainPart =
|
||||||
|
cleanParts.length > 1
|
||||||
|
? cleanParts.map((part) => capitalizeFirstLetter(part)).join(" ")
|
||||||
|
: capitalizeFirstLetter(cleanParts[0]);
|
||||||
|
|
||||||
|
if (domainPart) return domainPart;
|
||||||
|
|
||||||
|
return url;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user