Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yctercero committed Jun 8, 2020
1 parent aea3b16 commit 854892a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 43 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/lists/public/exceptions/hooks/use_api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
deleteExceptionList: (arg: ApiCallMemoProps) => Promise<void>;
getExceptionItem: (
Expand All @@ -24,7 +24,7 @@ interface ExceptionsApi {

export const useApi = (http: HttpStart): ExceptionsApi => {
return useMemo(
() => ({
(): ExceptionsApi => ({
async deleteExceptionItem({
id,
namespaceType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useExceptionList = ({
lists,
pagination = {
page: 1,
perPage: 5,
perPage: 20,
total: 0,
},
filterOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
EuiEmptyPrompt,
EuiText,
EuiLink,
EuiLoadingContent,
EuiOverlayMask,
EuiModal,
EuiModalBody,
Expand Down Expand Up @@ -71,10 +70,10 @@ const initialState: State = {
},
endpointList: null,
detectionsList: null,
allExceptions: [],
exceptions: [],
exceptionToEdit: null,
loadingItemIds: [],
isLoading: false,
isModalOpen: false,
};

Expand Down Expand Up @@ -118,7 +117,6 @@ const ExceptionsViewerComponent = ({
const { deleteExceptionItem } = useApi(services.http);
const [
{
isLoading,
endpointList,
detectionsList,
exceptions,
Expand Down Expand Up @@ -184,10 +182,9 @@ const ExceptionsViewerComponent = ({
type: 'updateFilterOptions',
filterOptions: filter,
pagination: pag,
ruleExceptionLists: exceptionListsMeta,
});
},
[dispatch, exceptionListsMeta]
[dispatch]
);

const onAddException = useCallback(
Expand All @@ -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
Expand Down Expand Up @@ -257,14 +254,7 @@ const ExceptionsViewerComponent = ({
},
});
},
[
dispatch,
setLoadingItemIds,
deleteExceptionItem,
loadingItemIds,
onFetchList,
onDispatchToaster,
]
[setLoadingItemIds, deleteExceptionItem, loadingItemIds, onFetchList, onDispatchToaster]
);

// Logic for initial render
Expand Down Expand Up @@ -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 (
<>
Expand All @@ -338,10 +328,8 @@ const ExceptionsViewerComponent = ({
</EuiOverlayMask>
)}

<Panel loading={initLoading || isLoading}>
{initLoading && (
<EuiLoadingContent data-test-subj="initialLoadingAllExceptionItemsView" lines={10} />
)}
<Panel loading={initLoading}>
{initLoading && <Loader data-test-subj="loadingPanelAllRulesTable" overlay size="xl" />}

<ExceptionsViewerHeader
isInitLoading={initLoading}
Expand All @@ -352,14 +340,15 @@ const ExceptionsViewerComponent = ({
onAddExceptionClick={onAddException}
/>

<EuiSpacer size="l" />

{(filterOptions.showEndpointList || filterOptions.showDetectionsList) && (
<>
<EuiSpacer size="xs" />
<StyledText size="s">{exceptionsSubtext}</StyledText>
</>
)}

<EuiSpacer size="l" />

<UtilityBar>
<UtilityBarSection>
<UtilityBarGroup>
Expand All @@ -379,8 +368,6 @@ const ExceptionsViewerComponent = ({
<EuiSpacer size="s" />

<MyExceptionsContainer className="eui-yScrollWithShadows">
{isLoading && <Loader data-test-subj="loadingPanelAllRulesTable" overlay size="xl" />}

{showEmpty && (
<EuiEmptyPrompt
iconType="advancedSettingsApp"
Expand All @@ -393,7 +380,6 @@ const ExceptionsViewerComponent = ({

<EuiFlexGroup direction="column" className="eui-yScrollWithShadows">
{!initLoading &&
!isLoading &&
exceptions.length > 0 &&
exceptions.map((exception, index) => (
<EuiFlexItem grow={false} key={exception.id}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -35,7 +35,6 @@ export type Action =
type: 'updateFilterOptions';
filterOptions: Partial<FilterOptions>;
pagination: Partial<Pagination>;
ruleExceptionLists: ExceptionIdentifiers[];
}
| { type: 'updateModalOpen'; isOpen: boolean }
| { type: 'updateExceptionToEdit'; exception: ExceptionListItemSchema }
Expand All @@ -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': {
Expand All @@ -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,
Expand All @@ -96,6 +94,7 @@ export const allExceptionItemsReducer = () => (state: State, action: Action): St
} else {
return {
...returnState,
exceptions: state.allExceptions,
};
}
}
Expand Down

0 comments on commit 854892a

Please sign in to comment.