From 9864cfcf70a160d385b8fd945146cbc8eafc6e30 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 28 Dec 2024 00:09:33 +1100 Subject: [PATCH] [8.17] [Search][a11y] Add validation to extraction rules form (#202980) (#205192) # Backport This will backport the following commits from `main` to `8.17`: - [[Search][a11y] Add validation to extraction rules form (#202980)](https://github.com/elastic/kibana/pull/202980) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Navarone Feekery <13634519+navarone-feekery@users.noreply.github.com> --- .../extraction_rules/edit_extraction_rule.tsx | 30 ++++++- .../edit_field_rule_flyout.tsx | 79 +++++++++++++------ 2 files changed, 81 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_extraction_rule.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_extraction_rule.tsx index fa69e05bd65fd..c32e495f3f889 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_extraction_rule.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_extraction_rule.tsx @@ -298,9 +298,34 @@ export const EditExtractionRule: React.FC = ({ ( + rules={{ + validate: (rule) => { + if (!rule?.trim()) { + return i18n.translate( + 'xpack.enterpriseSearch.content.indices.extractionRules.editContentField.fieldInput.requiredError', + { + defaultMessage: 'A value is required.', + } + ); + } + + if (rule[0] !== '/') { + return i18n.translate( + 'xpack.enterpriseSearch.content.indices.extractionRules.editContentField.fieldInput.slashMissingError', + { + defaultMessage: 'Value must begin with a /.', + } + ); + } + + return true; + }, + }} + render={({ field, fieldState: { error, isTouched } }) => ( <> = ({ = ({ data-telemetry-id="entSearchContent-crawler-domainDetail-extractionRules-saveExtractionRule" type="submit" onClick={() => saveRule({ ...getValues() })} - disabled={!formState.isValid} + disabled={!formState.isValid || !rulesFields || rulesFields.length === 0} > {i18n.translate( 'xpack.enterpriseSearch.content.indices.extractionRules.editRule.saveButtonLabel', diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_field_rule_flyout.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_field_rule_flyout.tsx index 253d66d63820f..c5bad553ab0f6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_field_rule_flyout.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/crawler/crawler_domain_detail/extraction_rules/edit_field_rule_flyout.tsx @@ -227,28 +227,39 @@ export const EditFieldRuleFlyout: React.FC = ({ {!!field.value && ( <> - - ( + + !!rule?.trim() || + i18n.translate( + 'xpack.enterpriseSearch.content.indices.extractionRules.editContentField.fieldInput.requiredError', + { + defaultMessage: 'A value is required.', + } + ), + }} + render={({ field: selectorField, fieldState: { error, isTouched } }) => ( + = ({ onChange={selectorField.onChange} value={selectorField.value ?? ''} /> - )} - /> - + + )} + /> {field.value === FieldType.HTML ? ( = ({ ( + rules={{ + validate: (rule) => + !!rule?.trim() || + i18n.translate( + 'xpack.enterpriseSearch.content.indices.extractionRules.editContentField.contentFixedValue.requiredError', + { + defaultMessage: 'A value is required', + } + ), + }} + render={({ + field: valueField, + fieldState: { error: fieldError, isTouched: fieldIsTouched }, + }) => ( = ({