From c4cc2bfa88fa80f9fe28459d275a69581bed8a63 Mon Sep 17 00:00:00 2001 From: dej611 Date: Thu, 12 Nov 2020 10:01:37 +0100 Subject: [PATCH] :recycle: Refactor to reuse shared function --- .../definitions/filters/filter_popover.tsx | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx index 85e041ac7a4b3..18fdf2be000c7 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx @@ -32,9 +32,13 @@ export const FilterPopover = ({ const [isPopoverOpen, setIsPopoverOpen] = useState(false); const inputRef = React.useRef(); - const setPopoverOpen = (isOpen: boolean) => { - setIsPopoverOpen(isOpen); - setIsOpenByCreation(isOpen); + const closePopover = () => { + if (isOpenByCreation) { + setIsOpenByCreation(false); + } + if (isPopoverOpen) { + setIsPopoverOpen(false); + } }; const setFilterLabel = (label: string) => setFilter({ ...filter, label }); @@ -57,14 +61,7 @@ export const FilterPopover = ({ panelClassName="lnsIndexPatternDimensionEditor__filtersEditor" isOpen={isOpenByCreation || isPopoverOpen} ownFocus - closePopover={() => { - if (isOpenByCreation) { - setIsOpenByCreation(false); - } - if (isPopoverOpen) { - setIsPopoverOpen(false); - } - }} + closePopover={() => closePopover()} button={