Added http/https toggle (#462)
* Added toggle between http and https * Added https prop to field component * Added type fix to create monitor function * Reverted monitor model change * Added docs explaining prepending logic
This commit is contained in:
1 parent
477cad7cc9
commit
3377523f93
3 files changed
+67
-16
No files matched your search
@@ -19,6 +19,7 @@ import { useState } from "react";
|
|||||||
* @param {string} [props.type] - Type of input field (e.g., 'text', 'password').
|
* @param {string} [props.type] - Type of input field (e.g., 'text', 'password').
|
||||||
* @param {string} props.id - ID of the input field.
|
* @param {string} props.id - ID of the input field.
|
||||||
* @param {string} [props.label] - Label for the input field.
|
* @param {string} [props.label] - Label for the input field.
|
||||||
|
* @param {boolean} [props.https] - Indicates if it should display http or https.
|
||||||
* @param {boolean} [props.isRequired] - Indicates if the field is required, will display a red asterisk.
|
* @param {boolean} [props.isRequired] - Indicates if the field is required, will display a red asterisk.
|
||||||
* @param {boolean} [props.isOptional] - Indicates if the field is optional, will display optional text.
|
* @param {boolean} [props.isOptional] - Indicates if the field is optional, will display optional text.
|
||||||
* @param {string} [props.optionalLabel] - Optional label for the input field.
|
* @param {string} [props.optionalLabel] - Optional label for the input field.
|
||||||
@@ -35,6 +36,7 @@ const Field = ({
|
|||||||
type = "text",
|
type = "text",
|
||||||
id,
|
id,
|
||||||
label,
|
label,
|
||||||
|
https,
|
||||||
isRequired,
|
isRequired,
|
||||||
isOptional,
|
isOptional,
|
||||||
optionalLabel,
|
optionalLabel,
|
||||||
@@ -92,7 +94,9 @@ const Field = ({
|
|||||||
borderRight: `solid 1px ${theme.palette.section.borderColor}`,
|
borderRight: `solid 1px ${theme.palette.section.borderColor}`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography component="h5">https://</Typography>
|
<Typography component="h5">
|
||||||
|
{https ? "https" : "http"}://
|
||||||
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
),
|
),
|
||||||
endAdornment:
|
endAdornment:
|
||||||
@@ -152,6 +156,7 @@ Field.propTypes = {
|
|||||||
type: PropTypes.oneOf(["text", "password", "url", "email", "description"]),
|
type: PropTypes.oneOf(["text", "password", "url", "email", "description"]),
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
|
https: PropTypes.bool,
|
||||||
isRequired: PropTypes.bool,
|
isRequired: PropTypes.bool,
|
||||||
isOptional: PropTypes.bool,
|
isOptional: PropTypes.bool,
|
||||||
optionalLabel: PropTypes.string,
|
optionalLabel: PropTypes.string,
|
||||||
|
|||||||
@@ -60,7 +60,13 @@
|
|||||||
gap: var(--env-var-spacing-4);
|
gap: var(--env-var-spacing-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.create-monitor .MuiStack-root .MuiButtonGroup-root button {
|
||||||
|
font-size: var(--env-var-font-size-small);
|
||||||
|
height: 28px;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
body:has(.create-monitor) .select-dropdown .MuiMenuItem-root,
|
body:has(.create-monitor) .select-dropdown .MuiMenuItem-root,
|
||||||
.create-monitor .select-wrapper .select-component > .MuiSelect-select {
|
.create-monitor .select-wrapper .select-component > .MuiSelect-select {
|
||||||
text-transform: lowercase;
|
text-transform: lowercase;
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ import "./index.css";
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import RadioButton from "../../../Components/RadioButton";
|
import RadioButton from "../../../Components/RadioButton";
|
||||||
import Button from "../../../Components/Button";
|
import Button from "../../../Components/Button";
|
||||||
import { Box, MenuItem, Stack, Typography } from "@mui/material";
|
import { Box, ButtonGroup, Stack, Typography } from "@mui/material";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createMonitor } from "../../../Features/Monitors/monitorsSlice";
|
import { createMonitor } from "../../../Features/Monitors/monitorsSlice";
|
||||||
@@ -85,14 +85,17 @@ const CreateMonitor = () => {
|
|||||||
//obj to submit
|
//obj to submit
|
||||||
let monitor = {
|
let monitor = {
|
||||||
url:
|
url:
|
||||||
checks.type === "http"
|
//preprending protocol for url
|
||||||
? "https://" + generalSettings.url
|
checks.type === "http" || checks.type === "https"
|
||||||
|
? `${checks.type}://` + generalSettings.url
|
||||||
: generalSettings.url,
|
: generalSettings.url,
|
||||||
name:
|
name:
|
||||||
generalSettings.name === ""
|
generalSettings.name === ""
|
||||||
? generalSettings.url
|
? generalSettings.url
|
||||||
: generalSettings.name,
|
: generalSettings.name,
|
||||||
...checks,
|
//there is no separate monitor type for https since the operations for the two protocols are identical
|
||||||
|
//however the URL does need the correct prepend hence https is still being tracked but overwritten when prepping the monitor obj
|
||||||
|
type: checks.type === "https" ? "http" : checks.type,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { error } = monitorValidation.validate(monitor, {
|
const { error } = monitorValidation.validate(monitor, {
|
||||||
@@ -167,9 +170,14 @@ const CreateMonitor = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.gap.xl}>
|
<Stack gap={theme.gap.xl}>
|
||||||
<Field
|
<Field
|
||||||
type="url"
|
type={
|
||||||
|
checks.type === "http" || checks.type === "https"
|
||||||
|
? "url"
|
||||||
|
: "text"
|
||||||
|
}
|
||||||
id="monitor-url"
|
id="monitor-url"
|
||||||
label="URL to monitor"
|
label="URL to monitor"
|
||||||
|
https={checks.type === "https"}
|
||||||
placeholder="google.com"
|
placeholder="google.com"
|
||||||
value={generalSettings.url}
|
value={generalSettings.url}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
@@ -199,15 +207,47 @@ const CreateMonitor = () => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Stack gap={theme.gap.large}>
|
<Stack gap={theme.gap.large}>
|
||||||
<RadioButton
|
<Stack gap={theme.gap.medium}>
|
||||||
id="monitor-checks-http"
|
<RadioButton
|
||||||
title="HTTP/website monitoring"
|
id="monitor-checks-http"
|
||||||
desc="Use HTTP(s) to monitor your website or API endpoint."
|
title="Website monitoring"
|
||||||
size="small"
|
desc="Use HTTP(s) to monitor your website or API endpoint."
|
||||||
value="http"
|
size="small"
|
||||||
checked={checks.type === "http"}
|
value="http"
|
||||||
onChange={(event) => handleChange(event, "type", setChecks)}
|
checked={checks.type === "http" || checks.type === "https"}
|
||||||
/>
|
onChange={(event) => handleChange(event, "type", setChecks)}
|
||||||
|
/>
|
||||||
|
{checks.type === "http" || checks.type === "https" ? (
|
||||||
|
<ButtonGroup sx={{ ml: "32px" }}>
|
||||||
|
<Button
|
||||||
|
level="secondary"
|
||||||
|
label="HTTP"
|
||||||
|
onClick={() =>
|
||||||
|
setChecks((prev) => ({ ...prev, type: "http" }))
|
||||||
|
}
|
||||||
|
sx={{
|
||||||
|
backgroundColor:
|
||||||
|
checks.type === "http" &&
|
||||||
|
theme.palette.otherColors.fillGray,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
level="secondary"
|
||||||
|
label="HTTPS"
|
||||||
|
onClick={() =>
|
||||||
|
setChecks((prev) => ({ ...prev, type: "https" }))
|
||||||
|
}
|
||||||
|
sx={{
|
||||||
|
backgroundColor:
|
||||||
|
checks.type === "https" &&
|
||||||
|
theme.palette.otherColors.fillGray,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ButtonGroup>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
<RadioButton
|
<RadioButton
|
||||||
id="monitor-checks-ping"
|
id="monitor-checks-ping"
|
||||||
title="Ping monitoring"
|
title="Ping monitoring"
|
||||||
|
|||||||
Reference in new issue
Block a user