-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] refactor DimensionContainer and fix flyout bug #79277
Changes from 3 commits
1cc3a16
70eda9a
1786760
21d284c
4c43d3e
4248be1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
*/ | ||
import './dimension_container.scss'; | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import React, { useState } from 'react'; | ||
import { | ||
EuiFlyoutHeader, | ||
EuiFlyoutFooter, | ||
|
@@ -16,89 +16,33 @@ import { | |
EuiOutsideClickDetector, | ||
} from '@elastic/eui'; | ||
|
||
import classNames from 'classnames'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { VisualizationDimensionGroupConfig } from '../../../types'; | ||
import { DimensionContainerState } from './types'; | ||
|
||
export function DimensionContainer({ | ||
dimensionContainerState, | ||
setDimensionContainerState, | ||
groups, | ||
accessor, | ||
groupId, | ||
trigger, | ||
isOpen, | ||
groupLabel, | ||
close, | ||
panel, | ||
panelTitle, | ||
}: { | ||
dimensionContainerState: DimensionContainerState; | ||
setDimensionContainerState: (newState: DimensionContainerState) => void; | ||
groups: VisualizationDimensionGroupConfig[]; | ||
accessor: string; | ||
groupId: string; | ||
trigger: React.ReactElement; | ||
isOpen: boolean; | ||
close: () => void; | ||
panel: React.ReactElement; | ||
panelTitle: React.ReactNode; | ||
groupLabel: string; | ||
}) { | ||
const [openByCreation, setIsOpenByCreation] = useState( | ||
dimensionContainerState.openId === accessor | ||
); | ||
const [focusTrapIsEnabled, setFocusTrapIsEnabled] = useState(false); | ||
const [flyoutIsVisible, setFlyoutIsVisible] = useState(false); | ||
|
||
const noMatch = dimensionContainerState.isOpen | ||
? !groups.some((d) => d.accessors.includes(accessor)) | ||
: false; | ||
|
||
const closeFlyout = () => { | ||
setDimensionContainerState({ | ||
isOpen: false, | ||
openId: null, | ||
addingToGroupId: null, | ||
}); | ||
setIsOpenByCreation(false); | ||
close(); | ||
setFocusTrapIsEnabled(false); | ||
setFlyoutIsVisible(false); | ||
}; | ||
|
||
const openFlyout = () => { | ||
setFlyoutIsVisible(true); | ||
setTimeout(() => { | ||
setFocusTrapIsEnabled(true); | ||
}, 255); | ||
}; | ||
|
||
const flyoutShouldBeOpen = | ||
dimensionContainerState.isOpen && | ||
(dimensionContainerState.openId === accessor || | ||
(noMatch && dimensionContainerState.addingToGroupId === groupId)); | ||
|
||
useEffect(() => { | ||
if (flyoutShouldBeOpen) { | ||
openFlyout(); | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
if (!flyoutShouldBeOpen) { | ||
if (flyoutIsVisible) { | ||
setFlyoutIsVisible(false); | ||
} | ||
if (focusTrapIsEnabled) { | ||
setFocusTrapIsEnabled(false); | ||
} | ||
} | ||
}, [flyoutShouldBeOpen, flyoutIsVisible, focusTrapIsEnabled]); | ||
|
||
const flyout = flyoutIsVisible && ( | ||
return isOpen ? ( | ||
<EuiFocusTrap disabled={!focusTrapIsEnabled} clickOutsideDisables={true}> | ||
<EuiOutsideClickDetector onOutsideClick={closeFlyout} isDisabled={!flyoutIsVisible}> | ||
<EuiOutsideClickDetector onOutsideClick={closeFlyout} isDisabled={!isOpen}> | ||
<div | ||
role="dialog" | ||
aria-labelledby="lnsDimensionContainerTitle" | ||
className={classNames('lnsDimensionContainer', { | ||
'lnsDimensionContainer--noAnimation': openByCreation, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly this line was responsible for directly showing the flyout without having it sliding out if it's a new dimension. Is there a special reason we don't want to do it anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flash1293 this is a weird construct that is a legacy from popover (each trigger has its own popover/flyout). In master, when you open a new dimension, there is an animation of opening a flyout. Then, if you configure it to the correct dimension, under the hood we close 'empty-dimension' flyout and open the 'configured dimension' flyout (it has to be different because the trigger is different). But we want the user to perceive it as seamless change, without the animation of what's really happening (close new dimension flyout, open existing dimension flyout). Adding this classname was causing the animation not to trigger in this case so it looked like it's the same flyout. In this PR, as we have one dimensionContainer for all of the triggers, when a user switches from new dimension to configured one, it's still the same DimensionContainer so nothing has to be hacked. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbondyra Got it, thanks for the explanation! |
||
})} | ||
className="lnsDimensionContainer" | ||
> | ||
<EuiFlyoutHeader hasBorder className="lnsDimensionContainer__header"> | ||
<EuiTitle size="xs"> | ||
|
@@ -109,7 +53,14 @@ export function DimensionContainer({ | |
iconType="sortLeft" | ||
flush="left" | ||
> | ||
<strong>{panelTitle}</strong> | ||
<strong> | ||
{i18n.translate('xpack.lens.configure.configurePanelTitle', { | ||
defaultMessage: '{groupLabel} configuration', | ||
values: { | ||
groupLabel, | ||
}, | ||
})} | ||
</strong> | ||
</EuiButtonEmpty> | ||
</EuiTitle> | ||
</EuiFlyoutHeader> | ||
|
@@ -126,12 +77,5 @@ export function DimensionContainer({ | |
</div> | ||
</EuiOutsideClickDetector> | ||
</EuiFocusTrap> | ||
); | ||
|
||
return ( | ||
<> | ||
{trigger} | ||
{flyout} | ||
</> | ||
); | ||
) : null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wasn't used anywhere