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] Add Esc key handling to lens_configuration_flyout #198487

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
EuiFlexGroup,
EuiFlexItem,
euiScrollBarStyles,
EuiWindowEvent,
keys,
} from '@elastic/eui';
import { euiThemeVars } from '@kbn/ui-theme';
import type { Datatable } from '@kbn/expressions-plugin/public';
Expand Down Expand Up @@ -392,40 +394,51 @@ export function LensEditConfigurationFlyout({
getUserMessages,
]);

const onKeyDown = (e: KeyboardEvent) => {
if (e.key === keys.ESCAPE) {
closeFlyout?.();
setIsInlineFlyoutVisible(false);
}
};

if (isLoading) return null;
// Example is the Discover editing where we dont want to render the text based editor on the panel, neither the suggestions (for now)
if (!canEditTextBasedQuery && hidesSuggestions) {
return (
<FlyoutWrapper
isInlineFlyoutVisible={isInlineFlyoutVisible}
displayFlyoutHeader={displayFlyoutHeader}
onCancel={onCancel}
navigateToLensEditor={navigateToLensEditor}
onApply={onApply}
isScrollable
isNewPanel={isNewPanel}
isSaveable={isSaveable}
>
<LayerConfiguration
// TODO: remove this once we support switching to any chart in Discover
onlyAllowSwitchToSubtypes
getUserMessages={getUserMessages}
attributes={attributes}
coreStart={coreStart}
startDependencies={startDependencies}
visualizationMap={visualizationMap}
datasourceMap={datasourceMap}
datasourceId={datasourceId}
hasPadding
framePublicAPI={framePublicAPI}
setIsInlineFlyoutVisible={setIsInlineFlyoutVisible}
/>
</FlyoutWrapper>
<>
{isInlineFlyoutVisible && <EuiWindowEvent event="keydown" handler={onKeyDown} />}
<FlyoutWrapper
isInlineFlyoutVisible={isInlineFlyoutVisible}
displayFlyoutHeader={displayFlyoutHeader}
onCancel={onCancel}
navigateToLensEditor={navigateToLensEditor}
onApply={onApply}
isScrollable
isNewPanel={isNewPanel}
isSaveable={isSaveable}
>
<LayerConfiguration
// TODO: remove this once we support switching to any chart in Discover
onlyAllowSwitchToSubtypes
getUserMessages={getUserMessages}
attributes={attributes}
coreStart={coreStart}
startDependencies={startDependencies}
visualizationMap={visualizationMap}
datasourceMap={datasourceMap}
datasourceId={datasourceId}
hasPadding
framePublicAPI={framePublicAPI}
setIsInlineFlyoutVisible={setIsInlineFlyoutVisible}
/>
</FlyoutWrapper>
</>
);
}

return (
<>
{isInlineFlyoutVisible && <EuiWindowEvent event="keydown" handler={onKeyDown} />}
<FlyoutWrapper
isInlineFlyoutVisible={isInlineFlyoutVisible}
displayFlyoutHeader={displayFlyoutHeader}
Expand Down