Skip to content

Commit

Permalink
[Discover][DocViewer] Change logic. Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Apr 4, 2024
1 parent 6ccf117 commit 339c024
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ describe('Discover flyout', function () {
expect(props.setExpandedDoc).not.toHaveBeenCalled();
});

it('should not navigate with arrow keys through documents if an input is in focus', async () => {
mockFlyoutCustomization.Content = () => {
return <input data-test-subj="flyoutCustomInput" />;
};

const { component, props } = await mountComponent({});
findTestSubject(component, 'flyoutCustomInput').simulate('keydown', {
key: 'ArrowRight',
});
findTestSubject(component, 'flyoutCustomInput').simulate('keydown', {
key: 'ArrowLeft',
});
expect(props.setExpandedDoc).not.toHaveBeenCalled();
});

it('should not render single/surrounding views for text based', async () => {
const { component } = await mountComponent({
query: { esql: 'FROM indexpattern' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React, { useMemo, useCallback } from 'react';
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import type { DataView } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -99,6 +100,10 @@ export function DiscoverGridFlyout({

const onKeyDown = useCallback(
(ev: React.KeyboardEvent) => {
const nodeName = get(ev, 'target.nodeName', null);
if (typeof nodeName === 'string' && nodeName.toLowerCase() === 'input') {
return;
}
if (ev.key === keys.ARROW_LEFT || ev.key === keys.ARROW_RIGHT) {
ev.preventDefault();
ev.stopPropagation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ export const DocViewerTable = ({
[storage]
);

const handleKeyDown = useCallback((event) => {
// prevents the flyout keydown handler from being triggered in order to switch between data grid rows
event.stopPropagation();
}, []);

const { pinnedItems, restItems } = Object.keys(flattened)
.sort((fieldA, fieldB) => {
const mappingA = mapping(fieldA);
Expand Down Expand Up @@ -421,7 +416,6 @@ export const DocViewerTable = ({
<EuiFieldSearch
aria-label={searchPlaceholder}
fullWidth
onKeyDown={handleKeyDown}
onChange={handleOnChange}
placeholder={searchPlaceholder}
value={searchText}
Expand Down

0 comments on commit 339c024

Please sign in to comment.