From 854892a7af871ae59ca6c67f6d1f52e06bb26987 Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Mon, 8 Jun 2020 17:15:33 -0400 Subject: [PATCH] cleanup --- .../lists/public/exceptions/hooks/use_api.tsx | 4 +-- .../exceptions/hooks/use_exception_list.tsx | 2 +- .../components/exceptions/translations.ts | 2 +- .../viewer/exceptions_viewer_header.tsx | 2 +- .../components/exceptions/viewer/index.tsx | 36 ++++++------------- .../components/exceptions/viewer/reducer.ts | 25 +++++++------ 6 files changed, 28 insertions(+), 43 deletions(-) diff --git a/x-pack/plugins/lists/public/exceptions/hooks/use_api.tsx b/x-pack/plugins/lists/public/exceptions/hooks/use_api.tsx index dec00747c9e918..45e180d9d617c6 100644 --- a/x-pack/plugins/lists/public/exceptions/hooks/use_api.tsx +++ b/x-pack/plugins/lists/public/exceptions/hooks/use_api.tsx @@ -11,7 +11,7 @@ import { HttpStart } from '../../../../../../src/core/public'; import { ExceptionListItemSchema, ExceptionListSchema } from '../../../common/schemas'; import { ApiCallMemoProps } from '../types'; -interface ExceptionsApi { +export interface ExceptionsApi { deleteExceptionItem: (arg: ApiCallMemoProps) => Promise; deleteExceptionList: (arg: ApiCallMemoProps) => Promise; getExceptionItem: ( @@ -24,7 +24,7 @@ interface ExceptionsApi { export const useApi = (http: HttpStart): ExceptionsApi => { return useMemo( - () => ({ + (): ExceptionsApi => ({ async deleteExceptionItem({ id, namespaceType, diff --git a/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.tsx b/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.tsx index 9d80dd367efc14..c26d556fe8f258 100644 --- a/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.tsx +++ b/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.tsx @@ -35,7 +35,7 @@ export const useExceptionList = ({ lists, pagination = { page: 1, - perPage: 5, + perPage: 20, total: 0, }, filterOptions = { diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/translations.ts b/x-pack/plugins/security_solution/public/common/components/exceptions/translations.ts index 4e6092af3882b9..23e9f64caf695a 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/translations.ts +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/translations.ts @@ -62,7 +62,7 @@ export const OPERATING_SYSTEM = i18n.translate( export const SEARCH_DEFAULT = i18n.translate( 'xpack.securitySolution.exceptions.viewer.searchDefaultPlaceholder', { - defaultMessage: 'Search field (default)', + defaultMessage: 'Search field (ex: host.name)', } ); diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_header.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_header.tsx index a819539fc5d94d..92a8830310b516 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_header.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_header.tsx @@ -51,7 +51,7 @@ const ExceptionsViewerHeaderComponent = ({ filter: { filter, showDetectionsList, showEndpointList, tags }, pagination: {}, }); - }, [filter, tags, showDetectionsList, showEndpointList]); + }, [filter, tags, showDetectionsList, showEndpointList, onFilterChange]); const onAddExceptionDropdownClick = useCallback( (): void => setAddExceptionMenuOpen(!isAddExceptionMenuOpen), 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 9ae694b49a936d..31cff134d2dc4b 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 @@ -9,7 +9,6 @@ import { EuiEmptyPrompt, EuiText, EuiLink, - EuiLoadingContent, EuiOverlayMask, EuiModal, EuiModalBody, @@ -71,10 +70,10 @@ const initialState: State = { }, endpointList: null, detectionsList: null, + allExceptions: [], exceptions: [], exceptionToEdit: null, loadingItemIds: [], - isLoading: false, isModalOpen: false, }; @@ -118,7 +117,6 @@ const ExceptionsViewerComponent = ({ const { deleteExceptionItem } = useApi(services.http); const [ { - isLoading, endpointList, detectionsList, exceptions, @@ -184,10 +182,9 @@ const ExceptionsViewerComponent = ({ type: 'updateFilterOptions', filterOptions: filter, pagination: pag, - ruleExceptionLists: exceptionListsMeta, }); }, - [dispatch, exceptionListsMeta] + [dispatch] ); const onAddException = useCallback( @@ -212,7 +209,7 @@ const ExceptionsViewerComponent = ({ ); const onCloseExceptionModal = useCallback( - ({ actionType, listId, listNamespaceType }): void => { + ({ actionType, listId }): void => { setIsModalOpen(false); // TODO: This callback along with fetchList can probably get @@ -257,14 +254,7 @@ const ExceptionsViewerComponent = ({ }, }); }, - [ - dispatch, - setLoadingItemIds, - deleteExceptionItem, - loadingItemIds, - onFetchList, - onDispatchToaster, - ] + [setLoadingItemIds, deleteExceptionItem, loadingItemIds, onFetchList, onDispatchToaster] ); // Logic for initial render @@ -321,8 +311,8 @@ const ExceptionsViewerComponent = ({ }, [filterOptions.showEndpointList, filterOptions.showDetectionsList, ruleSettingsUrl]); const showEmpty = useMemo((): boolean => { - return !initLoading && !isLoading && exceptions.length === 0; - }, [initLoading, exceptions.length, isLoading]); + return !initLoading && exceptions.length === 0; + }, [initLoading, exceptions.length]); return ( <> @@ -338,10 +328,8 @@ const ExceptionsViewerComponent = ({ )} - - {initLoading && ( - - )} + + {initLoading && } - - {(filterOptions.showEndpointList || filterOptions.showDetectionsList) && ( <> + {exceptionsSubtext} )} + + @@ -379,8 +368,6 @@ const ExceptionsViewerComponent = ({ - {isLoading && } - {showEmpty && ( {!initLoading && - !isLoading && exceptions.length > 0 && exceptions.map((exception, index) => ( diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts index 142f750f383fca..121a33741534cd 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts @@ -10,18 +10,18 @@ import { ExceptionListItemSchema, Pagination, } from '../types'; -import { ExceptionList, ExceptionIdentifiers } from '../../../../../public/lists_plugin_deps'; +import { ExceptionList } from '../../../../../public/lists_plugin_deps'; export interface State { filterOptions: FilterOptions; pagination: ExceptionsPagination; endpointList: ExceptionList | null; detectionsList: ExceptionList | null; + allExceptions: ExceptionListItemSchema[]; exceptions: ExceptionListItemSchema[]; exceptionToEdit: ExceptionListItemSchema | null; loadingItemIds: ApiProps[]; isModalOpen: boolean; - isLoading: boolean; } export type Action = @@ -35,7 +35,6 @@ export type Action = type: 'updateFilterOptions'; filterOptions: Partial; pagination: Partial; - ruleExceptionLists: ExceptionIdentifiers[]; } | { type: 'updateModalOpen'; isOpen: boolean } | { type: 'updateExceptionToEdit'; exception: ExceptionListItemSchema } @@ -49,20 +48,20 @@ export const allExceptionItemsReducer = () => (state: State, action: Action): St return { ...state, - endpointList: state.filterOptions.showEndpointList - ? endpointList[0] ?? null - : state.endpointList, - detectionsList: state.filterOptions.showDetectionsList - ? detectionsList[0] ?? null - : state.detectionsList, + endpointList: state.filterOptions.showDetectionsList + ? state.endpointList + : endpointList[0] ?? null, + detectionsList: state.filterOptions.showEndpointList + ? state.detectionsList + : detectionsList[0] ?? null, pagination: { ...state.pagination, pageIndex: action.pagination.page - 1, pageSize: action.pagination.perPage, totalItemCount: action.pagination.total, }, + allExceptions: action.exceptions, exceptions: action.exceptions, - isLoading: false, }; } case 'updateFilterOptions': { @@ -76,18 +75,17 @@ export const allExceptionItemsReducer = () => (state: State, action: Action): St ...state.pagination, ...action.pagination, }, - isLoading: true, }; if (action.filterOptions.showEndpointList) { - const exceptions = state.exceptions.filter((t) => t.type === 'endpoint'); + const exceptions = state.allExceptions.filter((t) => t._tags.includes('endpoint')); return { ...returnState, exceptions, }; } else if (action.filterOptions.showDetectionsList) { - const exceptions = state.exceptions.filter((t) => t.type === 'detection'); + const exceptions = state.allExceptions.filter((t) => t._tags.includes('detection')); return { ...returnState, @@ -96,6 +94,7 @@ export const allExceptionItemsReducer = () => (state: State, action: Action): St } else { return { ...returnState, + exceptions: state.allExceptions, }; } }