[9.0] [Inference Endpoints] Fix non-required secret fields getting mangled (#214159) (#214753)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Inference Endpoints] Fix non-required secret fields getting mangled
(#214159)](https://github.com/elastic/kibana/pull/214159)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"94373878+sphilipse@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-17T13:12:17Z","message":"[Inference
Endpoints] Fix non-required secret fields getting mangled
(#214159)\n\nThis fixes an issue with the inference flyout where a
'secret' field\nthat wasn't required would defocus after every keypress.
This happened\nbecause the validation accidentally removed those secrets
from the\nschema, which forced a destruction of the components, and then
on the\nnext render they got added back in.\n\nThis fixes that by no
longer filtering out documents in the validation,\nbut only mapping
them.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"cb6f8bbd3a0545eba76ef6cb3969a33377a4fa25","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Search","backport:all-open","v9.1.0","v8.19.0","v8.18.1"],"title":"[Inference
Endpoints] Fix non-required secret fields getting
mangled","number":214159,"url":"https://github.com/elastic/kibana/pull/214159","mergeCommit":{"message":"[Inference
Endpoints] Fix non-required secret fields getting mangled
(#214159)\n\nThis fixes an issue with the inference flyout where a
'secret' field\nthat wasn't required would defocus after every keypress.
This happened\nbecause the validation accidentally removed those secrets
from the\nschema, which forced a destruction of the components, and then
on the\nnext render they got added back in.\n\nThis fixes that by no
longer filtering out documents in the validation,\nbut only mapping
them.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"cb6f8bbd3a0545eba76ef6cb3969a33377a4fa25"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x","8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214159","number":214159,"mergeCommit":{"message":"[Inference
Endpoints] Fix non-required secret fields getting mangled
(#214159)\n\nThis fixes an issue with the inference flyout where a
'secret' field\nthat wasn't required would defocus after every keypress.
This happened\nbecause the validation accidentally removed those secrets
from the\nschema, which forced a destruction of the components, and then
on the\nnext render they got added back in.\n\nThis fixes that by no
longer filtering out documents in the validation,\nbut only mapping
them.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"cb6f8bbd3a0545eba76ef6cb3969a33377a4fa25"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Sander Philipse <94373878+sphilipse@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2025-03-17 16:12:50 +01:00 committed by GitHub
parent c129ade30c
commit 88b05d2315
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 21 deletions

View file

@ -130,7 +130,7 @@ export const LEARN_MORE = i18n.translate(
export const RE_ENTER_SECRETS = (label: string) => {
return i18n.translate('xpack.inferenceEndpointUICommon.components.requiredGenericTextField', {
defaultMessage:
'You will need to reenter your ${label} each time you edit the inference endpoint',
'You will need to re-enter your {label} each time you edit the inference endpoint',
values: { label },
});
};

View file

@ -44,28 +44,26 @@ export const getNonEmptyValidator = (
const configData = (value ?? {}) as Record<string, unknown>;
let hasErrors = false;
if (schema) {
schema
.filter((f: ConfigEntryView) => f.required)
.forEach((field: ConfigEntryView) => {
// validate if submitting or on field edit - value is not default to null
if (configData[field.key] !== null || isSubmitting) {
// validate secrets fields separately from regular
if (isSecrets ? field.sensitive : !field.sensitive) {
if (
!configData[field.key] ||
(typeof configData[field.key] === 'string' && isEmpty(configData[field.key]))
) {
field.validationErrors = [LABELS.getRequiredMessage(field.label)];
field.isValid = false;
hasErrors = true;
} else {
field.validationErrors = [];
field.isValid = true;
}
schema.map((field: ConfigEntryView) => {
// validate if submitting or on field edit - value is not default to null
if (field.required && (configData[field.key] !== null || isSubmitting)) {
// validate secrets fields separately from regular
if (isSecrets ? field.sensitive : !field.sensitive) {
if (
!configData[field.key] ||
(typeof configData[field.key] === 'string' && isEmpty(configData[field.key]))
) {
field.validationErrors = [LABELS.getRequiredMessage(field.label)];
field.isValid = false;
hasErrors = true;
} else {
field.validationErrors = [];
field.isValid = true;
}
}
newSchema.push(field);
});
}
newSchema.push(field);
});
validationEventHandler(newSchema);
if (hasErrors) {