Skip to content

Commit 1adaa3b

Browse files
authored
[Security Solution][Exceptions] - Remove initial add exception item button in builder (#72215)
## Summary This PR addresses two issues in the builder: - **Existing behavior:** if you add a bunch of entries then delete all but one, the indent that shows for when multiple entries exists does not go away - **Updated behavior:** if you add a bunch of entries and delete all but one, the indent that shows for when multiple entries exist goes away - **Existing behavior:** on render of add exception modal, if no exception items exist (or no exception items with entries exist) an `Add Exception` button appears - **Updated behavior:** if only one entry exists, the delete button is disabled for that entry; on initial render of the add exception modal, if no entries exist, an empty entry is shown
1 parent 44fc2a8 commit 1adaa3b

File tree

8 files changed

+493
-282
lines changed

8 files changed

+493
-282
lines changed

x-pack/plugins/security_solution/public/common/components/exceptions/builder/builder_button_options.stories.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,12 @@ addDecorator((storyFn) => (
1616
));
1717

1818
storiesOf('Components|Exceptions|BuilderButtonOptions', module)
19-
.add('init button', () => {
20-
return (
21-
<BuilderButtonOptions
22-
isAndDisabled={false}
23-
isOrDisabled={false}
24-
showNestedButton={false}
25-
displayInitButton
26-
onOrClicked={action('onClick')}
27-
onAndClicked={action('onClick')}
28-
onNestedClicked={action('onClick')}
29-
/>
30-
);
31-
})
3219
.add('and/or buttons', () => {
3320
return (
3421
<BuilderButtonOptions
3522
isAndDisabled={false}
3623
isOrDisabled={false}
3724
showNestedButton={false}
38-
displayInitButton={false}
3925
onOrClicked={action('onClick')}
4026
onAndClicked={action('onClick')}
4127
onNestedClicked={action('onClick')}
@@ -48,7 +34,6 @@ storiesOf('Components|Exceptions|BuilderButtonOptions', module)
4834
isAndDisabled={false}
4935
isOrDisabled={false}
5036
showNestedButton
51-
displayInitButton={false}
5237
onOrClicked={action('onClick')}
5338
onAndClicked={action('onClick')}
5439
onNestedClicked={action('onClick')}
@@ -61,7 +46,6 @@ storiesOf('Components|Exceptions|BuilderButtonOptions', module)
6146
isAndDisabled
6247
isOrDisabled={false}
6348
showNestedButton={false}
64-
displayInitButton={false}
6549
onOrClicked={action('onClick')}
6650
onAndClicked={action('onClick')}
6751
onNestedClicked={action('onClick')}
@@ -74,7 +58,6 @@ storiesOf('Components|Exceptions|BuilderButtonOptions', module)
7458
isAndDisabled={false}
7559
isOrDisabled
7660
showNestedButton={false}
77-
displayInitButton={false}
7861
onOrClicked={action('onClick')}
7962
onAndClicked={action('onClick')}
8063
onNestedClicked={action('onClick')}

x-pack/plugins/security_solution/public/common/components/exceptions/builder/builder_button_options.test.tsx

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ describe('BuilderButtonOptions', () => {
1616
isAndDisabled={false}
1717
isOrDisabled={false}
1818
showNestedButton={false}
19-
displayInitButton={false}
2019
onOrClicked={jest.fn()}
2120
onAndClicked={jest.fn()}
2221
onNestedClicked={jest.fn()}
@@ -31,44 +30,6 @@ describe('BuilderButtonOptions', () => {
3130
expect(wrapper.find('[data-test-subj="exceptionsNestedButton"] button')).toHaveLength(0);
3231
});
3332

34-
test('it renders "add exception" button if "displayInitButton" is true', () => {
35-
const wrapper = mount(
36-
<BuilderButtonOptions
37-
isAndDisabled={false}
38-
isOrDisabled={false}
39-
showNestedButton={false}
40-
displayInitButton
41-
onOrClicked={jest.fn()}
42-
onAndClicked={jest.fn()}
43-
onNestedClicked={jest.fn()}
44-
/>
45-
);
46-
47-
expect(wrapper.find('[data-test-subj="exceptionsAddNewExceptionButton"] button')).toHaveLength(
48-
1
49-
);
50-
});
51-
52-
test('it invokes "onAddExceptionClicked" when "add exception" button is clicked', () => {
53-
const onOrClicked = jest.fn();
54-
55-
const wrapper = mount(
56-
<BuilderButtonOptions
57-
isAndDisabled={false}
58-
isOrDisabled={false}
59-
showNestedButton={false}
60-
displayInitButton
61-
onOrClicked={onOrClicked}
62-
onAndClicked={jest.fn()}
63-
onNestedClicked={jest.fn()}
64-
/>
65-
);
66-
67-
wrapper.find('[data-test-subj="exceptionsAddNewExceptionButton"] button').simulate('click');
68-
69-
expect(onOrClicked).toHaveBeenCalledTimes(1);
70-
});
71-
7233
test('it invokes "onOrClicked" when "or" button is clicked', () => {
7334
const onOrClicked = jest.fn();
7435

@@ -77,7 +38,6 @@ describe('BuilderButtonOptions', () => {
7738
isAndDisabled={false}
7839
isOrDisabled={false}
7940
showNestedButton={false}
80-
displayInitButton={false}
8141
onOrClicked={onOrClicked}
8242
onAndClicked={jest.fn()}
8343
onNestedClicked={jest.fn()}
@@ -97,7 +57,6 @@ describe('BuilderButtonOptions', () => {
9757
isAndDisabled={false}
9858
isOrDisabled={false}
9959
showNestedButton={false}
100-
displayInitButton={false}
10160
onOrClicked={jest.fn()}
10261
onAndClicked={onAndClicked}
10362
onNestedClicked={jest.fn()}
@@ -113,7 +72,6 @@ describe('BuilderButtonOptions', () => {
11372
const wrapper = mount(
11473
<BuilderButtonOptions
11574
showNestedButton={false}
116-
displayInitButton={false}
11775
isOrDisabled={false}
11876
isAndDisabled
11977
onOrClicked={jest.fn()}
@@ -131,7 +89,6 @@ describe('BuilderButtonOptions', () => {
13189
const wrapper = mount(
13290
<BuilderButtonOptions
13391
showNestedButton={false}
134-
displayInitButton={false}
13592
isOrDisabled
13693
isAndDisabled={false}
13794
onOrClicked={jest.fn()}
@@ -153,7 +110,6 @@ describe('BuilderButtonOptions', () => {
153110
isAndDisabled={false}
154111
isOrDisabled={false}
155112
showNestedButton
156-
displayInitButton={false}
157113
onOrClicked={jest.fn()}
158114
onAndClicked={jest.fn()}
159115
onNestedClicked={onNestedClicked}

x-pack/plugins/security_solution/public/common/components/exceptions/builder/builder_button_options.tsx

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const MyEuiButton = styled(EuiButton)`
1616
interface BuilderButtonOptionsProps {
1717
isOrDisabled: boolean;
1818
isAndDisabled: boolean;
19-
displayInitButton: boolean;
2019
showNestedButton: boolean;
2120
onAndClicked: () => void;
2221
onOrClicked: () => void;
@@ -26,64 +25,47 @@ interface BuilderButtonOptionsProps {
2625
export const BuilderButtonOptions: React.FC<BuilderButtonOptionsProps> = ({
2726
isOrDisabled = false,
2827
isAndDisabled = false,
29-
displayInitButton,
3028
showNestedButton = false,
3129
onAndClicked,
3230
onOrClicked,
3331
onNestedClicked,
3432
}) => (
3533
<EuiFlexGroup gutterSize="s" alignItems="center">
36-
{displayInitButton ? (
34+
<EuiFlexItem grow={false}>
35+
<MyEuiButton
36+
fill
37+
size="s"
38+
iconType="plusInCircle"
39+
onClick={onAndClicked}
40+
data-test-subj="exceptionsAndButton"
41+
isDisabled={isAndDisabled}
42+
>
43+
{i18n.AND}
44+
</MyEuiButton>
45+
</EuiFlexItem>
46+
<EuiFlexItem grow={false}>
47+
<MyEuiButton
48+
fill
49+
size="s"
50+
iconType="plusInCircle"
51+
onClick={onOrClicked}
52+
isDisabled={isOrDisabled}
53+
data-test-subj="exceptionsOrButton"
54+
>
55+
{i18n.OR}
56+
</MyEuiButton>
57+
</EuiFlexItem>
58+
{showNestedButton && (
3759
<EuiFlexItem grow={false}>
3860
<EuiButton
39-
fill
4061
size="s"
41-
iconType="plusInCircle"
42-
onClick={onOrClicked}
43-
data-test-subj="exceptionsAddNewExceptionButton"
62+
iconType="nested"
63+
onClick={onNestedClicked}
64+
data-test-subj="exceptionsNestedButton"
4465
>
45-
{i18n.ADD_EXCEPTION_TITLE}
66+
{i18n.ADD_NESTED_DESCRIPTION}
4667
</EuiButton>
4768
</EuiFlexItem>
48-
) : (
49-
<>
50-
<EuiFlexItem grow={false}>
51-
<MyEuiButton
52-
fill
53-
size="s"
54-
iconType="plusInCircle"
55-
onClick={onAndClicked}
56-
data-test-subj="exceptionsAndButton"
57-
isDisabled={isAndDisabled}
58-
>
59-
{i18n.AND}
60-
</MyEuiButton>
61-
</EuiFlexItem>
62-
<EuiFlexItem grow={false}>
63-
<MyEuiButton
64-
fill
65-
size="s"
66-
iconType="plusInCircle"
67-
onClick={onOrClicked}
68-
isDisabled={isOrDisabled}
69-
data-test-subj="exceptionsOrButton"
70-
>
71-
{i18n.OR}
72-
</MyEuiButton>
73-
</EuiFlexItem>
74-
{showNestedButton && (
75-
<EuiFlexItem grow={false}>
76-
<EuiButton
77-
size="s"
78-
iconType="nested"
79-
onClick={onNestedClicked}
80-
data-test-subj="exceptionsNestedButton"
81-
>
82-
{i18n.ADD_NESTED_DESCRIPTION}
83-
</EuiButton>
84-
</EuiFlexItem>
85-
)}
86-
</>
8769
)}
8870
</EuiFlexGroup>
8971
);

0 commit comments

Comments
 (0)