-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 25 commits
756e5a5
59756e8
2b816e8
ebc609b
d5cbcd1
841659b
ead2da0
7a32042
359e8d1
83f6517
3ab3352
51f6f4d
8f1e82d
4763023
249383f
8f3424b
c1098f8
7d76248
4ff74fb
87a1cde
84714f9
5f5021d
731039a
debbcb0
53e1ba9
907bfc1
4f941e1
82cd096
1cb3917
6d04fb3
46a801e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,4 @@ pageLoadAssetSize: | |
osquery: 107090 | ||
fileUpload: 25664 | ||
banners: 17946 | ||
cases: 102558 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import { DEFAULT_MAX_SIGNALS } from '../../security_solution/common/constants'; | ||
|
||
const DEFAULT_MAX_SIGNALS = 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'; | ||
|
||
/** | ||
|
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'; |
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
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(); |
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'; |
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; |
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 }; |
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?' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
); | ||
} | ||
} |
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'; |
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); | ||
}; |
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, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this file for cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! we import the form from |
||
* 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'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. the function |
||
* 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, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving
cases
out ofsecuritySolution
is under a feature flag. while the size ofcases
goes up,securitySolution
will go down once the feature flag is removed and the moved code can be removed fromsecuritySolution
.There was a problem hiding this comment.
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.