integrate TextField into create infrastructure page

This commit is contained in:
Alex Holliday committed 2024-11-26 12:15:41 +08:00
1 parent 7e553a73e8
commit 12767d5dbc
3 files changed
+25 -13

No files matched your search

@@ -56,6 +56,7 @@ Optional.propTypes = {
const TextInput = forwardRef( const TextInput = forwardRef(
( (
{ {
id,
type, type,
value, value,
placeholder, placeholder,
@@ -63,12 +64,14 @@ const TextInput = forwardRef(
isOptional, isOptional,
optionalLabel, optionalLabel,
onChange, onChange,
onBlur,
error = false, error = false,
helperText = null, helperText = null,
startAdornment = null, startAdornment = null,
endAdornment = null, endAdornment = null,
label = null, label = null,
maxWidth = "100%", maxWidth = "100%",
disabled = false,
}, },
ref ref
) => { ) => {
@@ -87,10 +90,12 @@ const TextInput = forwardRef(
{isOptional && <Optional optionalLabel={optionalLabel} />} {isOptional && <Optional optionalLabel={optionalLabel} />}
</Typography> </Typography>
<TextField <TextField
id={id}
type={fieldType} type={fieldType}
value={value} value={value}
placeholder={placeholder} placeholder={placeholder}
onChange={onChange} onChange={onChange}
onBlur={onBlur}
error={error} error={error}
helperText={helperText} helperText={helperText}
inputRef={ref} inputRef={ref}
@@ -103,6 +108,7 @@ const TextInput = forwardRef(
: null, : null,
}, },
}} }}
disabled={disabled}
/> />
</Stack> </Stack>
); );
@@ -113,18 +119,21 @@ TextInput.displayName = "TextInput";
TextInput.propTypes = { TextInput.propTypes = {
type: PropTypes.string, type: PropTypes.string,
id: PropTypes.string.isRequired,
value: PropTypes.string, value: PropTypes.string,
placeholder: PropTypes.string, placeholder: PropTypes.string,
isRequired: PropTypes.bool, isRequired: PropTypes.bool,
isOptional: PropTypes.bool, isOptional: PropTypes.bool,
optionalLabel: PropTypes.string, optionalLabel: PropTypes.string,
onChange: PropTypes.func, onChange: PropTypes.func,
onBlur: PropTypes.func,
error: PropTypes.bool, error: PropTypes.bool,
helperText: PropTypes.string, helperText: PropTypes.string,
startAdornment: PropTypes.node, startAdornment: PropTypes.node,
endAdornment: PropTypes.node, endAdornment: PropTypes.node,
label: PropTypes.string, label: PropTypes.string,
maxWidth: PropTypes.string, maxWidth: PropTypes.string,
disabled: PropTypes.bool,
}; };
export default TextInput; export default TextInput;
@@ -1,5 +1,6 @@
import { Box, Stack, Typography } from "@mui/material"; import { Box, Stack, Typography } from "@mui/material";
import Field from "../../../../Components/Inputs/Field"; import Field from "../../../../Components/Inputs/Field";
import TextInput from "../../../../Components/Inputs/TextInput";
import Checkbox from "../../../../Components/Inputs/Checkbox"; import Checkbox from "../../../../Components/Inputs/Checkbox";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
@@ -57,17 +58,17 @@ export const CustomThreshold = ({
justifyContent: "flex-end", justifyContent: "flex-end",
}} }}
> >
<Field <TextInput
maxWidth="var(--env-var-width-4)"
type="number" type="number"
className="field-infrastructure-alert"
id={fieldId} id={fieldId}
value={infrastructureMonitor[fieldId]} value={infrastructureMonitor[fieldId]}
onBlur={onFieldBlur} onBlur={onFieldBlur}
onChange={onFieldChange} onChange={onFieldChange}
error={errors[fieldId]} error={errors[fieldId] ? true : false}
disabled={!infrastructureMonitor[checkboxId]} disabled={!infrastructureMonitor[checkboxId]}
hideErrorText={true} />
></Field>
<Typography <Typography
component="p" component="p"
m={theme.spacing(3)} m={theme.spacing(3)}
@@ -10,9 +10,9 @@ import {
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { createToast } from "../../../Utils/toastUtils"; import { createToast } from "../../../Utils/toastUtils";
import { logger } from "../../../Utils/Logger";
import { ConfigBox } from "../../Monitors/styled"; import { ConfigBox } from "../../Monitors/styled";
import Field from "../../../Components/Inputs/Field"; import Field from "../../../Components/Inputs/Field";
import TextInput from "../../../Components/Inputs/TextInput";
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";
@@ -93,7 +93,6 @@ const CreateInfrastructureMonitor = () => {
event.preventDefault(); event.preventDefault();
const { value, id } = event.target; const { value, id } = event.target;
let name = appendedId ?? idMap[id] ?? id; let name = appendedId ?? idMap[id] ?? id;
if (name.includes("notification-")) { if (name.includes("notification-")) {
name = name.replace("notification-", ""); name = name.replace("notification-", "");
let hasNotif = infrastructureMonitor.notifications.some( let hasNotif = infrastructureMonitor.notifications.some(
@@ -240,7 +239,7 @@ const CreateInfrastructureMonitor = () => {
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.spacing(15)}> <Stack gap={theme.spacing(15)}>
<Field <TextInput
type="text" type="text"
id="url" id="url"
label="Server URL" label="Server URL"
@@ -248,9 +247,10 @@ const CreateInfrastructureMonitor = () => {
value={infrastructureMonitor.url} value={infrastructureMonitor.url}
onBlur={handleBlur} onBlur={handleBlur}
onChange={handleChange} onChange={handleChange}
error={errors["url"]} error={errors["url"] ? true : false}
helperText={errors["url"]}
/> />
<Field <TextInput
type="text" type="text"
id="name" id="name"
label="Friendly name" label="Friendly name"
@@ -260,14 +260,15 @@ const CreateInfrastructureMonitor = () => {
onChange={handleChange} onChange={handleChange}
error={errors["name"]} error={errors["name"]}
/> />
<Field <TextInput
type="text" type="text"
id="secret" id="secret"
label="Authorization secret" label="Authorization secret"
value={infrastructureMonitor.secret} value={infrastructureMonitor.secret}
onBlur={handleBlur} onBlur={handleBlur}
onChange={handleChange} onChange={handleChange}
error={errors["secret"]} error={errors["secret"] ? true : false}
helperText={errors["secret"]}
/> />
</Stack> </Stack>
</ConfigBox> </ConfigBox>
@@ -297,7 +298,8 @@ const CreateInfrastructureMonitor = () => {
<Box> <Box>
<Typography component="h2">Customize alerts</Typography> <Typography component="h2">Customize alerts</Typography>
<Typography component="p"> <Typography component="p">
Send a notification to user(s) when thresholds exceed a specified percentage. Send a notification to user(s) when thresholds exceed a specified
percentage.
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.spacing(6)}> <Stack gap={theme.spacing(6)}>