-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[SIEM][Exceptions] - Exception builder component #67013
Merged
Merged
Changes from 58 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
c2702ed
added modified and or badge, should move to common folder
yctercero 1a0b722
added and or buttons with tests
yctercero 4436fed
added exception item entry component and helpers with tests
yctercero ad80d70
added exception item, needs tests, and some additional utils
yctercero 3008b0d
added exception item tests and made some modifications
yctercero 6b47020
added tests, index, cleaned up
yctercero e1c02e4
moved exception builder into common components
yctercero cf861dc
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 8b93681
cleaned up a few things, wip
yctercero a7dc8e6
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 3ded2df
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 0934ca8
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 0f84083
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero fe16cdf
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero c35bb4b
Add pure API functions and react hooks for value list APIs
rylnd c83dabc
Fix type errors in hook tests
rylnd 3572c6e
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero fa512d7
Merge branch 'master' into value_lists_api
rylnd 247f8e4
Document current limitations of useAsyncTask
rylnd b657229
Defines a new validation function that returns an Either instead of a…
rylnd d627a64
Remove duplicated copyright comment
rylnd 8d2eb3a
WIP: Perform request/response validations in the FP style
rylnd d99ba54
Adds helper function to convert a TaskEither back to a Promise
rylnd ef0a29e
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 6920459
Adds request/response validations to findLists
rylnd 6d6b5cc
Refactor our API types
rylnd 0f223aa
Add request/response validation to import/export functions
rylnd e7f5b86
Fix type errors
rylnd 2fe8948
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero f433c51
Attempting to reduce plugin bundle size
rylnd 15da0f7
Merge branch 'master' into value_lists_api
elasticmachine e8a0483
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 9364770
Merge branch 'master' into value_lists_api
rylnd 02101c7
useAsyncFn's initiator does not return a promise
rylnd 4f43637
Fix failing test
rylnd e2fb4d0
reworking builder
yctercero 3b8653a
wip - adding exception builder input blocks
yctercero dee8857
Merge branch 'value_lists_api' of https://github.com/rylnd/kibana int…
yctercero 708cfb3
added reusable field, operator and autocomplete components with tests…
yctercero 533f317
added exception builder components
yctercero bfa4f39
superficial change, updated lists exceptions public files to be exten…
yctercero 824246b
exported operator enum for use in front end and added tests
yctercero 15226b1
updated types in exceptions components
yctercero 575e2d2
fixed up lint issues
yctercero b5d034c
Merge branch 'master' of github.com:yctercero/kibana into exceptions_…
yctercero b0d2286
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 2c52325
reverting changes in prep for new changes from other branch
yctercero 004e312
reverting changes in prep for new changes from other branch
yctercero 2795bd1
reverting changes in prep for new changes from other branch
yctercero 32212bb
Worked on exception builder in a separate branch than original, mergi…
yctercero c30cf95
some cleanup
yctercero 91e02d0
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero 1bc48cd
clean up
yctercero a9b3e95
continued cleanup, added some more validation
yctercero 58b2ceb
updated operator field label
yctercero 3026957
fixed react warning, updated validation and tests
yctercero 9341cba
few changes didnt get in, updated tests
yctercero ac3074e
updated creation of new exception item
yctercero 7749035
Merge branch 'master' of github.com:yctercero/kibana into exception-b…
yctercero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -15,7 +15,6 @@ const antennaStyles = css` | |
background: ${({ theme }) => theme.eui.euiColorLightShade}; | ||
position: relative; | ||
width: 2px; | ||
margin: 0 12px 0 0; | ||
&:after { | ||
background: ${({ theme }) => theme.eui.euiColorLightShade}; | ||
content: ''; | ||
|
@@ -40,10 +39,6 @@ const BottomAntenna = styled(EuiFlexItem)` | |
} | ||
`; | ||
|
||
const EuiFlexItemWrapper = styled(EuiFlexItem)` | ||
margin: 0 12px 0 0; | ||
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. Removed, ended up being unnecessary. This antenna version of the badge is only being used in exceptions UI, so would not have ramifications elsewhere. |
||
`; | ||
|
||
export const RoundedBadgeAntenna: React.FC<{ type: AndOr }> = ({ type }) => ( | ||
<EuiFlexGroup | ||
className="andBadgeContainer" | ||
|
@@ -52,9 +47,9 @@ export const RoundedBadgeAntenna: React.FC<{ type: AndOr }> = ({ type }) => ( | |
alignItems="center" | ||
> | ||
<TopAntenna data-test-subj="andOrBadgeBarTop" grow={1} /> | ||
<EuiFlexItemWrapper grow={false}> | ||
<EuiFlexItem grow={false}> | ||
<RoundedBadge type={type} /> | ||
</EuiFlexItemWrapper> | ||
</EuiFlexItem> | ||
<BottomAntenna data-test-subj="andOrBadgeBarBottom" grow={1} /> | ||
</EuiFlexGroup> | ||
); | ||
|
156 changes: 156 additions & 0 deletions
156
x-pack/plugins/security_solution/public/common/components/autocomplete/field.test.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,156 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import { mount } from 'enzyme'; | ||
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui'; | ||
|
||
import { | ||
fields, | ||
getField, | ||
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks.ts'; | ||
import { FieldComponent } from './field'; | ||
|
||
describe('FieldComponent', () => { | ||
test('it renders disabled if "isDisabled" is true', () => { | ||
const wrapper = mount( | ||
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}> | ||
<FieldComponent | ||
placeholder="Placeholder text" | ||
indexPattern={{ | ||
id: '1234', | ||
title: 'logstash-*', | ||
fields, | ||
}} | ||
selectedField={getField('machine.os.raw')} | ||
isLoading={false} | ||
isClearable={false} | ||
isDisabled={true} | ||
onChange={jest.fn()} | ||
/> | ||
</ThemeProvider> | ||
); | ||
|
||
expect( | ||
wrapper.find(`[data-test-subj="fieldAutocompleteComboBox"] input`).prop('disabled') | ||
).toBeTruthy(); | ||
}); | ||
|
||
test('it renders loading if "isLoading" is true', () => { | ||
const wrapper = mount( | ||
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}> | ||
<FieldComponent | ||
placeholder="Placeholder text" | ||
indexPattern={{ | ||
id: '1234', | ||
title: 'logstash-*', | ||
fields, | ||
}} | ||
selectedField={getField('machine.os.raw')} | ||
isLoading={true} | ||
isClearable={false} | ||
isDisabled={false} | ||
onChange={jest.fn()} | ||
/> | ||
</ThemeProvider> | ||
); | ||
wrapper.find(`[data-test-subj="fieldAutocompleteComboBox"] button`).at(0).simulate('click'); | ||
expect( | ||
wrapper | ||
.find(`EuiComboBoxOptionsList[data-test-subj="fieldAutocompleteComboBox-optionsList"]`) | ||
.prop('isLoading') | ||
).toBeTruthy(); | ||
}); | ||
|
||
test('it allows user to clear values if "isClearable" is true', () => { | ||
const wrapper = mount( | ||
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}> | ||
<FieldComponent | ||
placeholder="Placeholder text" | ||
indexPattern={{ | ||
id: '1234', | ||
title: 'logstash-*', | ||
fields, | ||
}} | ||
selectedField={getField('machine.os.raw')} | ||
isLoading={false} | ||
isClearable={true} | ||
isDisabled={false} | ||
onChange={jest.fn()} | ||
/> | ||
</ThemeProvider> | ||
); | ||
|
||
expect( | ||
wrapper | ||
.find(`[data-test-subj="comboBoxInput"]`) | ||
.hasClass('euiComboBox__inputWrap-isClearable') | ||
).toBeTruthy(); | ||
}); | ||
|
||
test('it correctly displays selected field', () => { | ||
const wrapper = mount( | ||
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}> | ||
<FieldComponent | ||
placeholder="Placeholder text" | ||
indexPattern={{ | ||
id: '1234', | ||
title: 'logstash-*', | ||
fields, | ||
}} | ||
selectedField={getField('machine.os.raw')} | ||
isLoading={false} | ||
isClearable={false} | ||
isDisabled={false} | ||
onChange={jest.fn()} | ||
/> | ||
</ThemeProvider> | ||
); | ||
|
||
expect( | ||
wrapper.find(`[data-test-subj="fieldAutocompleteComboBox"] EuiComboBoxPill`).at(0).text() | ||
).toEqual('machine.os.raw'); | ||
}); | ||
|
||
test('it invokes "onChange" when option selected', () => { | ||
const mockOnChange = jest.fn(); | ||
const wrapper = mount( | ||
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}> | ||
<FieldComponent | ||
placeholder="Placeholder text" | ||
indexPattern={{ | ||
id: '1234', | ||
title: 'logstash-*', | ||
fields, | ||
}} | ||
selectedField={getField('machine.os.raw')} | ||
isLoading={false} | ||
isClearable={false} | ||
isDisabled={false} | ||
onChange={mockOnChange} | ||
/> | ||
</ThemeProvider> | ||
); | ||
|
||
((wrapper.find(EuiComboBox).props() as unknown) as { | ||
onChange: (a: EuiComboBoxOptionOption[]) => void; | ||
}).onChange([{ label: 'machine.os' }]); | ||
|
||
expect(mockOnChange).toHaveBeenCalledWith([ | ||
{ | ||
aggregatable: true, | ||
count: 0, | ||
esTypes: ['text'], | ||
name: 'machine.os', | ||
readFromDocValues: false, | ||
scripted: false, | ||
searchable: true, | ||
type: 'string', | ||
}, | ||
]); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
x-pack/plugins/security_solution/public/common/components/autocomplete/field.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,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React, { useMemo, useCallback } from 'react'; | ||
import { EuiComboBoxOptionOption, EuiComboBox } from '@elastic/eui'; | ||
|
||
import { IFieldType, IIndexPattern } from '../../../../../../../src/plugins/data/common'; | ||
import { getGenericComboBoxProps } from './helpers'; | ||
import { GetGenericComboBoxPropsReturn } from './types'; | ||
|
||
interface OperatorProps { | ||
placeholder: string; | ||
selectedField: IFieldType | undefined; | ||
indexPattern: IIndexPattern | undefined; | ||
isLoading: boolean; | ||
isDisabled: boolean; | ||
isClearable: boolean; | ||
fieldInputWidth?: number; | ||
onChange: (a: IFieldType[]) => void; | ||
} | ||
|
||
export const FieldComponent: React.FC<OperatorProps> = ({ | ||
placeholder, | ||
selectedField, | ||
indexPattern, | ||
isLoading = false, | ||
isDisabled = false, | ||
isClearable = false, | ||
fieldInputWidth = 190, | ||
onChange, | ||
}): JSX.Element => { | ||
const getLabel = useCallback((field): string => field.name, []); | ||
const optionsMemo = useMemo((): IFieldType[] => (indexPattern ? indexPattern.fields : []), [ | ||
indexPattern, | ||
]); | ||
const selectedOptionsMemo = useMemo((): IFieldType[] => (selectedField ? [selectedField] : []), [ | ||
selectedField, | ||
]); | ||
const { comboOptions, labels, selectedComboOptions } = useMemo( | ||
(): GetGenericComboBoxPropsReturn => | ||
getGenericComboBoxProps<IFieldType>({ | ||
options: optionsMemo, | ||
selectedOptions: selectedOptionsMemo, | ||
getLabel, | ||
}), | ||
[optionsMemo, selectedOptionsMemo, getLabel] | ||
); | ||
|
||
const handleValuesChange = (newOptions: EuiComboBoxOptionOption[]): void => { | ||
const newValues: IFieldType[] = newOptions.map( | ||
({ label }) => optionsMemo[labels.indexOf(label)] | ||
); | ||
onChange(newValues); | ||
}; | ||
|
||
return ( | ||
<EuiComboBox | ||
placeholder={placeholder} | ||
options={comboOptions} | ||
selectedOptions={selectedComboOptions} | ||
onChange={handleValuesChange} | ||
isLoading={isLoading} | ||
isDisabled={isDisabled} | ||
isClearable={isClearable} | ||
singleSelection={{ asPlainText: true }} | ||
data-test-subj="fieldAutocompleteComboBox" | ||
style={{ width: `${fieldInputWidth}px` }} | ||
/> | ||
); | ||
}; | ||
|
||
FieldComponent.displayName = 'Field'; |
27 changes: 27 additions & 0 deletions
27
...ugins/security_solution/public/common/components/autocomplete/field_value_exists.test.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,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import { mount } from 'enzyme'; | ||
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; | ||
|
||
import { AutocompleteFieldExistsComponent } from './field_value_exists'; | ||
|
||
describe('AutocompleteFieldExistsComponent', () => { | ||
test('it renders field disabled', () => { | ||
const wrapper = mount( | ||
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}> | ||
<AutocompleteFieldExistsComponent placeholder="Placeholder text" /> | ||
</ThemeProvider> | ||
); | ||
|
||
expect( | ||
wrapper | ||
.find(`[data-test-subj="valuesAutocompleteComboBox existsComboxBox"] input`) | ||
.prop('disabled') | ||
).toBeTruthy(); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
...ck/plugins/security_solution/public/common/components/autocomplete/field_value_exists.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,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { EuiComboBox } from '@elastic/eui'; | ||
|
||
interface AutocompleteFieldExistsProps { | ||
placeholder: string; | ||
} | ||
|
||
export const AutocompleteFieldExistsComponent: React.FC<AutocompleteFieldExistsProps> = ({ | ||
placeholder, | ||
}): JSX.Element => ( | ||
<EuiComboBox | ||
placeholder={placeholder} | ||
options={[]} | ||
selectedOptions={[]} | ||
onChange={undefined} | ||
isDisabled | ||
data-test-subj="valuesAutocompleteComboBox existsComboxBox" | ||
fullWidth | ||
/> | ||
); | ||
|
||
AutocompleteFieldExistsComponent.displayName = 'AutocompleteFieldExists'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Icky, I know. It's a workaround to enums not being a thing in io-ts yet - gcanti/io-ts#67 . I've added unit tests so that if the io-ts type
operator
is updated, tests will fail and user will see note about needing to updateOperatorEnum
as well.