added safe var access
This commit is contained in:
1 parent
d59e2796e7
commit
19d3ae119c
3 files changed
+31
-55
No files matched your search
@@ -6,18 +6,18 @@ const useMonitorUtils = () => {
|
|||||||
let uptimePercentage = "";
|
let uptimePercentage = "";
|
||||||
let percentageColor = "";
|
let percentageColor = "";
|
||||||
|
|
||||||
if (monitor.uptimePercentage !== undefined) {
|
if (monitor?.uptimePercentage !== undefined) {
|
||||||
uptimePercentage =
|
uptimePercentage =
|
||||||
monitor.uptimePercentage === 0
|
monitor?.uptimePercentage === 0
|
||||||
? "0"
|
? "0"
|
||||||
: (monitor.uptimePercentage * 100).toFixed(2);
|
: (monitor?.uptimePercentage * 100).toFixed(2);
|
||||||
|
|
||||||
percentageColor =
|
percentageColor =
|
||||||
monitor.uptimePercentage < 0.25
|
monitor?.uptimePercentage < 0.25
|
||||||
? theme.palette.error.main
|
? theme.palette.error.main
|
||||||
: monitor.uptimePercentage < 0.5
|
: monitor?.uptimePercentage < 0.5
|
||||||
? theme.palette.warning.main
|
? theme.palette.warning.main
|
||||||
: monitor.uptimePercentage < 0.75
|
: monitor?.uptimePercentage < 0.75
|
||||||
? theme.palette.success.main
|
? theme.palette.success.main
|
||||||
: theme.palette.success.main;
|
: theme.palette.success.main;
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ const useMonitorUtils = () => {
|
|||||||
|
|
||||||
const determineState = useCallback((monitor) => {
|
const determineState = useCallback((monitor) => {
|
||||||
if (typeof monitor === "undefined") return "pending";
|
if (typeof monitor === "undefined") return "pending";
|
||||||
if (monitor.isActive === false) return "paused";
|
if (monitor?.isActive === false) return "paused";
|
||||||
if (monitor?.status === undefined) return "pending";
|
if (monitor?.status === undefined) return "pending";
|
||||||
return monitor?.status == true ? "up" : "down";
|
return monitor?.status == true ? "up" : "down";
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -163,18 +163,18 @@ const Configure = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const toSubmit = {
|
const toSubmit = {
|
||||||
_id: form._id,
|
_id: form?._id,
|
||||||
url: form.url,
|
url: form?.url,
|
||||||
name: form.name,
|
name: form?.name,
|
||||||
type: form.type,
|
type: form?.type,
|
||||||
matchMethod: form.matchMethod,
|
matchMethod: form?.matchMethod,
|
||||||
expectedValue: form.expectedValue,
|
expectedValue: form?.expectedValue,
|
||||||
jsonPath: form.jsonPath,
|
jsonPath: form?.jsonPath,
|
||||||
interval: form.interval,
|
interval: form?.interval,
|
||||||
teamId: form.teamId,
|
teamId: form?.teamId,
|
||||||
userId: form.userId,
|
userId: form?.userId,
|
||||||
port: form.port,
|
port: form?.port,
|
||||||
ignoreTlsErrors: form.ignoreTlsErrors,
|
ignoreTlsErrors: form?.ignoreTlsErrors,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!useAdvancedMatching) {
|
if (!useAdvancedMatching) {
|
||||||
@@ -197,7 +197,7 @@ const Configure = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toSubmit.notifications = form.notifications;
|
toSubmit.notifications = form?.notifications;
|
||||||
await updateMonitor({ monitor: toSubmit, redirect: "/uptime" });
|
await updateMonitor({ monitor: toSubmit, redirect: "/uptime" });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ const Configure = () => {
|
|||||||
component="h1"
|
component="h1"
|
||||||
variant="monitorName"
|
variant="monitorName"
|
||||||
>
|
>
|
||||||
{form.name}
|
{form?.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -267,7 +267,7 @@ const Configure = () => {
|
|||||||
component="h2"
|
component="h2"
|
||||||
variant="monitorUrl"
|
variant="monitorUrl"
|
||||||
>
|
>
|
||||||
{form.url?.replace(/^https?:\/\//, "") || "..."}
|
{form?.url?.replace(/^https?:\/\//, "") || "..."}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
position="relative"
|
position="relative"
|
||||||
@@ -352,11 +352,11 @@ const Configure = () => {
|
|||||||
type="number"
|
type="number"
|
||||||
label={t("portToMonitor")}
|
label={t("portToMonitor")}
|
||||||
placeholder="5173"
|
placeholder="5173"
|
||||||
value={form.port || ""}
|
value={form?.port || ""}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
error={errors["port"] ? true : false}
|
error={errors["port"] ? true : false}
|
||||||
helperText={errors["port"]}
|
helperText={errors["port"]}
|
||||||
hidden={form.type !== "port"}
|
hidden={form?.type !== "port"}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
name="name"
|
name="name"
|
||||||
@@ -379,7 +379,7 @@ const Configure = () => {
|
|||||||
<NotificationsConfig
|
<NotificationsConfig
|
||||||
notifications={notifications}
|
notifications={notifications}
|
||||||
setMonitor={setForm}
|
setMonitor={setForm}
|
||||||
setNotifications={form.notifications}
|
setNotifications={form?.notifications}
|
||||||
/>
|
/>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
<ConfigBox>
|
<ConfigBox>
|
||||||
@@ -398,7 +398,7 @@ const Configure = () => {
|
|||||||
control={
|
control={
|
||||||
<Switch
|
<Switch
|
||||||
name="ignoreTlsErrors"
|
name="ignoreTlsErrors"
|
||||||
checked={form.ignoreTlsErrors ?? false}
|
checked={form?.ignoreTlsErrors ?? false}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
sx={{ mr: theme.spacing(2) }}
|
sx={{ mr: theme.spacing(2) }}
|
||||||
/>
|
/>
|
||||||
@@ -430,12 +430,12 @@ const Configure = () => {
|
|||||||
isChecked={useAdvancedMatching}
|
isChecked={useAdvancedMatching}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
{form.type === "http" && useAdvancedMatching && (
|
{form?.type === "http" && useAdvancedMatching && (
|
||||||
<>
|
<>
|
||||||
<Select
|
<Select
|
||||||
name="matchMethod"
|
name="matchMethod"
|
||||||
label={t("matchMethod")}
|
label={t("matchMethod")}
|
||||||
value={form.matchMethod || "equal"}
|
value={form?.matchMethod || "equal"}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
items={matchMethodOptions}
|
items={matchMethodOptions}
|
||||||
/>
|
/>
|
||||||
@@ -445,8 +445,8 @@ const Configure = () => {
|
|||||||
name="expectedValue"
|
name="expectedValue"
|
||||||
label={t("expectedValue")}
|
label={t("expectedValue")}
|
||||||
isOptional={true}
|
isOptional={true}
|
||||||
placeholder={expectedValuePlaceholders[form.matchMethod || "equal"]}
|
placeholder={expectedValuePlaceholders[form?.matchMethod || "equal"]}
|
||||||
value={form.expectedValue}
|
value={form?.expectedValue}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
error={errors["expectedValue"] ? true : false}
|
error={errors["expectedValue"] ? true : false}
|
||||||
helperText={errors["expectedValue"]}
|
helperText={errors["expectedValue"]}
|
||||||
@@ -466,7 +466,7 @@ const Configure = () => {
|
|||||||
label="JSON Path"
|
label="JSON Path"
|
||||||
isOptional={true}
|
isOptional={true}
|
||||||
placeholder="data.status"
|
placeholder="data.status"
|
||||||
value={form.jsonPath}
|
value={form?.jsonPath}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
error={errors["jsonPath"] ? true : false}
|
error={errors["jsonPath"] ? true : false}
|
||||||
helperText={errors["jsonPath"]}
|
helperText={errors["jsonPath"]}
|
||||||
|
|||||||
@@ -111,30 +111,6 @@ class NetworkService {
|
|||||||
return this.axiosInstance.post(`/monitors`, monitor);
|
return this.axiosInstance.post(`/monitors`, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* ************************************
|
|
||||||
* Check the endpoint resolution
|
|
||||||
* ************************************
|
|
||||||
*
|
|
||||||
* @async
|
|
||||||
* @param {Object} config - The configuration object.
|
|
||||||
* @param {Object} config.monitorURL - The monitor url to be sent in the request body.
|
|
||||||
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
|
|
||||||
*/
|
|
||||||
async checkEndpointResolution(config) {
|
|
||||||
const { monitorURL } = config;
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
|
|
||||||
if (monitorURL) params.append("monitorURL", monitorURL);
|
|
||||||
|
|
||||||
return this.axiosInstance.get(`/monitors/resolution/url?${params.toString()}`, {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ************************************
|
* ************************************
|
||||||
* Get all uptime monitors for a Team
|
* Get all uptime monitors for a Team
|
||||||
|
|||||||
Reference in new issue
Block a user