Skip to content

Commit

Permalink
[Security Solution][Case] Manual attach alert to a case (#82996)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas authored Dec 8, 2020
1 parent 4b4419a commit 11470ac
Show file tree
Hide file tree
Showing 26 changed files with 536 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('AddComment ', () => {

await waitFor(() => {
expect(onCommentSaving).toBeCalled();
expect(postComment).toBeCalledWith(sampleData, onCommentPosted);
expect(postComment).toBeCalledWith(addCommentProps.caseId, sampleData, onCommentPosted);
expect(wrapper.find(`[data-test-subj="add-comment"] textarea`).text()).toBe('');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface AddCommentProps {
export const AddComment = React.memo(
forwardRef<AddCommentRefObject, AddCommentProps>(
({ caseId, disabled, showLoading = true, onCommentPosted, onCommentSaving }, ref) => {
const { isLoading, postComment } = usePostComment(caseId);
const { isLoading, postComment } = usePostComment();

const { form } = useForm<AddCommentFormSchema>({
defaultValue: initialCommentValue,
Expand Down Expand Up @@ -79,10 +79,10 @@ export const AddComment = React.memo(
if (onCommentSaving != null) {
onCommentSaving();
}
postComment({ ...data, type: CommentType.user }, onCommentPosted);
postComment(caseId, { ...data, type: CommentType.user }, onCommentPosted);
reset();
}
}, [onCommentPosted, onCommentSaving, postComment, reset, submit]);
}, [onCommentPosted, onCommentSaving, postComment, reset, submit, caseId]);

return (
<span id="add-comment-permLink">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,44 @@ describe('AllCases', () => {
);
await waitFor(() => {
wrapper.find('[data-test-subj="cases-table-row-1"]').first().simulate('click');
expect(onRowClick).toHaveBeenCalledWith('1');
expect(onRowClick).toHaveBeenCalledWith({
closedAt: null,
closedBy: null,
comments: [],
connector: { fields: null, id: '123', name: 'My Connector', type: '.none' },
createdAt: '2020-02-19T23:06:33.798Z',
createdBy: {
email: 'leslie.knope@elastic.co',
fullName: 'Leslie Knope',
username: 'lknope',
},
description: 'Security banana Issue',
externalService: {
connectorId: '123',
connectorName: 'connector name',
externalId: 'external_id',
externalTitle: 'external title',
externalUrl: 'basicPush.com',
pushedAt: '2020-02-20T15:02:57.995Z',
pushedBy: {
email: 'leslie.knope@elastic.co',
fullName: 'Leslie Knope',
username: 'lknope',
},
},
id: '1',
status: 'open',
tags: ['coke', 'pepsi'],
title: 'Another horrible breach!!',
totalComment: 0,
updatedAt: '2020-02-20T15:02:57.995Z',
updatedBy: {
email: 'leslie.knope@elastic.co',
fullName: 'Leslie Knope',
username: 'lknope',
},
version: 'WzQ3LDFd',
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const getSortField = (field: string): SortFieldCase => {
};

interface AllCasesProps {
onRowClick?: (id?: string) => void;
onRowClick?: (theCase?: Case) => void;
isModal?: boolean;
userCanCrud: boolean;
}
Expand Down Expand Up @@ -339,32 +339,20 @@ export const AllCases = React.memo<AllCasesProps>(

const TableWrap = useMemo(() => (isModal ? 'span' : Panel), [isModal]);

const onTableRowClick = useMemo(
() =>
memoize<(id: string) => () => void>((id) => () => {
const tableRowProps = useCallback(
(theCase: Case) => {
const onTableRowClick = memoize(() => {
if (onRowClick) {
onRowClick(id);
onRowClick(theCase);
}
}),
[onRowClick]
);
});

const tableRowProps = useCallback(
(item) => {
const rowProps = {
'data-test-subj': `cases-table-row-${item.id}`,
return {
'data-test-subj': `cases-table-row-${theCase.id}`,
...(isModal ? { onClick: onTableRowClick } : {}),
};

if (isModal) {
return {
...rowProps,
onClick: onTableRowClick(item.id),
};
}

return rowProps;
},
[isModal, onTableRowClick]
[isModal, onRowClick]
);

return (
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({ onCaseChanged, sel

const onCaseCreated = useCallback(() => refetchCases(), [refetchCases]);

const { Modal: CreateCaseModal, openModal } = useCreateCaseModal({ onCaseCreated });
const { modal, openModal } = useCreateCaseModal({ onCaseCreated });

const onChange = useCallback(
(id: string) => {
Expand All @@ -46,7 +46,7 @@ const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({ onCaseChanged, sel
selectedCase={selectedCase ?? undefined}
onCaseChanged={onChange}
/>
<CreateCaseModal />
{modal}
</>
);
};
Expand Down
Loading

0 comments on commit 11470ac

Please sign in to comment.