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,8 +32,11 @@ export function DimensionContainer({
const [focusTrapIsEnabled, setFocusTrapIsEnabled] = useState(false);

const closeFlyout = () => {
handleClose();
setFocusTrapIsEnabled(false);
// some internal popovers are pretty slow to unmount, so give it some time
setTimeout(() => {
handleClose();
setFocusTrapIsEnabled(false);
}, 150); // <= 150 has been chosen from empirical testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really concerned about this approach. As you said it will add a delay as well as not even work in all cases depending on the timing of things.

I think I wasn't really clear in my original review, I think it's fine to use the updater function setState approach to make sure the flyout stays closed if the additional setStates triggered on closing the popover are really necessary, but I was under the impression the state update happening in this scenario doesn't even make sense and we can just avoid it all together.

So, in summary

  • Let's please not introduce constant waiting times in the UI if avoidable
  • See if it's possible to not update the state on unmount like this
  • If we have to, use the updater function to make sure the flyout stays closed, but limit the cases where this is happening

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move the issue upstream and have EUI fix it at component level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created issue elastic/eui#4265 on EUI repo and will remove the code here.

};

useEffect(() => {
Expand Down
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