From c58c53efacbba416aabaca271b83fc3dd7f1c692 Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Tue, 10 Oct 2023 12:28:01 +0700 Subject: [PATCH 1/3] Fix report action context menu stuck when open search page with keyboard shortcut Signed-off-by: Tsaqif --- src/components/PopoverProvider/index.js | 4 ++++ src/components/PopoverWithoutOverlay/index.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/PopoverProvider/index.js b/src/components/PopoverProvider/index.js index efa230d920d5..20ad18f93c7d 100644 --- a/src/components/PopoverProvider/index.js +++ b/src/components/PopoverProvider/index.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import lodashGet from 'lodash/get'; const propTypes = { children: PropTypes.node.isRequired, @@ -22,7 +23,9 @@ function PopoverContextProvider(props) { if (!activePopoverRef.current || (anchorRef && anchorRef !== activePopoverRef.current.anchorRef)) { return; } + activePopoverRef.current.close(); + lodashGet(activePopoverRef, 'current.onCloseCallback', () => {})(); activePopoverRef.current = null; setIsOpen(false); }, []); @@ -106,6 +109,7 @@ function PopoverContextProvider(props) { closePopover(activePopoverRef.current.anchorRef); } activePopoverRef.current = popoverParams; + lodashGet(activePopoverRef, 'current.onOpenCallback', () => {})(); setIsOpen(true); }, [closePopover], diff --git a/src/components/PopoverWithoutOverlay/index.js b/src/components/PopoverWithoutOverlay/index.js index d35637958f1d..b7ebe29688d0 100644 --- a/src/components/PopoverWithoutOverlay/index.js +++ b/src/components/PopoverWithoutOverlay/index.js @@ -34,6 +34,8 @@ function Popover(props) { ref: props.withoutOverlayRef, close: props.onClose, anchorRef: props.anchorRef, + onCloseCallback: () => Modal.setCloseModal(null), + onOpenCallback: () => Modal.setCloseModal(() => props.onClose(props.anchorRef)), }); } else { props.onModalHide(); @@ -48,7 +50,6 @@ function Popover(props) { return; } firstRenderRef.current = false; - Modal.setCloseModal(props.isVisible ? () => props.onClose(props.anchorRef) : null); // We want this effect to run strictly ONLY when isVisible prop changes // eslint-disable-next-line react-hooks/exhaustive-deps From 2245a7e16d265a29dc9d9643864345d88e57d1c6 Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Mon, 16 Oct 2023 12:50:07 +0700 Subject: [PATCH 2/3] Using if clause instead of lodaashGet Signed-off-by: Tsaqif --- src/components/PopoverProvider/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/PopoverProvider/index.js b/src/components/PopoverProvider/index.js index 20ad18f93c7d..58a58643003b 100644 --- a/src/components/PopoverProvider/index.js +++ b/src/components/PopoverProvider/index.js @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import lodashGet from 'lodash/get'; const propTypes = { children: PropTypes.node.isRequired, @@ -25,7 +24,9 @@ function PopoverContextProvider(props) { } activePopoverRef.current.close(); - lodashGet(activePopoverRef, 'current.onCloseCallback', () => {})(); + if (activePopoverRef && activePopoverRef.current && activePopoverRef.current.onCloseCallback) { + activePopoverRef.current.onCloseCallback(); + } activePopoverRef.current = null; setIsOpen(false); }, []); @@ -109,7 +110,9 @@ function PopoverContextProvider(props) { closePopover(activePopoverRef.current.anchorRef); } activePopoverRef.current = popoverParams; - lodashGet(activePopoverRef, 'current.onOpenCallback', () => {})(); + if (popoverParams && popoverParams.onOpenCallback) { + popoverParams.onOpenCallback(); + } setIsOpen(true); }, [closePopover], From e7da926fdd5339bf5eb337806501defc646bac28 Mon Sep 17 00:00:00 2001 From: Tsaqif Date: Thu, 19 Oct 2023 22:55:46 +0700 Subject: [PATCH 3/3] modify if conditionn before calling onCloseCallback Signed-off-by: Tsaqif --- src/components/PopoverProvider/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PopoverProvider/index.js b/src/components/PopoverProvider/index.js index 58a58643003b..a4c8eb10eb1c 100644 --- a/src/components/PopoverProvider/index.js +++ b/src/components/PopoverProvider/index.js @@ -24,7 +24,7 @@ function PopoverContextProvider(props) { } activePopoverRef.current.close(); - if (activePopoverRef && activePopoverRef.current && activePopoverRef.current.onCloseCallback) { + if (activePopoverRef.current.onCloseCallback) { activePopoverRef.current.onCloseCallback(); } activePopoverRef.current = null;