Skip to content

Commit

Permalink
[Lens] Add Esc key handling to lens_configuration_flyout (#198487)
Browse files Browse the repository at this point in the history
## Summary

This PR adds `Esc` key handling to `LensEditConfigurationFlyout`

Closes: #175100
(cherry picked from commit 79331d5)
  • Loading branch information
kowalczyk-krzysztof committed Nov 4, 2024
1 parent 71e6eb0 commit da18801
Showing 1 changed file with 38 additions and 25 deletions.
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

0 comments on commit da18801

Please sign in to comment.