[8.8] [Fleet] Do not show error state on input if there are no errors (#157160) (#157172)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Fleet] Do not show error state on input if there are no errors
(#157160)](https://github.com/elastic/kibana/pull/157160)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Mark
Hopkin","email":"mark.hopkin@elastic.co"},"sourceCommit":{"committedDate":"2023-05-09T14:15:27Z","message":"[Fleet]
Do not show error state on input if there are no errors (#157160)\n\n##
Summary\r\nFixes this bug, where there was previously an error with this
input but\r\nit has been solved, we still have it in the error
state:\r\n<img width=\"1030\" alt=\"Screenshot 2023-05-09 at 12 26
04\"\r\nsrc=\"4381523a-d839-4425-af5f-0f56e6aa9199\">\r\n\r\nNote
there is no error message, where a correct error input looks
like\r\nthis:\r\n<img width=\"379\" alt=\"Screenshot 2023-05-09 at 12 27
44\"\r\nsrc=\"4b7a498a-ac9a-46d8-94e1-525f4b090cfd\">\r\n\r\nThe
error is simply that `[]` is truthy so was showing as having
errors","sha":"5ceeaa0333025f6ff6e28208a367e05622b40dc6","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","v8.8.0","v8.9.0"],"number":157160,"url":"https://github.com/elastic/kibana/pull/157160","mergeCommit":{"message":"[Fleet]
Do not show error state on input if there are no errors (#157160)\n\n##
Summary\r\nFixes this bug, where there was previously an error with this
input but\r\nit has been solved, we still have it in the error
state:\r\n<img width=\"1030\" alt=\"Screenshot 2023-05-09 at 12 26
04\"\r\nsrc=\"4381523a-d839-4425-af5f-0f56e6aa9199\">\r\n\r\nNote
there is no error message, where a correct error input looks
like\r\nthis:\r\n<img width=\"379\" alt=\"Screenshot 2023-05-09 at 12 27
44\"\r\nsrc=\"4b7a498a-ac9a-46d8-94e1-525f4b090cfd\">\r\n\r\nThe
error is simply that `[]` is truthy so was showing as having
errors","sha":"5ceeaa0333025f6ff6e28208a367e05622b40dc6"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157160","number":157160,"mergeCommit":{"message":"[Fleet]
Do not show error state on input if there are no errors (#157160)\n\n##
Summary\r\nFixes this bug, where there was previously an error with this
input but\r\nit has been solved, we still have it in the error
state:\r\n<img width=\"1030\" alt=\"Screenshot 2023-05-09 at 12 26
04\"\r\nsrc=\"4381523a-d839-4425-af5f-0f56e6aa9199\">\r\n\r\nNote
there is no error message, where a correct error input looks
like\r\nthis:\r\n<img width=\"379\" alt=\"Screenshot 2023-05-09 at 12 27
44\"\r\nsrc=\"4b7a498a-ac9a-46d8-94e1-525f4b090cfd\">\r\n\r\nThe
error is simply that `[]` is truthy so was showing as having
errors","sha":"5ceeaa0333025f6ff6e28208a367e05622b40dc6"}}]}]
BACKPORT-->

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
This commit is contained in:
Kibana Machine 2023-05-09 12:06:15 -04:00 committed by GitHub
parent 2bb4d54322
commit ae7073d487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,7 +60,7 @@ export const PackagePolicyInputVarField: React.FunctionComponent<{
}) => {
const [isDirty, setIsDirty] = useState<boolean>(false);
const { multi, required, type, title, name, description, options } = varDef;
const isInvalid = (isDirty || forceShowErrors) && !!varErrors;
const isInvalid = (isDirty || forceShowErrors) && !!varErrors?.length;
const errors = isInvalid ? varErrors : null;
const fieldLabel = title || name;
const fieldTestSelector = fieldLabel.replace(/\s/g, '-').toLowerCase();