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

fix(Dashboard): Omnibar dropdown visibility and keyboard commands #16168

Merged
merged 4 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
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 @@ -84,40 +84,6 @@ test('Open Omnibar with ctrl + k with featureflag enabled', () => {
).not.toBeVisible();
});

test('Open Omnibar with ctrl + s with featureflag enabled', () => {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this test could be written with K and esc keystrokes, to keep it rather than delete it.

(isFeatureEnabled as jest.Mock).mockImplementation(
(ff: string) => ff === 'OMNIBAR',
);
const logEvent = jest.fn();
render(
<div data-test="test">
<OmniContainer logEvent={logEvent} />
</div>,
);

expect(
screen.queryByPlaceholderText('Search all dashboards'),
).not.toBeInTheDocument();

// show Omnibar
fireEvent.keyDown(screen.getByTestId('test'), {
ctrlKey: true,
code: 'KeyS',
});
expect(
screen.queryByPlaceholderText('Search all dashboards'),
).toBeInTheDocument();

// hide Omnibar
fireEvent.keyDown(screen.getByTestId('test'), {
ctrlKey: true,
code: 'KeyS',
});
expect(
screen.queryByPlaceholderText('Search all dashboards'),
).not.toBeVisible();
});

test('Open Omnibar with Command + k with featureflag enabled', () => {
(isFeatureEnabled as jest.Mock).mockImplementation(
(ff: string) => ff === 'OMNIBAR',
Expand Down Expand Up @@ -152,7 +118,7 @@ test('Open Omnibar with Command + k with featureflag enabled', () => {
).not.toBeVisible();
});

test('Open Omnibar with Command + s with featureflag enabled', () => {
test('Open Omnibar with Cmd/Ctrl-K and close with ESC', () => {
(isFeatureEnabled as jest.Mock).mockImplementation(
(ff: string) => ff === 'OMNIBAR',
);
Expand All @@ -169,17 +135,17 @@ test('Open Omnibar with Command + s with featureflag enabled', () => {

// show Omnibar
fireEvent.keyDown(screen.getByTestId('test'), {
metaKey: true,
code: 'KeyS',
ctrlKey: true,
code: 'KeyK',
});
expect(
screen.queryByPlaceholderText('Search all dashboards'),
).toBeInTheDocument();

// hide Omnibar
// Close Omnibar
fireEvent.keyDown(screen.getByTestId('test'), {
metaKey: true,
code: 'KeyS',
key: 'Escape',
code: 'Escape',
});
expect(
screen.queryByPlaceholderText('Search all dashboards'),
Expand Down
12 changes: 11 additions & 1 deletion superset-frontend/src/components/OmniContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const OmniModal = styled(Modal)`

.ant-modal-body {
padding: 0;
overflow: visible;
}
`;

Expand All @@ -47,7 +48,16 @@ export default function OmniContainer({ logEvent }: Props) {
function handleKeydown(event: KeyboardEvent) {
if (!isFeatureEnabled(FeatureFlag.OMNIBAR)) return;
const controlOrCommand = event.ctrlKey || event.metaKey;
const isOk = ['KeyK', 'KeyS'].includes(event.code); // valid keys "s" or "k"
const isOk = ['KeyK'].includes(event.code);
const isEsc = event.key === 'Escape';
if (isEsc && showOmni.current) {
logEvent(LOG_ACTIONS_OMNIBAR_TRIGGERED, {
show_omni: false,
});
showOmni.current = false;
setShowModal(false);
return;
}
if (controlOrCommand && isOk) {
logEvent(LOG_ACTIONS_OMNIBAR_TRIGGERED, {
show_omni: !!showOmni.current,
Expand Down