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] Move create page components and dependencies to Cases #94444

Merged
merged 31 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 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
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ pageLoadAssetSize:
osquery: 107090
fileUpload: 25664
banners: 17946
cases: 102558
Copy link
Contributor Author

@stephmilovic stephmilovic Mar 14, 2021

Choose a reason for hiding this comment

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

Moving cases out of securitySolution is under a feature flag. while the size of cases goes up,securitySolution will go down once the feature flag is removed and the moved code can be removed from securitySolution.

Copy link
Member

Choose a reason for hiding this comment

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

Ok! Maybe when the flag is removed and cases is ready, we can check if we can optimize the bundle size.

1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export * from './cases';
export * from './connectors';
export * from './helpers';
export * from './runtime_types';
export * from './saved_object';
export * from './user';
3 changes: 1 addition & 2 deletions x-pack/plugins/cases/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* 2.0.
*/

import { DEFAULT_MAX_SIGNALS } from '../../security_solution/common/constants';

const DEFAULT_MAX_SIGNALS = 100;
Copy link
Member

Choose a reason for hiding this comment

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

I think we should put a comment here and in security solution that there is a dependency between the two plugins and if changed in security solution it should change in cases also.

export const APP_ID = 'cases';

/**
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/cases/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './constants';
export * from './api';
5 changes: 3 additions & 2 deletions x-pack/plugins/cases/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"configPath": ["xpack", "cases"],
"id": "cases",
"kibanaVersion": "kibana",
"requiredPlugins": ["actions", "securitySolution"],
"extraPublicDirs": ["common"],
"requiredPlugins": ["actions", "esUiShared", "kibanaReact", "triggersActionsUi"],
"optionalPlugins": [
"spaces",
"security"
],
"server": true,
"ui": false,
"ui": true,
"version": "8.0.0"
}
39 changes: 39 additions & 0 deletions x-pack/plugins/cases/public/common/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { has } from 'lodash/fp';

export interface AppError {
name: string;
message: string;
body: {
message: string;
};
}

export interface KibanaError extends AppError {
body: {
message: string;
statusCode: number;
};
}

export interface SecurityAppError extends AppError {
Copy link
Member

Choose a reason for hiding this comment

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

This should be CasesAppError right?

Copy link
Contributor Author

@stephmilovic stephmilovic Mar 16, 2021

Choose a reason for hiding this comment

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

good call. i just did a search for the word security/siem and got rid of it in my next commit

body: {
message: string;
status_code: number;
};
}

export const isKibanaError = (error: unknown): error is KibanaError =>
has('message', error) && has('body.message', error) && has('body.statusCode', error);

export const isSecurityAppError = (error: unknown): error is SecurityAppError =>
has('message', error) && has('body.message', error) && has('body.status_code', error);

export const isAppError = (error: unknown): error is AppError =>
isKibanaError(error) || isSecurityAppError(error);
30 changes: 30 additions & 0 deletions x-pack/plugins/cases/public/common/lib/kibana/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { notificationServiceMock } from '../../../../../../../../src/core/public/mocks';
import {
createKibanaContextProviderMock,
createStartServicesMock,
createWithKibanaMock,
} from '../kibana_react.mock';

export const KibanaServices = { get: jest.fn(), getKibanaVersion: jest.fn(() => '8.0.0') };
export const useKibana = jest.fn().mockReturnValue({
services: createStartServicesMock(),
});

export const useHttp = jest.fn().mockReturnValue(createStartServicesMock().http);
export const useTimeZone = jest.fn();
export const useDateFormat = jest.fn();
export const useBasePath = jest.fn(() => '/test/base/path');
export const useToasts = jest
.fn()
.mockReturnValue(notificationServiceMock.createStartContract().toasts);
export const useCurrentUser = jest.fn();
export const withKibana = jest.fn(createWithKibanaMock());
export const KibanaContextProvider = jest.fn(createKibanaContextProviderMock());
export const useGetUserSavedObjectPermissions = jest.fn();
9 changes: 9 additions & 0 deletions x-pack/plugins/cases/public/common/lib/kibana/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './kibana_react';
export * from './services';
35 changes: 35 additions & 0 deletions x-pack/plugins/cases/public/common/lib/kibana/kibana_react.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import { RecursivePartial } from '@elastic/eui/src/components/common';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { StartServices } from '../../../types';
import { EuiTheme } from '../../../../../../../src/plugins/kibana_react/common';

export const createStartServicesMock = (): StartServices =>
(coreMock.createStart() as unknown) as StartServices;

export const createWithKibanaMock = () => {
const services = createStartServicesMock();

return (Component: unknown) => (props: unknown) => {
return React.createElement(Component as string, { ...(props as object), kibana: { services } });
};
};

export const createKibanaContextProviderMock = () => {
const services = createStartServicesMock();

return ({ children }: { children: React.ReactNode }) =>
React.createElement(KibanaContextProvider, { services }, children);
};

export const getMockTheme = (partialTheme: RecursivePartial<EuiTheme>): EuiTheme =>
partialTheme as EuiTheme;
16 changes: 16 additions & 0 deletions x-pack/plugins/cases/public/common/lib/kibana/kibana_react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
KibanaContextProvider,
useKibana,
} from '../../../../../../../src/plugins/kibana_react/public';
import { StartServices } from '../../../types';

const useTypedKibana = () => useKibana<StartServices>();

export { KibanaContextProvider, useTypedKibana as useKibana };
42 changes: 42 additions & 0 deletions x-pack/plugins/cases/public/common/lib/kibana/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CoreStart } from 'kibana/public';

type GlobalServices = Pick<CoreStart, 'http'>;

export class KibanaServices {
private static kibanaVersion?: string;
private static services?: GlobalServices;

public static init({ http, kibanaVersion }: GlobalServices & { kibanaVersion: string }) {
this.services = { http };
this.kibanaVersion = kibanaVersion;
}

public static get(): GlobalServices {
if (!this.services) {
this.throwUninitializedError();
}

return this.services;
}

public static getKibanaVersion(): string {
if (!this.kibanaVersion) {
this.throwUninitializedError();
}

return this.kibanaVersion;
}

private static throwUninitializedError(): never {
throw new Error(
'Kibana services not initialized - are you trying to import this module from outside of the SIEM app?'
Copy link
Member

Choose a reason for hiding this comment

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

nit: SIEM -> Cases

);
}
}
8 changes: 8 additions & 0 deletions x-pack/plugins/cases/public/common/mock/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './test_providers';
23 changes: 23 additions & 0 deletions x-pack/plugins/cases/public/common/mock/kibana_react.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { CoreStart } from 'kibana/public';
import { coreMock } from '../../../../../../src/core/public/mocks';
import React from 'react';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public/context';

export const createStartServicesMock = (): CoreStart => {
const core = coreMock.createStart();
return (core as unknown) as CoreStart;
};
export const createKibanaContextProviderMock = () => {
const services = coreMock.createStart();

return ({ children }: { children: React.ReactNode }) =>
React.createElement(KibanaContextProvider, { services }, children);
};
58 changes: 58 additions & 0 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
import { I18nProvider } from '@kbn/i18n/react';
import React from 'react';
import { BehaviorSubject } from 'rxjs';
import { ThemeProvider } from 'styled-components';
import { createKibanaContextProviderMock, createStartServicesMock } from './kibana_react.mock';
import { FieldHook } from '../shared_imports';

interface Props {
children: React.ReactNode;
}

export const kibanaObservable = new BehaviorSubject(createStartServicesMock());

window.scrollTo = jest.fn();
const MockKibanaContextProvider = createKibanaContextProviderMock();

/** A utility for wrapping children in the providers required to run most tests */
const TestProvidersComponent: React.FC<Props> = ({ children }) => (
<I18nProvider>
<MockKibanaContextProvider>
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>{children}</ThemeProvider>
</MockKibanaContextProvider>
</I18nProvider>
);

