Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Make the dimension flyout panel stay close on outside click #83059

Merged
merged 9 commits into from
Nov 16, 2020
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,14 @@ export const FilterPopover = ({
panelClassName="lnsIndexPatternDimensionEditor__filtersEditor"
isOpen={isOpenByCreation || isPopoverOpen}
ownFocus
closePopover={() => {
setPopoverOpen(false);
}}
closePopover={() => closePopover()}
button={
<Button
onClick={() => {
if (isOpenByCreation) {
setIsOpenByCreation(false);
}
setIsPopoverOpen((open) => !open);
setIsOpenByCreation(false);
}}
/>
}
Expand All @@ -84,7 +88,7 @@ export const FilterPopover = ({
onChange={setFilterLabel}
placeholder={getPlaceholder(filter.input.query)}
inputRef={inputRef}
onSubmit={() => setPopoverOpen(false)}
onSubmit={() => closePopover()}
dataTestSubj="indexPattern-filters-label"
/>
</EuiPopover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ export const RangePopover = ({
});

const onSubmit = () => {
setIsPopoverOpen(false);
setIsOpenByCreation(false);
saveRangeAndReset(tempRange, true);
if (isOpenByCreation) {
setIsOpenByCreation(false);
}
if (isPopoverOpen) {
setIsPopoverOpen(false);
}
};

return (
Expand All @@ -100,8 +103,10 @@ export const RangePopover = ({
button={
<Button
onClick={() => {
if (isOpenByCreation) {
setIsOpenByCreation(false);
}
setIsPopoverOpen((isOpen) => !isOpen);
setIsOpenByCreation(false);
}}
/>
}
Expand Down Expand Up @@ -209,7 +214,7 @@ export const AdvancedRangeEditor = ({
const lastIndex = localRanges.length - 1;

// Update locally all the time, but bounce the parents prop function
// to aviod too many requests
// to avoid too many requests
useDebounce(
() => {
setRanges(localRanges.map(({ id, ...rest }) => ({ ...rest })));
Expand Down Expand Up @@ -249,7 +254,11 @@ export const AdvancedRangeEditor = ({
<>
<DragDropBuckets
onDragEnd={setLocalRanges}
onDragStart={() => setIsOpenByCreation(false)}
onDragStart={() => {
if (isOpenByCreation) {
setIsOpenByCreation(false);
}
}}
droppableId="RANGES_DROPPABLE_AREA"
items={localRanges}
>
Expand Down