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] [Cases] Cases UI Plugin for RAC #97646

Merged
merged 87 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
756e5a5
init simple case ui plugin
michaelolo24 Mar 9, 2021
59756e8
remove hello world piece
michaelolo24 Mar 9, 2021
2b816e8
rename case to cases
michaelolo24 Mar 10, 2021
ebc609b
Merge 2b816e8c9e833ca2e2a361b29bc62861879982aa into 81da4f79e122b7c1b…
michaelolo24 Mar 10, 2021
d5cbcd1
move create
stephmilovic Mar 10, 2021
841659b
clearing type errs
stephmilovic Mar 10, 2021
ead2da0
clearing type errs
stephmilovic Mar 10, 2021
7a32042
resolve issue w exports
stephmilovic Mar 10, 2021
359e8d1
its working
stephmilovic Mar 11, 2021
83f6517
we are so good at this
stephmilovic Mar 11, 2021
3ab3352
add mock
stephmilovic Mar 11, 2021
51f6f4d
fixed components tests
stephmilovic Mar 11, 2021
8f1e82d
flip USE_RAC_CASES_UI to false
stephmilovic Mar 11, 2021
4763023
fix container tests
michaelolo24 Mar 11, 2021
249383f
Merge branch 'cases_moving_create' of https://github.com/stephmilovic…
michaelolo24 Mar 11, 2021
8f3424b
rm some comments
stephmilovic Mar 11, 2021
c1098f8
Merge branch 'cases_moving_create' of github.com:stephmilovic/kibana …
stephmilovic Mar 11, 2021
7d76248
Merge branch 'master' into cases_moving_create
kibanamachine Mar 11, 2021
4ff74fb
fix more imports
stephmilovic Mar 11, 2021
87a1cde
Merge branch 'cases_moving_create' of github.com:stephmilovic/kibana …
stephmilovic Mar 11, 2021
84714f9
fix more imports
stephmilovic Mar 13, 2021
5f5021d
fix mistake
stephmilovic Mar 13, 2021
731039a
add cases to kbn-optimizer/limits.yml
stephmilovic Mar 14, 2021
debbcb0
Fix i18n
stephmilovic Mar 14, 2021
53e1ba9
Merge branch 'master' into cases_moving_create
stephmilovic Mar 14, 2021
907bfc1
pr changes
stephmilovic Mar 16, 2021
4f941e1
master merge
stephmilovic Mar 16, 2021
82cd096
fix type and test
stephmilovic Mar 16, 2021
1cb3917
fix a gosh darn silly type
stephmilovic Mar 16, 2021
6d04fb3
one more Security remove
stephmilovic Mar 16, 2021
46a801e
add prop for afterCaseCreated to make christos happiest boy in greece
stephmilovic Mar 16, 2021
54ca62d
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 22, 2021
6b87eb0
[Security Solution][Cases] - Migrate all cases page (#94992)
michaelolo24 Mar 22, 2021
0d28c5a
[DOCS] Adds docs for search sessions (#94661)
gchaps Mar 22, 2021
9ad1b49
[SECURITY_SOLUTION] Adds hash validation on UI for trusted app (#94958)
dasansol92 Mar 22, 2021
2e3f333
[uiSettings/theme] restrict theme options based on KBN_OPTIMIZER_THEM…
Mar 22, 2021
23cf913
[dashboard/bwc_shared_urls] check viz are loaded (#94941)
dmlemeshko Mar 22, 2021
f26b10c
[Security Solution] [Cases] Add deprecation in cases plugin for renam…
stephmilovic Mar 22, 2021
c3490d2
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 22, 2021
2c44d56
[Security Solution] [Cases] Move configure cases component (#95096)
stephmilovic Mar 22, 2021
bac342f
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 23, 2021
d91bdf2
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 23, 2021
026c31c
[Security Solutions] [Cases] Update readme and add jsdocs to public m…
stephmilovic Mar 25, 2021
47338bd
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 25, 2021
0187d83
trying to merge master
stephmilovic Mar 26, 2021
191c58e
hoorah, fixed w master
stephmilovic Mar 26, 2021
8826419
Merge branch 'master' into cases_rac_ui
michaelolo24 Mar 29, 2021
d8e4708
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 29, 2021
439d2e1
[Security Solution][Cases] Migrate case_details to cases plugin (#95086)
michaelolo24 Mar 29, 2021
cdd1b68
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 30, 2021
ab5c6ee
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 31, 2021
442c57c
Merge branch 'master' into cases_rac_ui
stephmilovic Mar 31, 2021
bbabf7b
merge masteR
stephmilovic Apr 1, 2021
e0616b7
[Security Solution] [Cases] Deleting files from security solution and…
stephmilovic Apr 1, 2021
bc59d53
rm bazel dir
stephmilovic Apr 2, 2021
8ba55b5
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 5, 2021
369e252
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 6, 2021
39f4844
[Security Solution] Tsconfig for cases (#96249)
stephmilovic Apr 7, 2021
634b541
merge master
stephmilovic Apr 7, 2021
faee413
rm jsdom thirteen
stephmilovic Apr 7, 2021
ece4185
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 8, 2021
71a1b49
Merge branch 'master' into cases_rac_ui
michaelolo24 Apr 12, 2021
f2132d6
Merge branch 'master' into cases_rac_ui
michaelolo24 Apr 12, 2021
f1509f2
Merge branch 'master' into cases_rac_ui
michaelolo24 Apr 12, 2021
d2eaf3b
[Security Solution][Cases] - Update navigation props (#96493)
michaelolo24 Apr 13, 2021
47b4a0f
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 13, 2021
636524a
[Security Solution][Cases] Re-enable timeline functionality (#96496)
michaelolo24 Apr 13, 2021
85244ef
[Security Solution][Cases] Fix cases breadcrumbs (#97040)
michaelolo24 Apr 14, 2021
d7830be
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 14, 2021
76ae331
merge conflicts
stephmilovic Apr 20, 2021
fd7f810
fix bad push
stephmilovic Apr 20, 2021
89721fa
fix type err
stephmilovic Apr 20, 2021
64e35a1
Merge branch 'master' into cases_rac_ui
kibanamachine Apr 21, 2021
54c97d4
[Security Solution] [Cases] All Cases Refactor & getAllCasesSelectorM…
stephmilovic Apr 21, 2021
4d9bf46
readme changes
stephmilovic Apr 22, 2021
b9cdc2e
fix merge
stephmilovic Apr 22, 2021
05aceaa
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 23, 2021
6cc459b
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 26, 2021
4b85082
pr changes 1
stephmilovic Apr 26, 2021
870610c
ok undo
stephmilovic Apr 26, 2021
cc21d3a
[Security Solution] [Cases] Polishing up the jest tests in cases ui p…
stephmilovic Apr 26, 2021
b5d3932
fix double api calls
stephmilovic Apr 26, 2021
abf8cd9
Merge branch 'cases_rac_ui' of github.com:elastic/kibana into cases_r…
stephmilovic Apr 26, 2021
f5fa7f1
fix infinite loop, improve breadcrumb
michaelolo24 Apr 26, 2021
df7097e
fix attach alert to new case
michaelolo24 Apr 28, 2021
54d9730
Merge branch 'master' into cases_rac_ui
stephmilovic Apr 28, 2021
e0e4bee
rid of unnecessary log
stephmilovic Apr 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
import { ConnectorTypes } from '../../../common';
import { TestProviders } from '../../common/mock';
import { usePostCase } from '../../containers/use_post_case';
import { usePostComment } from '../../containers/use_post_comment';
import { useGetTags } from '../../containers/use_get_tags';
import { useConnectors } from '../../containers/configure/use_connectors';
import { useCaseConfigure } from '../../containers/configure/use_configure';
Expand Down Expand Up @@ -41,6 +42,7 @@ import { usePostPushToService } from '../../containers/use_post_push_to_service'
const sampleId = 'case-id';

jest.mock('../../containers/use_post_case');
jest.mock('../../containers/use_post_comment');
jest.mock('../../containers/use_post_push_to_service');
jest.mock('../../containers/use_get_tags');
jest.mock('../../containers/configure/use_connectors');
Expand All @@ -56,6 +58,7 @@ jest.mock('../connectors/servicenow/use_get_choices');
const useConnectorsMock = useConnectors as jest.Mock;
const useCaseConfigureMock = useCaseConfigure as jest.Mock;
const usePostCaseMock = usePostCase as jest.Mock;
const usePostCommentMock = usePostComment as jest.Mock;
const usePostPushToServiceMock = usePostPushToService as jest.Mock;
const useGetIncidentTypesMock = useGetIncidentTypes as jest.Mock;
const useGetSeverityMock = useGetSeverity as jest.Mock;
Expand Down Expand Up @@ -104,13 +107,15 @@ describe('Create case', () => {
const fetchTags = jest.fn();
const onFormSubmitSuccess = jest.fn();
const afterCaseCreated = jest.fn();
const postComment = jest.fn();

beforeAll(() => {
postCase.mockResolvedValue({
id: sampleId,
...sampleData,
});
usePostCaseMock.mockImplementation(() => defaultPostCase);
usePostCommentMock.mockImplementation(() => ({ postComment }));
usePostPushToServiceMock.mockImplementation(() => defaultPostPushToService);
useConnectorsMock.mockReturnValue(sampleConnectorData);
useCaseConfigureMock.mockImplementation(() => useCaseConfigureResponse);
Expand Down Expand Up @@ -629,10 +634,13 @@ describe('Create case', () => {

wrapper.find(`[data-test-subj="create-case-submit"]`).first().simulate('click');
await waitFor(() => {
expect(afterCaseCreated).toHaveBeenCalledWith({
id: sampleId,
...sampleData,
});
expect(afterCaseCreated).toHaveBeenCalledWith(
{
id: sampleId,
...sampleData,
},
postComment
);
});
});

Expand Down
16 changes: 13 additions & 3 deletions x-pack/plugins/cases/public/components/create/form_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useConnectors } from '../../containers/configure/use_connectors';
import { useCaseConfigure } from '../../containers/configure/use_configure';
import { Case } from '../../containers/types';
import { CaseType, ConnectorTypes } from '../../../common';
import { UsePostComment, usePostComment } from '../../containers/use_post_comment';

const initialCaseValue: FormProps = {
description: '',
Expand All @@ -31,7 +32,7 @@ const initialCaseValue: FormProps = {
};

interface Props {
afterCaseCreated?: (theCase: Case) => Promise<void>;
afterCaseCreated?: (theCase: Case, postComment: UsePostComment['postComment']) => Promise<void>;
caseType?: CaseType;
children?: JSX.Element | JSX.Element[];
hideConnectorServiceNowSir?: boolean;
Expand All @@ -48,6 +49,7 @@ export const FormContext: React.FC<Props> = ({
const { connectors, loading: isLoadingConnectors } = useConnectors();
const { connector: configurationConnector } = useCaseConfigure();
const { postCase } = usePostCase();
const { postComment } = usePostComment();
const { pushCaseToExternalService } = usePostPushToService();

const connectorId = useMemo(() => {
Expand Down Expand Up @@ -87,7 +89,7 @@ export const FormContext: React.FC<Props> = ({
});

if (afterCaseCreated && updatedCase) {
await afterCaseCreated(updatedCase);
await afterCaseCreated(updatedCase, postComment);
}

if (updatedCase?.id && dataConnectorId !== 'none') {
Expand All @@ -102,7 +104,15 @@ export const FormContext: React.FC<Props> = ({
}
}
},
[caseType, connectors, postCase, onSuccess, pushCaseToExternalService, afterCaseCreated]
[
caseType,
connectors,
postCase,
postComment,
onSuccess,
pushCaseToExternalService,
afterCaseCreated,
]
);

const { form } = useForm<FormProps>({
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/public/components/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CaseType } from '../../../common/api/cases';
import { CasesTimelineIntegration, CasesTimelineIntegrationProvider } from '../timeline_context';
import { fieldName as descriptionFieldName } from './description';
import { InsertTimeline } from '../insert_timeline';
import { UsePostComment } from '../../containers/use_post_comment';

export const CommonUseField = getUseField({ component: Field });

Expand All @@ -29,7 +30,7 @@ const Container = styled.div`
`;

export interface CreateCaseProps {
afterCaseCreated?: (theCase: Case) => Promise<void>;
afterCaseCreated?: (theCase: Case, postComment: UsePostComment['postComment']) => Promise<void>;
caseType?: CaseType;
hideConnectorServiceNowSir?: boolean;
onCancel: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ interface AddToCaseActionProps {
ecsRowData: Ecs;
}

interface PostCommentArg {
caseId: string;
data: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's worth it or not (or if it causes a circular dependency) but we might be able to pull the data type from the case common types:

https://github.com/elastic/kibana/blob/master/x-pack/plugins/cases/common/api/cases/comment.ts#L125

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, was trying to avoid a circular dependency when I tossed this together, but thinking about it more, since cases doesn't depend on Security Solution, it shouldn't be

type: 'alert';
alertId: string | string[];
index: string | string[];
rule: { id: string | null; name: string | null };
};
updateCase?: (newCase: Case) => void;
subCaseId?: string;
}

const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({
ariaLabel = i18n.ACTION_ADD_TO_CASE_ARIA_LABEL,
ecsRowData,
Expand Down Expand Up @@ -80,6 +92,31 @@ const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({
closeControl: closeCaseFlyoutOpen,
} = useControl();

const attachAlertToCase = useCallback(
async (
theCase: Case,
postComment?: (arg: PostCommentArg) => Promise<void>,
updateCase?: (newCase: Case) => void
) => {
closeCaseFlyoutOpen();
if (postComment) {
await postComment({
caseId: theCase.id,
data: {
type: 'alert',
alertId: eventId,
index: eventIndex ?? '',
rule: {
id: rule?.id != null ? rule.id[0] : null,
name: rule?.name != null ? rule.name[0] : null,
},
},
updateCase,
});
}
},
[closeCaseFlyoutOpen, eventId, eventIndex, rule]
);
const onCaseSuccess = useCallback(
async (theCase: Case) => {
closeCaseFlyoutOpen();
Expand Down Expand Up @@ -183,7 +220,11 @@ const AddToCaseActionComponent: React.FC<AddToCaseActionProps> = ({
</EuiPopover>
</ActionIconItem>
{isCreateCaseFlyoutOpen && (
<CreateCaseFlyout onCloseFlyout={closeCaseFlyoutOpen} onSuccess={onCaseSuccess} />
<CreateCaseFlyout
afterCaseCreated={attachAlertToCase}
onCloseFlyout={closeCaseFlyoutOpen}
onSuccess={onCaseSuccess}
/>
)}
{isAllCaseModalOpen &&
cases.getAllCasesSelectorModal({
Expand Down