Fleet UI: Label errors (#7406)

This commit is contained in:
RachelElysia 2022-08-26 07:55:21 -07:00 committed by GitHub
parent 87e42d4dd8
commit aa3c70be92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1 @@
* Fleet UI: Show user errors for creating/editing a label with a label name or label description that is too long

View file

@ -984,6 +984,22 @@ const ManageHostsPage = ({
setLabelValidator({
name: "A label with this name already exists",
});
} else if (
updateError.data.errors[0].reason.includes(
"Data too long for column 'name'"
)
) {
setLabelValidator({
name: "Label name is too long",
});
} else if (
updateError.data.errors[0].reason.includes(
"Data too long for column 'description'"
)
) {
setLabelValidator({
description: "Label description is too long",
});
} else {
renderFlash("error", "Could not create label. Please try again.");
}
@ -1011,6 +1027,22 @@ const ManageHostsPage = ({
setLabelValidator({
name: "A label with this name already exists",
});
} else if (
updateError.data.errors[0].reason.includes(
"Data too long for column 'name'"
)
) {
setLabelValidator({
name: "Label name is too long",
});
} else if (
updateError.data.errors[0].reason.includes(
"Data too long for column 'description'"
)
) {
setLabelValidator({
description: "Label description is too long",
});
} else {
renderFlash("error", "Could not create label. Please try again.");
}

View file

@ -66,6 +66,7 @@ const LabelForm = ({
const [description, setDescription] = useState<string>(
selectedLabel?.description || ""
);
const [descriptionError, setDescriptionError] = useState<string>("");
const [query, setQuery] = useState<string>(selectedLabel?.query || "");
const [queryError, setQueryError] = useState<string>("");
const [platform, setPlatform] = useState<string>(
@ -88,6 +89,7 @@ const LabelForm = ({
useEffect(() => {
setNameError(backendValidators.name);
setDescriptionError(backendValidators.description);
}, [backendValidators]);
useEffect(() => {
@ -206,6 +208,7 @@ const LabelForm = ({
placeholder="Label name"
/>
<InputField
error={descriptionError}
name="description"
onChange={onDescriptionChange}
value={description}