- add onBlur to handle Serverslist validation
This commit is contained in:
1 parent
f0352cc215
commit
dba8517d25
4 files changed
+30
-6
No files matched your search
@@ -12,6 +12,7 @@ import SearchIcon from "../../../assets/icons/search.svg?react";
|
|||||||
* @param {string} props.filteredBy - Key to access the option label from the options
|
* @param {string} props.filteredBy - Key to access the option label from the options
|
||||||
* @param {string} props.value - Current input value for the Autocomplete
|
* @param {string} props.value - Current input value for the Autocomplete
|
||||||
* @param {Function} props.handleChange - Function to call when the input changes
|
* @param {Function} props.handleChange - Function to call when the input changes
|
||||||
|
* @param {Function} Prop.onBlur - Function to call when the input is blured
|
||||||
* @param {Object} props.sx - Additional styles to apply to the component
|
* @param {Object} props.sx - Additional styles to apply to the component
|
||||||
* @returns {JSX.Element} The rendered Search component
|
* @returns {JSX.Element} The rendered Search component
|
||||||
*/
|
*/
|
||||||
@@ -55,11 +56,13 @@ const Search = ({
|
|||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
startAdornment,
|
startAdornment,
|
||||||
endAdornment
|
endAdornment,
|
||||||
|
onBlur
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
|
onBlur={onBlur}
|
||||||
multiple={multiple}
|
multiple={multiple}
|
||||||
id={id}
|
id={id}
|
||||||
value={value}
|
value={value}
|
||||||
@@ -202,7 +205,8 @@ Search.propTypes = {
|
|||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
startAdornment: PropTypes.object,
|
startAdornment: PropTypes.object,
|
||||||
endAdornment: PropTypes.object
|
endAdornment: PropTypes.object,
|
||||||
|
onBlur: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Search;
|
export default Search;
|
||||||
@@ -11,6 +11,8 @@ import { createToast } from "../../../Utils/toastUtils";
|
|||||||
import { networkService } from "../../../main";
|
import { networkService } from "../../../main";
|
||||||
import ServersList from "./ServersList";
|
import ServersList from "./ServersList";
|
||||||
import Checkbox from "../../Inputs/Checkbox";
|
import Checkbox from "../../Inputs/Checkbox";
|
||||||
|
import { publicPageSettingsValidation } from "../../../Validation/validation";
|
||||||
|
import { buildErrors } from "../../../Validation/error";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content Panel is used to compose the second part of the status page
|
* Content Panel is used to compose the second part of the status page
|
||||||
@@ -76,6 +78,17 @@ const ContentPanel = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleServersBlur = () => {
|
||||||
|
const { error } = publicPageSettingsValidation.validate(
|
||||||
|
{ "monitors": form.monitors },
|
||||||
|
{
|
||||||
|
abortEarly: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
setErrors((prev) => {
|
||||||
|
return buildErrors(prev, "monitors", error);
|
||||||
|
});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<TabPanel
|
<TabPanel
|
||||||
value="Contents"
|
value="Contents"
|
||||||
@@ -144,6 +157,7 @@ const ContentPanel = () => {
|
|||||||
form={form}
|
form={form}
|
||||||
setForm={setForm}
|
setForm={setForm}
|
||||||
removeItem={removeCard}
|
removeItem={removeCard}
|
||||||
|
onBlur= {handleServersBlur}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{errors["monitors"] && (
|
{errors["monitors"] && (
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ import PropTypes from "prop-types";
|
|||||||
* @param {*} removeItem The function used to remove a single server
|
* @param {*} removeItem The function used to remove a single server
|
||||||
* @param {*} onChange The Change handler function to handle when the server value is changed
|
* @param {*} onChange The Change handler function to handle when the server value is changed
|
||||||
* used to update the server(monitor) lists*
|
* used to update the server(monitor) lists*
|
||||||
|
* @param {*} onBlur Function to call when the input is blured
|
||||||
* @param {*} dragHandleProps the dragHandleProps passed on to the designated dom node
|
* @param {*} dragHandleProps the dragHandleProps passed on to the designated dom node
|
||||||
* so that there will be a draging indicator when mouse over it
|
* so that there will be a draging indicator when mouse over it
|
||||||
* @returns A single server whose value is one of the existing monitors
|
* @returns A single server whose value is one of the existing monitors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Server = ({ id, value, monitors, onChange, removeItem, dragHandleProps }) => {
|
const Server = ({ id, value, monitors, onChange, removeItem, onBlur, dragHandleProps }) => {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const handleSearch = (val) => {
|
const handleSearch = (val) => {
|
||||||
setSearch(val);
|
setSearch(val);
|
||||||
@@ -32,6 +33,7 @@ const Server = ({ id, value, monitors, onChange, removeItem, dragHandleProps })
|
|||||||
options={monitors ? monitors : []}
|
options={monitors ? monitors : []}
|
||||||
filteredBy="name"
|
filteredBy="name"
|
||||||
inputValue={search}
|
inputValue={search}
|
||||||
|
onBlur={onBlur}
|
||||||
value={value}
|
value={value}
|
||||||
startAdornment={<ServerStartAdornment dragHandleProps={dragHandleProps} />}
|
startAdornment={<ServerStartAdornment dragHandleProps={dragHandleProps} />}
|
||||||
endAdornment={
|
endAdornment={
|
||||||
@@ -51,8 +53,9 @@ Server.propTypes = {
|
|||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
monitors: PropTypes.array.isRequired,
|
monitors: PropTypes.array.isRequired,
|
||||||
value: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
value: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||||
removeItem: PropTypes.func.isRequired,
|
removeItem: PropTypes.func.isRequired,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
|
onBlur: PropTypes.func.isRequired,
|
||||||
dragHandleProps: PropTypes.object.isRequired,
|
dragHandleProps: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ import { Stack, useTheme } from "@mui/material";
|
|||||||
* @param {*} form The Status page form
|
* @param {*} form The Status page form
|
||||||
* @param {*} setForm Function to set the form
|
* @param {*} setForm Function to set the form
|
||||||
* @param {*} removeItem The function used to remove a single server
|
* @param {*} removeItem The function used to remove a single server
|
||||||
|
* @param {*} onBlur Function to call when the input is blured*
|
||||||
* @returns A list of user selected Servers/Monitors
|
* @returns A list of user selected Servers/Monitors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const ServersList = ({ monitors, cards, setCards, form, setForm, removeItem }) => {
|
const ServersList = ({ monitors, cards, setCards, form, setForm, removeItem, onBlur }) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const grid = parseInt(theme.spacing(4));
|
const grid = parseInt(theme.spacing(4));
|
||||||
|
|
||||||
@@ -114,6 +115,7 @@ const ServersList = ({ monitors, cards, setCards, form, setForm, removeItem }) =
|
|||||||
onChange={handleCardChange}
|
onChange={handleCardChange}
|
||||||
removeItem={removeItem}
|
removeItem={removeItem}
|
||||||
dragHandleProps={provided.dragHandleProps}
|
dragHandleProps={provided.dragHandleProps}
|
||||||
|
onBlur={onBlur}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
@@ -133,7 +135,8 @@ ServersList.propTypes = {
|
|||||||
setCards: PropTypes.func.isRequired,
|
setCards: PropTypes.func.isRequired,
|
||||||
form: PropTypes.object.isRequired,
|
form: PropTypes.object.isRequired,
|
||||||
setForm: PropTypes.func.isRequired,
|
setForm: PropTypes.func.isRequired,
|
||||||
removeItem: PropTypes.func.isRequired
|
removeItem: PropTypes.func.isRequired,
|
||||||
|
onBlur: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ServersList;
|
export default ServersList;
|
||||||
Reference in new issue
Block a user