From ceb780075d05e714b621c216e202c6337d3668b6 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 | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cypress/integration/2_rules.spec.js b/cypress/integration/2_rules.spec.js index 18b18f6ca..3e90ed212 100644 --- a/cypress/integration/2_rules.spec.js +++ b/cypress/integration/2_rules.spec.js @@ -330,13 +330,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() @@ -446,7 +453,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 bf63b5fa9..84390d5fe 100644 --- a/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx +++ b/public/pages/Rules/components/RuleEditor/DetectionVisualEditor.tsx @@ -275,7 +275,7 @@ export class DetectionVisualEditor extends React.Component< 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, hyphens, dots, and underscores'; }