Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
peluja1012 committed Jul 6, 2020
1 parent 08a2f68 commit 169cd10
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
const [showClearSelectionAction, setShowClearSelectionAction] = useState(false);
const [filterGroup, setFilterGroup] = useState<Status>(FILTER_OPEN);
const [shouldShowAddExceptionModal, setShouldShowAddExceptionModal] = useState(false);
const [addExceptionModalState, setAddExceptionModalState] = useState(
const [addExceptionModalState, setAddExceptionModalState] = useState<AddExceptionOnClick>(
addExceptionModalInitialState
);
const [{ browserFields, indexPatterns }] = useFetchIndexPatterns(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface UseFetchOrCreateRuleExceptionListProps {
ruleId: Rule['id'];
exceptionListType: ExceptionListSchema['type'];
onError: (arg: Error) => void;
onSuccess?: (arg: ExceptionListSchema) => void;
}

/**
Expand All @@ -33,15 +32,13 @@ 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 = ({
http,
ruleId,
exceptionListType,
onError,
onSuccess,
}: UseFetchOrCreateRuleExceptionListProps): ReturnUseFetchOrCreateRuleExceptionList => {
const [isLoading, setIsLoading] = useState(false);
const [exceptionList, setExceptionList] = useState<ExceptionListSchema | null>(null);
Expand Down Expand Up @@ -77,17 +74,14 @@ export const useFetchOrCreateRuleExceptionList = ({
): Promise<ExceptionListSchema> {
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: {
Expand Down Expand Up @@ -149,9 +143,6 @@ export const useFetchOrCreateRuleExceptionList = ({
if (isSubscribed) {
setExceptionList(exceptionListToUse);
setIsLoading(false);
if (onSuccess !== undefined) {
onSuccess(exceptionListToUse);
}
}
} catch (error) {
if (isSubscribed) {
Expand All @@ -167,7 +158,7 @@ export const useFetchOrCreateRuleExceptionList = ({
isSubscribed = false;
abortCtrl.abort();
};
}, [http, ruleId, exceptionListType, onSuccess, onError]);
}, [http, ruleId, exceptionListType, onError]);

return [isLoading, exceptionList];
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -131,7 +131,7 @@ const ExceptionsViewerComponent = ({
});

const setCurrentModal = useCallback(
(modalName: string | null): void => {
(modalName: ViewerModalName): void => {
dispatch({
type: 'updateModalOpen',
modalName,
Expand Down Expand Up @@ -259,7 +259,7 @@ const ExceptionsViewerComponent = ({
/>
)}

{currentModal === 'addModal' && exceptionListTypeToEdit !== null && (
{currentModal === 'addModal' && exceptionListTypeToEdit != null && (
<AddExceptionModal
ruleName={ruleName}
ruleId={ruleId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
Pagination,
} from '../../../../../public/lists_plugin_deps';

export type ViewerModalName = 'addModal' | 'editModal' | null;

export interface State {
filterOptions: FilterOptions;
pagination: ExceptionsPagination;
Expand All @@ -23,7 +25,7 @@ export interface State {
loadingLists: ExceptionIdentifiers[];
loadingItemIds: ExceptionIdentifiers[];
isInitLoading: boolean;
currentModal: string | null;
currentModal: ViewerModalName;
exceptionListTypeToEdit: ExceptionListType | null;
}

Expand All @@ -41,7 +43,7 @@ export type Action =
allLists: ExceptionIdentifiers[];
}
| { type: 'updateIsInitLoading'; loading: boolean }
| { type: 'updateModalOpen'; modalName: string | null }
| { type: 'updateModalOpen'; modalName: ViewerModalName }
| { type: 'updateExceptionToEdit'; exception: ExceptionListItemSchema }
| { type: 'updateLoadingItemIds'; items: ExceptionIdentifiers[] }
| { type: 'updateExceptionListTypeToEdit'; exceptionListType: ExceptionListType | null };
Expand Down

0 comments on commit 169cd10

Please sign in to comment.