diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/action.ts b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/action.ts index 588eb9275ad21..c4432faef455f 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/action.ts +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/action.ts @@ -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; diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.test.ts b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.test.ts index 1b856f54d16a9..0deb7cb51c850 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.test.ts +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.test.ts @@ -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', diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts index b6e853ca4bf0f..c90d4af769e06 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/store/reducer.ts @@ -100,7 +100,7 @@ const eventFiltersChangeForm: CaseReducer = (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 diff --git a/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx b/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx index 29723a5fd3cf8..ac9766630d028 100644 --- a/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/event_filters/view/components/form/index.tsx @@ -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'; @@ -65,17 +65,22 @@ export const EventFiltersForm: React.FC = 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, + }), }, }); },