Skip to content

Commit

Permalink
Hide or button if needed (elastic#116124)
Browse files Browse the repository at this point in the history
  • Loading branch information
dasansol92 authored Oct 26, 2021
1 parent 27866ce commit 9c3c489
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface ExceptionBuilderProps {
isAndDisabled: boolean;
isNestedDisabled: boolean;
isOrDisabled: boolean;
isOrHidden?: boolean;
listId: string;
listNamespaceType: NamespaceType;
listType: ExceptionListType;
Expand All @@ -103,6 +104,7 @@ export const ExceptionBuilderComponent = ({
isAndDisabled,
isNestedDisabled,
isOrDisabled,
isOrHidden = false,
listId,
listNamespaceType,
listType,
Expand Down Expand Up @@ -433,6 +435,7 @@ export const ExceptionBuilderComponent = ({
<EuiFlexItem grow={1}>
<BuilderLogicButtons
isOrDisabled={isOrDisabled ? isOrDisabled : disableOr}
isOrHidden={isOrHidden}
isAndDisabled={isAndDisabled ? isAndDisabled : disableAnd}
isNestedDisabled={isNestedDisabled ? isNestedDisabled : disableNested}
isNested={addNested}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,25 @@ describe('BuilderLogicButtons', () => {
expect(wrapper.find('[data-test-subj="exceptionsNestedButton"] button')).toHaveLength(0);
});

test('it hides "or" button', () => {
const wrapper = mount(
<BuilderLogicButtons
isAndDisabled={false}
isOrDisabled={false}
isOrHidden={true}
isNestedDisabled={false}
isNested={false}
showNestedButton={false}
onOrClicked={jest.fn()}
onAndClicked={jest.fn()}
onNestedClicked={jest.fn()}
onAddClickWhenNested={jest.fn()}
/>
);

expect(wrapper.find('[data-test-subj="exceptionsOrButton"] button')).toHaveLength(0);
});

test('it invokes "onOrClicked" when "or" button is clicked', () => {
const onOrClicked = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface BuilderLogicButtonsProps {
isNested: boolean;
isNestedDisabled: boolean;
isOrDisabled: boolean;
isOrHidden?: boolean;
showNestedButton: boolean;
onAddClickWhenNested: () => void;
onAndClicked: () => void;
Expand All @@ -32,6 +33,7 @@ export const BuilderLogicButtons: React.FC<BuilderLogicButtonsProps> = ({
isNested,
isNestedDisabled = true,
isOrDisabled = false,
isOrHidden = false,
showNestedButton = false,
onAddClickWhenNested,
onAndClicked,
Expand All @@ -50,18 +52,20 @@ export const BuilderLogicButtons: React.FC<BuilderLogicButtonsProps> = ({
{i18n.AND}
</MyEuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<MyEuiButton
fill
size="s"
iconType="plusInCircle"
onClick={onOrClicked}
isDisabled={isOrDisabled}
data-test-subj="exceptionsOrButton"
>
{i18n.OR}
</MyEuiButton>
</EuiFlexItem>
{!isOrHidden && (
<EuiFlexItem grow={false}>
<MyEuiButton
fill
size="s"
iconType="plusInCircle"
onClick={onOrClicked}
isDisabled={isOrDisabled}
data-test-subj="exceptionsOrButton"
>
{i18n.OR}
</MyEuiButton>
</EuiFlexItem>
)}
{showNestedButton && (
<EuiFlexItem grow={false}>
<EuiButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export const EventFiltersForm: React.FC<EventFiltersFormProps> = memo(
listNamespaceType: 'agnostic',
ruleName: RULE_NAME,
indexPatterns,
isOrDisabled: true, // TODO: pending to be validated
isOrDisabled: true,
isOrHidden: true,
isAndDisabled: false,
isNestedDisabled: false,
dataTestSubj: 'alert-exception-builder',
Expand Down

0 comments on commit 9c3c489

Please sign in to comment.