-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Cases] Move create page components and dependenc…
…ies to Cases (#94444)
- Loading branch information
1 parent
769243c
commit c497239
Showing
362 changed files
with
17,515 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,3 +108,4 @@ pageLoadAssetSize: | |
fileUpload: 25664 | ||
banners: 17946 | ||
mapsEms: 26072 | ||
cases: 102558 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 CasesAppError extends AppError { | ||
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 isCasesAppError = (error: unknown): error is CasesAppError => | ||
has('message', error) && has('body.message', error) && has('body.status_code', error); | ||
|
||
export const isAppError = (error: unknown): error is AppError => | ||
isKibanaError(error) || isCasesAppError(error); |
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/cases/public/common/lib/kibana/__mocks__/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
x-pack/plugins/cases/public/common/lib/kibana/kibana_react.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
x-pack/plugins/cases/public/common/lib/kibana/kibana_react.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Cases app?' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
x-pack/plugins/cases/public/common/mock/kibana_react.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
x-pack/plugins/cases/public/common/mock/test_providers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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, ''); |
Oops, something went wrong.