From be94592c800470e46bf46aec42fd08d1c996c291 Mon Sep 17 00:00:00 2001 From: patrykkopycinski Date: Tue, 12 May 2020 14:42:09 +0200 Subject: [PATCH 1/3] [SIEM][Detection Engine] Fix StepDescription value in StepRuleActions (#63677) # Conflicts: # x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/actions_description.tsx # x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/throttle_description.tsx # x-pack/plugins/siem/public/alerts/components/rules/description_step/index.tsx # x-pack/plugins/siem/public/alerts/components/rules/step_rule_actions/index.tsx # x-pack/plugins/siem/public/alerts/components/rules/step_rule_actions/schema.tsx # x-pack/plugins/siem/public/alerts/components/rules/throttle_select_field/index.tsx --- .../description_step/actions_description.tsx | 35 +++++ .../components/description_step/index.tsx | 25 ++- .../description_step/throttle_description.tsx | 17 ++ .../components/step_rule_actions/index.tsx | 146 +++++++++--------- .../components/step_rule_actions/schema.tsx | 15 +- .../throttle_select_field/index.tsx | 2 + 6 files changed, 161 insertions(+), 79 deletions(-) create mode 100644 x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/actions_description.tsx create mode 100644 x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/throttle_description.tsx diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/actions_description.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/actions_description.tsx new file mode 100644 index 0000000000000..f98062a561040 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/actions_description.tsx @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { startCase } from 'lodash/fp'; +import { AlertAction } from '../../../../../../../../../plugins/alerting/common'; + +const ActionsDescription = ({ actions }: { actions: AlertAction[] }) => { + if (!actions.length) return null; + + return ( + + ); +}; + +export const buildActionsDescription = (actions: AlertAction[], title: string) => ({ + title: actions.length ? title : '', + description: , +}); + +const getActionTypeName = (actionTypeId: AlertAction['actionTypeId']) => { + if (!actionTypeId) return ''; + const actionType = actionTypeId.split('.')[1]; + + if (!actionType) return ''; + + return startCase(actionType); +}; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx index 05e47225c8f4b..e929253556bc2 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx @@ -9,13 +9,13 @@ import { isEmpty, chunk, get, pick, isNumber } from 'lodash/fp'; import React, { memo, useState } from 'react'; import styled from 'styled-components'; +import { RuleType } from '../../types'; import { IIndexPattern, Filter, esFilters, FilterManager, } from '../../../../../../../../../../src/plugins/data/public'; -import { RuleType } from '../../../../../../common/detection_engine/types'; import { DEFAULT_TIMELINE_TITLE } from '../../../../../components/timeline/translations'; import { useKibana } from '../../../../../lib/kibana'; import { IMitreEnterpriseAttack } from '../../types'; @@ -34,6 +34,8 @@ import { } from './helpers'; import { useSiemJobs } from '../../../../../components/ml_popover/hooks/use_siem_jobs'; import { buildMlJobDescription } from './ml_job_description'; +import { buildActionsDescription } from './actions_description'; +import { buildThrottleDescription } from './throttle_description'; const DescriptionListContainer = styled(EuiDescriptionList)` &.euiDescriptionList--column .euiDescriptionList__title { @@ -73,6 +75,15 @@ export const StepRuleDescriptionComponent: React.FC = ), ]; } + + if (key === 'throttle') { + return [...acc, buildThrottleDescription(get(key, data), get([key, 'label'], schema))]; + } + + if (key === 'actions') { + return [...acc, buildActionsDescription(get(key, data), get([key, 'label'], schema))]; + } + return [...acc, ...buildListItems(data, pick(key, schema), filterManager, indexPatterns)]; }, []); @@ -97,12 +108,12 @@ export const StepRuleDescriptionComponent: React.FC = {columns === 'single' ? ( ) : ( - - )} + + )} ); diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/throttle_description.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/throttle_description.tsx new file mode 100644 index 0000000000000..b3cdbabab36e2 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/throttle_description.tsx @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { find } from 'lodash/fp'; +import { THROTTLE_OPTIONS, DEFAULT_THROTTLE_OPTION } from '../throttle_select_field'; + +export const buildThrottleDescription = (value = DEFAULT_THROTTLE_OPTION.value, title: string) => { + const throttleOption = find(['value', value], THROTTLE_OPTIONS); + + return { + title, + description: throttleOption ? throttleOption.text : value, + }; +}; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx index aec315938b6ae..29171f3a5a572 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx @@ -9,11 +9,19 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState } from 'reac import deepEqual from 'fast-deep-equal'; import { setFieldValue } from '../../helpers'; -import { RuleStep, RuleStepProps, ActionsStepRule } from '../../types'; +import { + RuleStep, + RuleStepProps, + ActionsStepRule, +} from '../../types'; import { StepRuleDescription } from '../description_step'; import { Form, UseField, useForm } from '../../../../../shared_imports'; import { StepContentWrapper } from '../step_content_wrapper'; -import { ThrottleSelectField, THROTTLE_OPTIONS } from '../throttle_select_field'; +import { + ThrottleSelectField, + THROTTLE_OPTIONS, + DEFAULT_THROTTLE_OPTION, +} from '../throttle_select_field'; import { RuleActionsField } from '../rule_actions_field'; import { useKibana } from '../../../../../lib/kibana'; import { schema } from './schema'; @@ -29,7 +37,7 @@ const stepActionsDefaultValue = { isNew: true, actions: [], kibanaSiemAppUrl: '', - throttle: THROTTLE_OPTIONS[0].value, + throttle: DEFAULT_THROTTLE_OPTION.value, }; const GhostFormField = () => <>; @@ -112,74 +120,74 @@ const StepRuleActionsComponent: FC = ({ return isReadOnlyView && myStepData != null ? ( - + ) : ( - <> - -
- - {myStepData.throttle !== stepActionsDefaultValue.throttle && ( - <> - - - - - )} - - -
- - {!isUpdateView && ( - <> - - - - - {I18n.COMPLETE_WITHOUT_ACTIVATING} - - - - - {I18n.COMPLETE_WITH_ACTIVATING} - - - - - )} - - ); + <> + +
+ + {myStepData.throttle !== stepActionsDefaultValue.throttle && ( + <> + + + + + )} + + +
+ + {!isUpdateView && ( + <> + + + + + {I18n.COMPLETE_WITHOUT_ACTIVATING} + + + + + {I18n.COMPLETE_WITH_ACTIVATING} + + + + + )} + + ); }; export const StepRuleActions = memo(StepRuleActionsComponent); diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx index bc3b0dfe720bc..78715eb5b222c 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx @@ -4,14 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ +/* istanbul ignore file */ + import { i18n } from '@kbn/i18n'; import { FormSchema } from '../../../../../shared_imports'; export const schema: FormSchema = { - actions: {}, - enabled: {}, - kibanaSiemAppUrl: {}, throttle: { label: i18n.translate( 'xpack.siem.detectionEngine.createRule.stepRuleActions.fieldThrottleLabel', @@ -27,4 +26,14 @@ export const schema: FormSchema = { } ), }, + actions: { + label: i18n.translate( + 'xpack.siem.detectionEngine.createRule.stepRuleActions.fieldActionsLabel', + { + defaultMessage: 'Actions', + } + ), + }, + enabled: {}, + kibanaSiemAppUrl: {}, }; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/throttle_select_field/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/throttle_select_field/index.tsx index 0cf15c41a0f91..9628ab7525404 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/throttle_select_field/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/throttle_select_field/index.tsx @@ -20,6 +20,8 @@ export const THROTTLE_OPTIONS = [ { value: '7d', text: 'Weekly' }, ]; +export const DEFAULT_THROTTLE_OPTION = THROTTLE_OPTIONS[0]; + type ThrottleSelectField = typeof SelectField; export const ThrottleSelectField: ThrottleSelectField = props => { From cdfa5583fa8f3c59426b32cd853437068da98208 Mon Sep 17 00:00:00 2001 From: Patryk Kopycinski Date: Tue, 12 May 2020 17:17:09 +0200 Subject: [PATCH 2/3] fix lint --- .../components/description_step/index.tsx | 14 +- .../components/step_rule_actions/index.tsx | 136 +++++++++--------- 2 files changed, 73 insertions(+), 77 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx index e929253556bc2..8a063216bd4f7 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx @@ -9,7 +9,7 @@ import { isEmpty, chunk, get, pick, isNumber } from 'lodash/fp'; import React, { memo, useState } from 'react'; import styled from 'styled-components'; -import { RuleType } from '../../types'; +import { RuleType } from '../../../../../../common/detection_engine/types'; import { IIndexPattern, Filter, @@ -108,12 +108,12 @@ export const StepRuleDescriptionComponent: React.FC = {columns === 'single' ? ( ) : ( - - )} + + )} ); diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx index 29171f3a5a572..7ffb49840eeb5 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/index.tsx @@ -9,11 +9,7 @@ import React, { FC, memo, useCallback, useEffect, useMemo, useState } from 'reac import deepEqual from 'fast-deep-equal'; import { setFieldValue } from '../../helpers'; -import { - RuleStep, - RuleStepProps, - ActionsStepRule, -} from '../../types'; +import { RuleStep, RuleStepProps, ActionsStepRule } from '../../types'; import { StepRuleDescription } from '../description_step'; import { Form, UseField, useForm } from '../../../../../shared_imports'; import { StepContentWrapper } from '../step_content_wrapper'; @@ -123,71 +119,71 @@ const StepRuleActionsComponent: FC = ({ ) : ( - <> - -
- - {myStepData.throttle !== stepActionsDefaultValue.throttle && ( - <> - - - - - )} - - -
- - {!isUpdateView && ( - <> - - - - - {I18n.COMPLETE_WITHOUT_ACTIVATING} - - - - - {I18n.COMPLETE_WITH_ACTIVATING} - - - - - )} - - ); + <> + +
+ + {myStepData.throttle !== stepActionsDefaultValue.throttle && ( + <> + + + + + )} + + +
+ + {!isUpdateView && ( + <> + + + + + {I18n.COMPLETE_WITHOUT_ACTIVATING} + + + + + {I18n.COMPLETE_WITH_ACTIVATING} + + + + + )} + + ); }; export const StepRuleActions = memo(StepRuleActionsComponent); From 2e297de3267e7b0d64405b6263c020549efc9bca Mon Sep 17 00:00:00 2001 From: Patryk Kopycinski Date: Tue, 12 May 2020 17:18:47 +0200 Subject: [PATCH 3/3] lint --- .../rules/components/description_step/index.tsx | 2 +- .../rules/components/step_rule_actions/schema.tsx | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx index 8a063216bd4f7..70d936fe26f63 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx @@ -9,13 +9,13 @@ import { isEmpty, chunk, get, pick, isNumber } from 'lodash/fp'; import React, { memo, useState } from 'react'; import styled from 'styled-components'; -import { RuleType } from '../../../../../../common/detection_engine/types'; import { IIndexPattern, Filter, esFilters, FilterManager, } from '../../../../../../../../../../src/plugins/data/public'; +import { RuleType } from '../../../../../../common/detection_engine/types'; import { DEFAULT_TIMELINE_TITLE } from '../../../../../components/timeline/translations'; import { useKibana } from '../../../../../lib/kibana'; import { IMitreEnterpriseAttack } from '../../types'; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx index 78715eb5b222c..18606975cb640 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_rule_actions/schema.tsx @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -/* istanbul ignore file */ - import { i18n } from '@kbn/i18n'; import { FormSchema } from '../../../../../shared_imports';