Skip to content

Commit

Permalink
♻️ Refactor to reuse shared function
Browse files Browse the repository at this point in the history
  • Loading branch information
dej611 committed Nov 12, 2020
1 parent 2dae5e8 commit c4cc2bf
Showing 1 changed file with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export const FilterPopover = ({
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const inputRef = React.useRef<HTMLInputElement>();

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 });
Expand All @@ -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={
<Button
onClick={() => {
Expand All @@ -91,12 +88,7 @@ export const FilterPopover = ({
onChange={setFilterLabel}
placeholder={getPlaceholder(filter.input.query)}
inputRef={inputRef}
onSubmit={() => {
if (isOpenByCreation) {
setIsOpenByCreation(false);
}
setIsPopoverOpen(false);
}}
onSubmit={() => closePopover()}
dataTestSubj="indexPattern-filters-label"
/>
</EuiPopover>
Expand Down

0 comments on commit c4cc2bf

Please sign in to comment.