From 169cd100a3a461664d85398b8099437060a3d463 Mon Sep 17 00:00:00 2001 From: Pedro Jaramillo Date: Mon, 6 Jul 2020 13:16:35 -0400 Subject: [PATCH] address PR comments --- .../alerts/components/alerts_table/index.tsx | 2 +- .../common/components/exceptions/helpers.tsx | 2 +- ...se_fetch_or_create_rule_exception_list.tsx | 21 ++++++------------- .../components/exceptions/viewer/index.tsx | 6 +++--- .../components/exceptions/viewer/reducer.ts | 6 ++++-- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx b/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx index c39f2ab21f70815..569145902dada48 100644 --- a/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx +++ b/x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx @@ -102,7 +102,7 @@ export const AlertsTableComponent: React.FC = ({ const [showClearSelectionAction, setShowClearSelectionAction] = useState(false); const [filterGroup, setFilterGroup] = useState(FILTER_OPEN); const [shouldShowAddExceptionModal, setShouldShowAddExceptionModal] = useState(false); - const [addExceptionModalState, setAddExceptionModalState] = useState( + const [addExceptionModalState, setAddExceptionModalState] = useState( addExceptionModalInitialState ); const [{ browserFields, indexPatterns }] = useFetchIndexPatterns( diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx index cb4b6f1d9d6cc27..db7cb5aeac8f093 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/helpers.tsx @@ -194,7 +194,7 @@ export const getDescriptionListContent = ( const details = [ { title: i18n.OPERATING_SYSTEM, - value: getOperatingSystems(exceptionItem._tags ?? []), + value: getOperatingSystems(exceptionItem._tags), }, { title: i18n.DATE_CREATED, diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx index bda406c5a2e4737..a0083b7ba563502 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx @@ -23,7 +23,6 @@ export interface UseFetchOrCreateRuleExceptionListProps { ruleId: Rule['id']; exceptionListType: ExceptionListSchema['type']; onError: (arg: Error) => void; - onSuccess?: (arg: ExceptionListSchema) => void; } /** @@ -33,7 +32,6 @@ export interface UseFetchOrCreateRuleExceptionListProps { * @param ruleId id of the rule * @param exceptionListType type of the exception list to be fetched or created * @param onError error callback - * @param onSuccess optional callback when all lists fetched successfully * */ export const useFetchOrCreateRuleExceptionList = ({ @@ -41,7 +39,6 @@ export const useFetchOrCreateRuleExceptionList = ({ ruleId, exceptionListType, onError, - onSuccess, }: UseFetchOrCreateRuleExceptionListProps): ReturnUseFetchOrCreateRuleExceptionList => { const [isLoading, setIsLoading] = useState(false); const [exceptionList, setExceptionList] = useState(null); @@ -77,17 +74,14 @@ export const useFetchOrCreateRuleExceptionList = ({ ): Promise { const newExceptionList = await createExceptionList(ruleResponse); - let newExceptionListReferences: ListArray; - const newExceptonListReference = { + const newExceptionListReference = { id: newExceptionList.id, namespace_type: newExceptionList.namespace_type, }; - const exceptionListReferences = ruleResponse.exceptions_list as ListArray; - if (exceptionListReferences && exceptionListReferences.length > 0) { - newExceptionListReferences = [...exceptionListReferences, newExceptonListReference]; - } else { - newExceptionListReferences = [newExceptonListReference]; - } + const newExceptionListReferences: ListArray = [ + ...(ruleResponse.exceptions_list ?? []), + newExceptionListReference, + ]; await patchRule({ ruleProperties: { @@ -149,9 +143,6 @@ export const useFetchOrCreateRuleExceptionList = ({ if (isSubscribed) { setExceptionList(exceptionListToUse); setIsLoading(false); - if (onSuccess !== undefined) { - onSuccess(exceptionListToUse); - } } } catch (error) { if (isSubscribed) { @@ -167,7 +158,7 @@ export const useFetchOrCreateRuleExceptionList = ({ isSubscribed = false; abortCtrl.abort(); }; - }, [http, ruleId, exceptionListType, onSuccess, onError]); + }, [http, ruleId, exceptionListType, onError]); return [isLoading, exceptionList]; }; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx index 9751f6d448bd510..fd4a4b9038a1e8c 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx @@ -15,7 +15,7 @@ import { Panel } from '../../../../common/components/panel'; import { Loader } from '../../../../common/components/loader'; import { ExceptionsViewerHeader } from './exceptions_viewer_header'; import { ExceptionListType, Filter } from '../types'; -import { allExceptionItemsReducer, State } from './reducer'; +import { allExceptionItemsReducer, State, ViewerModalName } from './reducer'; import { useExceptionList, ExceptionIdentifiers, @@ -131,7 +131,7 @@ const ExceptionsViewerComponent = ({ }); const setCurrentModal = useCallback( - (modalName: string | null): void => { + (modalName: ViewerModalName): void => { dispatch({ type: 'updateModalOpen', modalName, @@ -259,7 +259,7 @@ const ExceptionsViewerComponent = ({ /> )} - {currentModal === 'addModal' && exceptionListTypeToEdit !== null && ( + {currentModal === 'addModal' && exceptionListTypeToEdit != null && (