Skip to content

Commit

Permalink
[Security solution][Endpoint] Set event filters form as error when th…
Browse files Browse the repository at this point in the history
…ere are no entries (#107003) (#107075)

* Set form as error when there is no entries

* removes unused imports

* Add comparison

Co-authored-by: David Sánchez <[email protected]>
  • Loading branch information
kibanamachine and dasansol92 authored Jul 28, 2021
1 parent db13ec9 commit c6785ab
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type EventFiltersInitFromId = Action<'eventFiltersInitFromId'> & {

export type EventFiltersChangeForm = Action<'eventFiltersChangeForm'> & {
payload: {
entry: UpdateExceptionListItemSchema | CreateExceptionListItemSchema;
entry?: UpdateExceptionListItemSchema | CreateExceptionListItemSchema;
hasNameError?: boolean;
hasItemsError?: boolean;
hasOSError?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ describe('event filters reducer', () => {
});
});

it('change form values without entry', () => {
const newComment = 'new comment';
const result = eventFiltersPageReducer(initialState, {
type: 'eventFiltersChangeForm',
payload: { newComment },
});

expect(result).toStrictEqual({
...initialState,
form: {
...initialState.form,
newComment,
submissionResourceState: {
type: 'UninitialisedResourceState',
},
},
});
});

it('change form status', () => {
const result = eventFiltersPageReducer(initialState, {
type: 'eventFiltersFormStateChanged',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const eventFiltersChangeForm: CaseReducer<EventFiltersChangeForm> = (state, acti
...state,
form: {
...state.form,
entry: action.payload.entry,
entry: action.payload.entry !== undefined ? action.payload.entry : state.form.entry,
hasItemsError:
action.payload.hasItemsError !== undefined
? action.payload.hasItemsError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
EuiText,
} from '@elastic/eui';

import { isEmpty } from 'lodash/fp';
import type { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types';

import { OperatingSystem } from '../../../../../../../common/endpoint/types';
import { AddExceptionComments } from '../../../../../../common/components/exceptions/add_exception_comments';
import { filterIndexPatterns } from '../../../../../../common/components/exceptions/helpers';
Expand Down Expand Up @@ -65,17 +65,22 @@ export const EventFiltersForm: React.FC<EventFiltersFormProps> = memo(

const handleOnBuilderChange = useCallback(
(arg: ExceptionBuilder.OnChangeProps) => {
if (isEmpty(arg.exceptionItems)) return;
dispatch({
type: 'eventFiltersChangeForm',
payload: {
entry: {
...arg.exceptionItems[0],
name: exception?.name ?? '',
comments: exception?.comments ?? [],
os_types: exception?.os_types ?? [OperatingSystem.WINDOWS],
},
hasItemsError: arg.errorExists || !arg.exceptionItems[0].entries.length,
...(arg.exceptionItems[0] !== undefined
? {
entry: {
...arg.exceptionItems[0],
name: exception?.name ?? '',
comments: exception?.comments ?? [],
os_types: exception?.os_types ?? [OperatingSystem.WINDOWS],
},
hasItemsError: arg.errorExists || !arg.exceptionItems[0]?.entries?.length,
}
: {
hasItemsError: true,
}),
},
});
},
Expand Down

0 comments on commit c6785ab

Please sign in to comment.