Skip to content

Commit 11470ac

Browse files
authored
[Security Solution][Case] Manual attach alert to a case (#82996)
1 parent 4b4419a commit 11470ac

File tree

26 files changed

+536
-415
lines changed

26 files changed

+536
-415
lines changed

x-pack/plugins/security_solution/public/cases/components/add_comment/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('AddComment ', () => {
7777

7878
await waitFor(() => {
7979
expect(onCommentSaving).toBeCalled();
80-
expect(postComment).toBeCalledWith(sampleData, onCommentPosted);
80+
expect(postComment).toBeCalledWith(addCommentProps.caseId, sampleData, onCommentPosted);
8181
expect(wrapper.find(`[data-test-subj="add-comment"] textarea`).text()).toBe('');
8282
});
8383
});

x-pack/plugins/security_solution/public/cases/components/add_comment/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface AddCommentProps {
4343
export const AddComment = React.memo(
4444
forwardRef<AddCommentRefObject, AddCommentProps>(
4545
({ caseId, disabled, showLoading = true, onCommentPosted, onCommentSaving }, ref) => {
46-
const { isLoading, postComment } = usePostComment(caseId);
46+
const { isLoading, postComment } = usePostComment();
4747

4848
const { form } = useForm<AddCommentFormSchema>({
4949
defaultValue: initialCommentValue,
@@ -79,10 +79,10 @@ export const AddComment = React.memo(
7979
if (onCommentSaving != null) {
8080
onCommentSaving();
8181
}
82-
postComment({ ...data, type: CommentType.user }, onCommentPosted);
82+
postComment(caseId, { ...data, type: CommentType.user }, onCommentPosted);
8383
reset();
8484
}
85-
}, [onCommentPosted, onCommentSaving, postComment, reset, submit]);
85+
}, [onCommentPosted, onCommentSaving, postComment, reset, submit, caseId]);
8686

8787
return (
8888
<span id="add-comment-permLink">

x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,44 @@ describe('AllCases', () => {
437437
);
438438
await waitFor(() => {
439439
wrapper.find('[data-test-subj="cases-table-row-1"]').first().simulate('click');
440-
expect(onRowClick).toHaveBeenCalledWith('1');
440+
expect(onRowClick).toHaveBeenCalledWith({
441+
closedAt: null,
442+
closedBy: null,
443+
comments: [],
444+
connector: { fields: null, id: '123', name: 'My Connector', type: '.none' },
445+
createdAt: '2020-02-19T23:06:33.798Z',
446+
createdBy: {
447+
email: 'leslie.knope@elastic.co',
448+
fullName: 'Leslie Knope',
449+
username: 'lknope',
450+
},
451+
description: 'Security banana Issue',
452+
externalService: {
453+
connectorId: '123',
454+
connectorName: 'connector name',
455+
externalId: 'external_id',
456+
externalTitle: 'external title',
457+
externalUrl: 'basicPush.com',
458+
pushedAt: '2020-02-20T15:02:57.995Z',
459+
pushedBy: {
460+
email: 'leslie.knope@elastic.co',
461+
fullName: 'Leslie Knope',
462+
username: 'lknope',
463+
},
464+
},
465+
id: '1',
466+
status: 'open',
467+
tags: ['coke', 'pepsi'],
468+
title: 'Another horrible breach!!',
469+
totalComment: 0,
470+
updatedAt: '2020-02-20T15:02:57.995Z',
471+
updatedBy: {
472+
email: 'leslie.knope@elastic.co',
473+
fullName: 'Leslie Knope',
474+
username: 'lknope',
475+
},
476+
version: 'WzQ3LDFd',
477+
});
441478
});
442479
});
443480

x-pack/plugins/security_solution/public/cases/components/all_cases/index.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const getSortField = (field: string): SortFieldCase => {
8282
};
8383

8484
interface AllCasesProps {
85-
onRowClick?: (id?: string) => void;
85+
onRowClick?: (theCase?: Case) => void;
8686
isModal?: boolean;
8787
userCanCrud: boolean;
8888
}
@@ -339,32 +339,20 @@ export const AllCases = React.memo<AllCasesProps>(
339339

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

342-
const onTableRowClick = useMemo(
343-
() =>
344-
memoize<(id: string) => () => void>((id) => () => {
342+
const tableRowProps = useCallback(
343+
(theCase: Case) => {
344+
const onTableRowClick = memoize(() => {
345345
if (onRowClick) {
346-
onRowClick(id);
346+
onRowClick(theCase);
347347
}
348-
}),
349-
[onRowClick]
350-
);
348+
});
351349

352-
const tableRowProps = useCallback(
353-
(item) => {
354-
const rowProps = {
355-
'data-test-subj': `cases-table-row-${item.id}`,
350+
return {
351+
'data-test-subj': `cases-table-row-${theCase.id}`,
352+
...(isModal ? { onClick: onTableRowClick } : {}),
356353
};
357-
358-
if (isModal) {
359-
return {
360-
...rowProps,
361-
onClick: onTableRowClick(item.id),
362-
};
363-
}
364-
365-
return rowProps;
366354
},
367-
[isModal, onTableRowClick]
355+
[isModal, onRowClick]
368356
);
369357

370358
return (

x-pack/plugins/security_solution/public/cases/components/all_cases_modal/index.test.tsx

Lines changed: 0 additions & 153 deletions
This file was deleted.

x-pack/plugins/security_solution/public/cases/components/all_cases_modal/index.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

x-pack/plugins/security_solution/public/cases/components/all_cases_modal/translations.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

x-pack/plugins/security_solution/public/cases/components/connectors/case/existing_case.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({ onCaseChanged, sel
1919

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

22-
const { Modal: CreateCaseModal, openModal } = useCreateCaseModal({ onCaseCreated });
22+
const { modal, openModal } = useCreateCaseModal({ onCaseCreated });
2323

2424
const onChange = useCallback(
2525
(id: string) => {
@@ -46,7 +46,7 @@ const ExistingCaseComponent: React.FC<ExistingCaseProps> = ({ onCaseChanged, sel
4646
selectedCase={selectedCase ?? undefined}
4747
onCaseChanged={onChange}
4848
/>
49-
<CreateCaseModal />
49+
{modal}
5050
</>
5151
);
5252
};

0 commit comments

Comments
 (0)