Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution][Case] Manual attach alert to a case #82996

Merged
merged 17 commits into from
Dec 8, 2020
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();
XavierM marked this conversation as resolved.
Show resolved Hide resolved

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;
XavierM marked this conversation as resolved.
Show resolved Hide resolved
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