From 15b28c5d3ae41e337106a3c7079dc8bac0105644 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Tue, 5 Dec 2023 09:54:48 -0800 Subject: [PATCH] Allow empty field name for supporting timeframe and keywords when validating rule during creation/update (#823) * allow empty field name for supporting timeframe and keywords Signed-off-by: Amardeepsingh Siglani * fixed cypress test Signed-off-by: Amardeepsingh Siglani --------- Signed-off-by: Amardeepsingh Siglani --- cypress/integration/2_rules.spec.js | 12 +++++++++--- .../components/RuleEditor/DetectionVisualEditor.tsx | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cypress/integration/2_rules.spec.js b/cypress/integration/2_rules.spec.js index df5d49f12..884dd7192 100644 --- a/cypress/integration/2_rules.spec.js +++ b/cypress/integration/2_rules.spec.js @@ -325,13 +325,20 @@ describe('Rules', () => { it('...should validate selection map key field', () => { getSelectionPanelByIndex(0).within(() => { getMapKeyField().should('be.empty'); - getMapKeyField().focus().blur(); + getMapKeyField() + .focus() + .blur() + .parents('.euiFormRow__fieldWrapper') + .find('.euiFormErrorText') + .should('not.exist'); + + getMapKeyField().type('hello@'); getMapKeyField() .parentsUntil('.euiFormRow__fieldWrapper') .siblings() .contains('Invalid key name'); - getMapKeyField().type('FieldKey'); + getMapKeyField().focus().type('{selectall}').type('FieldKey'); getMapKeyField() .focus() .blur() @@ -441,7 +448,6 @@ describe('Rules', () => { getSelectionPanelByIndex(0).within(() => getMapKeyField().type('{selectall}').type('{backspace}') ); - toastShouldExist(); getSelectionPanelByIndex(0).within(() => getMapKeyField().type('FieldKey')); // selection map value field diff --git a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx index 3cf4d4bbc..f6de5a875 100644 --- a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx +++ b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx @@ -307,7 +307,8 @@ export class DetectionVisualEditor extends React.Component< if ('field' in data) { const fieldName = `field_${selIdx}_${idx}`; delete errors.fields[fieldName]; - if (!validateDetectionFieldName(data.field)) { + + if (data.field && !validateDetectionFieldName(data.field)) { errors.fields[fieldName] = 'Invalid key name. Valid characters are a-z, A-Z, 0-9, hyphen, period, and underscore.'; }