Skip to content

Commit

Permalink
[SIEM][Detection Engine] Fix StepDescription value in StepRuleActions (
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski authored May 12, 2020
1 parent 68432da commit 533b481
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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 '../../../../../../alerting/common';

const ActionsDescription = ({ actions }: { actions: AlertAction[] }) => {
if (!actions.length) return null;

return (
<ul>
{actions.map((action, index) => (
<li key={index}>{getActionTypeName(action.actionTypeId)}</li>
))}
</ul>
);
};

export const buildActionsDescription = (actions: AlertAction[], title: string) => ({
title: actions.length ? title : '',
description: <ActionsDescription actions={actions} />,
});

const getActionTypeName = (actionTypeId: AlertAction['actionTypeId']) => {
if (!actionTypeId) return '';
const actionType = actionTypeId.split('.')[1];

if (!actionType) return '';

return startCase(actionType);
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
} from './helpers';
import { useSiemJobs } from '../../../../common/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 {
Expand Down Expand Up @@ -73,6 +75,15 @@ export const StepRuleDescriptionComponent: React.FC<StepRuleDescriptionProps> =
),
];
}

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)];
}, []);

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import {
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 '../../../../common/lib/kibana';
import { schema } from './schema';
Expand All @@ -33,7 +37,7 @@ const stepActionsDefaultValue = {
isNew: true,
actions: [],
kibanaSiemAppUrl: '',
throttle: THROTTLE_OPTIONS[0].value,
throttle: DEFAULT_THROTTLE_OPTION.value,
};

const GhostFormField = () => <></>;
Expand Down Expand Up @@ -116,7 +120,7 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({

return isReadOnlyView && myStepData != null ? (
<StepContentWrapper addPadding={addPadding}>
<StepRuleDescription schema={schema} data={myStepData} />
<StepRuleDescription schema={schema} data={myStepData} columns="single" />
</StepContentWrapper>
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ 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',
Expand All @@ -29,4 +26,14 @@ export const schema: FormSchema = {
}
),
},
actions: {
label: i18n.translate(
'xpack.siem.detectionEngine.createRule.stepRuleActions.fieldActionsLabel',
{
defaultMessage: 'Actions',
}
),
},
enabled: {},
kibanaSiemAppUrl: {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 533b481

Please sign in to comment.