From 9c3c489e481c5fe9992584a3a1db2e37ce8f3bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20S=C3=A1nchez?= Date: Tue, 26 Oct 2021 09:21:58 +0200 Subject: [PATCH] Hide or button if needed (#116124) --- .../builder/exception_items_renderer.tsx | 3 ++ .../components/builder/logic_buttons.test.tsx | 19 +++++++++++++ .../components/builder/logic_buttons.tsx | 28 +++++++++++-------- .../view/components/form/index.tsx | 3 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx b/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx index 1b25a2cb91e8..280dd8acbc7e 100644 --- a/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx +++ b/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx @@ -81,6 +81,7 @@ export interface ExceptionBuilderProps { isAndDisabled: boolean; isNestedDisabled: boolean; isOrDisabled: boolean; + isOrHidden?: boolean; listId: string; listNamespaceType: NamespaceType; listType: ExceptionListType; @@ -103,6 +104,7 @@ export const ExceptionBuilderComponent = ({ isAndDisabled, isNestedDisabled, isOrDisabled, + isOrHidden = false, listId, listNamespaceType, listType, @@ -433,6 +435,7 @@ export const ExceptionBuilderComponent = ({ { expect(wrapper.find('[data-test-subj="exceptionsNestedButton"] button')).toHaveLength(0); }); + test('it hides "or" button', () => { + const wrapper = mount( + + ); + + expect(wrapper.find('[data-test-subj="exceptionsOrButton"] button')).toHaveLength(0); + }); + test('it invokes "onOrClicked" when "or" button is clicked', () => { const onOrClicked = jest.fn(); diff --git a/x-pack/plugins/lists/public/exceptions/components/builder/logic_buttons.tsx b/x-pack/plugins/lists/public/exceptions/components/builder/logic_buttons.tsx index 3846b844bb55..aa308ecdc345 100644 --- a/x-pack/plugins/lists/public/exceptions/components/builder/logic_buttons.tsx +++ b/x-pack/plugins/lists/public/exceptions/components/builder/logic_buttons.tsx @@ -20,6 +20,7 @@ interface BuilderLogicButtonsProps { isNested: boolean; isNestedDisabled: boolean; isOrDisabled: boolean; + isOrHidden?: boolean; showNestedButton: boolean; onAddClickWhenNested: () => void; onAndClicked: () => void; @@ -32,6 +33,7 @@ export const BuilderLogicButtons: React.FC = ({ isNested, isNestedDisabled = true, isOrDisabled = false, + isOrHidden = false, showNestedButton = false, onAddClickWhenNested, onAndClicked, @@ -50,18 +52,20 @@ export const BuilderLogicButtons: React.FC = ({ {i18n.AND} - - - {i18n.OR} - - + {!isOrHidden && ( + + + {i18n.OR} + + + )} {showNestedButton && ( = 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',