export const TestProviders = React.memo(TestProvidersComponent);

export const useFormFieldMock = <T,>(options?: Partial<FieldHook<T>>): FieldHook<T> => {
return {
path: 'path',
type: 'type',
value: ('mockedValue' as unknown) as T,
isPristine: false,
isValidating: false,
isValidated: false,
isChangingValue: false,
errors: [],
isValid: true,
getErrorsMessages: jest.fn(),
onChange: jest.fn(),
setValue: jest.fn(),
setErrors: jest.fn(),
clearErrors: jest.fn(),
validate: jest.fn(),
reset: jest.fn(),
__isIncludedInOutput: true,
__serializeValue: jest.fn(),
...options,
};
};
33 changes: 33 additions & 0 deletions x-pack/plugins/cases/public/common/shared_imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this file for cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! we import the form from es_ui_shared

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export {
getUseField,
getFieldValidityAndErrorMessage,
FieldHook,
FieldValidateResponse,
FIELD_TYPES,
Form,
FormData,
FormDataProvider,
FormHook,
FormSchema,
UseField,
UseMultiFields,
useForm,
useFormContext,
useFormData,
ValidationError,
ValidationFunc,
VALIDATION_TYPES,
} from '../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib';
export {
Field,
SelectField,
} from '../../../../../src/plugins/es_ui_shared/static/forms/components';
export { fieldValidators } from '../../../../../src/plugins/es_ui_shared/static/forms/helpers';
export { ERROR_CODE } from '../../../../../src/plugins/es_ui_shared/static/forms/helpers/field_validators/types';
12 changes: 12 additions & 0 deletions x-pack/plugins/cases/public/common/test_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Do we use this file for cases? If not I think we should remove it.

Copy link
Contributor Author

@stephmilovic stephmilovic Mar 16, 2021

Choose a reason for hiding this comment

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

yes. the function removeExternalLinkText is used in markdown_editor/renderer.test.ts.

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/**
* Convenience utility to remove text appended to links by EUI
*/
export const removeExternalLinkText = (str: string) =>
str.replace(/\(opens in a new tab or window\)/g, '');
Loading