From c8c288ab8331be62b0d6440827d257874770ac83 Mon Sep 17 00:00:00 2001 From: Amardeepsingh Siglani Date: Mon, 17 Apr 2023 10:42:43 -0700 Subject: [PATCH] Create detector refactor alert triggers per mocks (#503) (#514) * [FEATURE] Create detector \ Refactor and move field mapping to first the page of create detector feature #495 * [FEATURE] Create global state object for async requests #493 * [FEATURE] Create detector \ Refactor alert triggers per mocks #498 * [FEATURE] Create detector \ Refactor alert triggers per mocks #498 * [FEATURE] Create detector \ Refactor alert triggers per mocks #498 * Create detector refactor alert triggers per mocks #503 * Update detector details component #504 --------- Signed-off-by: Jovan Cvetkovic Co-authored-by: Jovan Cvetkovic --- cypress/integration/1_detectors.spec.js | 17 ++-- .../AlertCondition/AlertConditionPanel.tsx | 2 +- .../AlertConditionPanel.test.tsx.snap | 4 +- .../containers/ConfigureAlerts.tsx | 97 +++++++++++++------ .../containers/CreateDetector.tsx | 5 +- .../pages/CreateDetector/utils/constants.ts | 2 +- .../AlertTriggerView/AlertTriggerView.tsx | 7 +- .../AlertTriggerView.test.tsx.snap | 20 +--- .../FieldMappingsView/FieldMappingsView.tsx | 2 +- .../FieldMappingsView.test.tsx.snap | 16 +-- .../AlertTriggersView/AlertTriggersView.tsx | 23 ++++- .../AlertTriggersView.test.tsx.snap | 39 ++------ 12 files changed, 131 insertions(+), 103 deletions(-) diff --git a/cypress/integration/1_detectors.spec.js b/cypress/integration/1_detectors.spec.js index 2d4d253ea..81a33f2cc 100644 --- a/cypress/integration/1_detectors.spec.js +++ b/cypress/integration/1_detectors.spec.js @@ -18,6 +18,10 @@ const testMappings = { const cypressDNSRule = dns_rule_data.title; +const cypressIndexDns = 'cypress-index-dns'; +const cypressIndexWindows = 'cypress-index-windows'; +const detectorName = 'test detector'; + const createDetector = (detectorName, dataSource, expectFailure) => { // Locate Create detector button click to start cy.get('.euiButton').filter(':contains("Create detector")').click({ force: true }); @@ -73,10 +77,10 @@ const createDetector = (detectorName, dataSource, expectFailure) => { cy.get('button').contains('Next').click({ force: true }); // Check that correct page now showing - cy.contains('Set up alerts'); + cy.contains('Set up alert triggers'); // Type name of new trigger - cy.get(`input[placeholder="Enter a name for the alert condition."]`) + cy.get(`input[placeholder="Enter a name to describe the alert condition"]`) .focus() .realType('test_trigger'); @@ -113,8 +117,7 @@ const createDetector = (detectorName, dataSource, expectFailure) => { cy.contains('Detector details'); cy.contains(detectorName); cy.contains('dns'); - cy.contains(dataSource); - cy.contains('Alert on test_trigger'); + cy.contains('test_trigger'); // Create the detector cy.get('button').contains('Create').click({ force: true }); @@ -141,10 +144,6 @@ const createDetector = (detectorName, dataSource, expectFailure) => { }; describe('Detectors', () => { - const cypressIndexDns = 'cypress-index-dns'; - const cypressIndexWindows = 'cypress-index-windows'; - const detectorName = 'test detector'; - before(() => { cy.cleanUpTests(); @@ -362,6 +361,8 @@ describe('Detectors', () => { cy.get(`[data-test-subj="define-detector-select-data-source"]`).type( `${cypressIndexWindows}{enter}` ); + + cy.get('.reviewFieldMappings').should('be.visible'); }); it('...should show field mappings if rule selection is changed', () => { diff --git a/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx b/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx index ae7c5ef45..79939763b 100644 --- a/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx +++ b/public/pages/CreateDetector/components/ConfigureAlerts/components/AlertCondition/AlertConditionPanel.tsx @@ -311,7 +311,7 @@ export default class AlertConditionPanel extends Component< error={getNameErrorMessage(name, nameIsInvalid, nameFieldTouched)} > @@ -779,7 +779,7 @@ Object { class="euiFieldText" data-test-subj="alert-condition-name-0" id="some_html_id" - placeholder="Enter a name for the alert condition." + placeholder="Enter a name to describe the alert condition" type="text" value="alert_name" /> diff --git a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx index 9041ccab6..2bcc2223c 100644 --- a/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx +++ b/public/pages/CreateDetector/components/ConfigureAlerts/containers/ConfigureAlerts.tsx @@ -8,16 +8,17 @@ import { RouteComponentProps } from 'react-router-dom'; import { EuiAccordion, EuiButton, + EuiCallOut, + EuiFlexGroup, + EuiFlexItem, EuiHorizontalRule, EuiPanel, EuiSpacer, - EuiTitle, EuiText, + EuiTitle, } from '@elastic/eui'; -import { createDetectorSteps } from '../../../utils/constants'; import { MAX_ALERT_CONDITIONS } from '../utils/constants'; import AlertConditionPanel from '../components/AlertCondition'; -import { Detector } from '../../../../../../models/interfaces'; import { DetectorCreationStep } from '../../../models/types'; import { CreateDetectorRulesOptions } from '../../../../../models/types'; import { NotificationChannelTypeOptions } from '../models/interfaces'; @@ -30,6 +31,7 @@ import { NotificationsService } from '../../../../../services'; import { validateName } from '../../../../../utils/validation'; import { CoreServicesContext } from '../../../../../components/core_services'; import { BREADCRUMBS } from '../../../../../utils/constants'; +import { Detector } from '../../../../../../types'; interface ConfigureAlertsProps extends RouteComponentProps { detector: Detector; @@ -39,6 +41,7 @@ interface ConfigureAlertsProps extends RouteComponentProps { updateDataValidState: (step: DetectorCreationStep, isValid: boolean) => void; notificationsService: NotificationsService; hasNotificationPlugin: boolean; + skipAndConfigureHandler: () => void; } interface ConfigureAlertsState { @@ -77,12 +80,10 @@ export default class ConfigureAlerts extends Component { this.updateBreadcrumbs(); const { - isEdit, - detector, detector: { triggers }, } = this.props; this.getNotificationChannels(); - + if (triggers.length === 0) { this.addCondition(); } @@ -114,9 +115,11 @@ export default class ConfigureAlerts extends Component { - const isTriggerDataValid = newDetector.triggers.every((trigger) => { - return !!trigger.name && validateName(trigger.name) && trigger.severity; - }); + const isTriggerDataValid = + !newDetector.triggers.length || + newDetector.triggers.every((trigger) => { + return !!trigger.name && validateName(trigger.name) && trigger.severity; + }); this.props.changeDetector(newDetector); this.props.updateDataValidState(DetectorCreationStep.CONFIGURE_ALERTS, isTriggerDataValid); @@ -135,22 +138,45 @@ export default class ConfigureAlerts extends Component { + if (isEdit) { + return <>Alert triggers (${triggers.length}); + } + + return ( + + + +

Set up alert triggers

+
+ + Get notified when specific rule conditions are found by the detector. + +
+ {triggers?.length && ( + + { + const { changeDetector, detector } = this.props; + changeDetector({ ...detector, triggers: [] }); + skipAndConfigureHandler(); + }} + > + Skip and configure later + + + )} +
+ ); + }; + const { loading, notificationChannels } = this.state; return (
- -

- {isEdit - ? 'Edit alert triggers' - : createDetectorSteps[DetectorCreationStep.CONFIGURE_ALERTS].title + - ` (${triggers.length})`} -

-
- - - Get notified when specific rule conditions are found by the detector. - + {getPageTitle()} @@ -162,19 +188,15 @@ export default class ConfigureAlerts extends Component -

{alertCondition.name}

+

{isEdit ? alertCondition.name : 'Alert trigger'}

} paddingSize={'none'} initialIsOpen={true} extraAction={ - triggers.length > 1 ? ( - this.onDelete(index)}> - Remove alert trigger - - ) : ( - <> - ) + this.onDelete(index)}> + Remove + } > @@ -193,11 +215,26 @@ export default class ConfigureAlerts extends Component
))} + {!triggers?.length && ( + +

+ We recommend creating alert triggers to get notified when specific conditions are + found by the detector. +

+

You can also configure alert triggers after the detector is created.

+ + } + /> + )} = MAX_ALERT_CONDITIONS} onClick={this.addCondition}> - {`Add ${triggers.length > 0 ? 'another' : 'an'} alert condition`} + {triggers.length > 0 ? 'Add another alert trigger' : 'Add alert triggers'} ); diff --git a/public/pages/CreateDetector/containers/CreateDetector.tsx b/public/pages/CreateDetector/containers/CreateDetector.tsx index 5bdf62eb8..be04440da 100644 --- a/public/pages/CreateDetector/containers/CreateDetector.tsx +++ b/public/pages/CreateDetector/containers/CreateDetector.tsx @@ -312,6 +312,7 @@ export default class CreateDetector extends Component ); case DetectorCreationStep.REVIEW_CREATE: @@ -355,7 +356,7 @@ export default class CreateDetector extends Component DetectorCreationStep.DEFINE_DETECTOR && ( - Previous + Back )} @@ -380,7 +381,7 @@ export default class CreateDetector extends Component - Create + Create detector )} diff --git a/public/pages/CreateDetector/utils/constants.ts b/public/pages/CreateDetector/utils/constants.ts index 91cc66760..d4a27e787 100644 --- a/public/pages/CreateDetector/utils/constants.ts +++ b/public/pages/CreateDetector/utils/constants.ts @@ -12,7 +12,7 @@ export const createDetectorSteps: Record = ({ const conditionRuleNames = ids.map((ruleId) => rules[ruleId]?._source.title); return (
- {orderPosition > 0 && } - + {orderPosition > 0 && } + {orderPosition === 0 && } -

{`Alert on ${name}`}

+

{name}

} > @@ -104,7 +104,6 @@ export const AlertTriggerView: React.FC = ({ }, ])}
-
); }; diff --git a/public/pages/Detectors/components/AlertTriggerView/__snapshots__/AlertTriggerView.test.tsx.snap b/public/pages/Detectors/components/AlertTriggerView/__snapshots__/AlertTriggerView.test.tsx.snap index cc6d33387..bfceeddf3 100644 --- a/public/pages/Detectors/components/AlertTriggerView/__snapshots__/AlertTriggerView.test.tsx.snap +++ b/public/pages/Detectors/components/AlertTriggerView/__snapshots__/AlertTriggerView.test.tsx.snap @@ -7,10 +7,7 @@ Object {

-

- Alert on alert_name + alert_name

@@ -362,19 +359,13 @@ Object {
-
, "container":

-

- Alert on alert_name + alert_name

@@ -726,9 +717,6 @@ Object {
-
, "debug": [Function], diff --git a/public/pages/Detectors/components/FieldMappingsView/FieldMappingsView.tsx b/public/pages/Detectors/components/FieldMappingsView/FieldMappingsView.tsx index 76b4d55f9..da8599dfd 100644 --- a/public/pages/Detectors/components/FieldMappingsView/FieldMappingsView.tsx +++ b/public/pages/Detectors/components/FieldMappingsView/FieldMappingsView.tsx @@ -29,7 +29,7 @@ const columns: EuiBasicTableColumn[] = [ }, { field: 'logFieldName', - name: 'Mapped index field name', + name: 'Mapped log field name', }, ]; diff --git a/public/pages/Detectors/components/FieldMappingsView/__snapshots__/FieldMappingsView.test.tsx.snap b/public/pages/Detectors/components/FieldMappingsView/__snapshots__/FieldMappingsView.test.tsx.snap index 199178e02..86c71d206 100644 --- a/public/pages/Detectors/components/FieldMappingsView/__snapshots__/FieldMappingsView.test.tsx.snap +++ b/public/pages/Detectors/components/FieldMappingsView/__snapshots__/FieldMappingsView.test.tsx.snap @@ -112,9 +112,9 @@ Object { > - Mapped index field name + Mapped log field name @@ -148,7 +148,7 @@ Object {
- Mapped index field name + Mapped log field name
- Mapped index field name + Mapped log field name
- Mapped index field name + Mapped log field name @@ -353,7 +353,7 @@ Object {
- Mapped index field name + Mapped log field name
- Mapped index field name + Mapped log field name
= ({ rules={rules} /> ))} + {!detector?.triggers?.length && ( + <> + +

No alert triggers defined.

+ + + +

+ We recommend creating alert triggers to get notified when specific conditions are + found by the detector. +

+

You can also configure alert triggers after the detector is created.

+ + } + /> + + )} ); }; diff --git a/public/pages/Detectors/containers/AlertTriggersView/__snapshots__/AlertTriggersView.test.tsx.snap b/public/pages/Detectors/containers/AlertTriggersView/__snapshots__/AlertTriggersView.test.tsx.snap index df175c554..812c5575a 100644 --- a/public/pages/Detectors/containers/AlertTriggersView/__snapshots__/AlertTriggersView.test.tsx.snap +++ b/public/pages/Detectors/containers/AlertTriggersView/__snapshots__/AlertTriggersView.test.tsx.snap @@ -579,10 +579,10 @@ exports[` spec renders the component 1`] = ` >
spec renders the component 1`] = ` size="m" >

- Alert on alert_name + alert_name

} @@ -637,7 +637,7 @@ exports[` spec renders the component 1`] = ` className="euiText euiText--medium" >

- Alert on alert_name + alert_name

@@ -1357,13 +1357,6 @@ exports[` spec renders the component 1`] = `
- -
-
spec renders the component 1`] = ` rules={Object {}} >
- +
- -
- spec renders the component 1`] = ` size="m" >

- Alert on alert_name + alert_name

} @@ -1670,7 +1658,7 @@ exports[` spec renders the component 1`] = ` className="euiText euiText--medium" >

- Alert on alert_name + alert_name

@@ -2390,13 +2378,6 @@ exports[` spec renders the component 1`] = `
- -
-