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

[8.6] [Discover] Support case-insensitive search in Document Viewer (#148312) #148429

Merged
merged 2 commits into from Jan 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -8,26 +8,45 @@

import React from 'react';
import { render } from 'enzyme';
import { stubLogstashDataView as dataView } from '@kbn/data-plugin/common/stubs';
import { FieldName } from './field_name';

// Note that it currently provides just 2 basic tests, there should be more, but
// the components involved will soon change
test('FieldName renders a string field by providing fieldType and fieldName', () => {
const component = render(<FieldName fieldType="string" fieldName="test" />);
expect(component).toMatchSnapshot();
});
describe('FieldName', function () {
test('renders a string field by providing fieldType and fieldName', () => {
const component = render(<FieldName fieldType="string" fieldName="test" />);
expect(component).toMatchSnapshot();
});

test('FieldName renders a number field by providing a field record', () => {
const component = render(<FieldName fieldName={'test.test.test'} fieldType={'number'} />);
expect(component).toMatchSnapshot();
});
test('renders a number field by providing a field record', () => {
const component = render(<FieldName fieldName={'test.test.test'} fieldType={'number'} />);
expect(component).toMatchSnapshot();
});

test('FieldName renders a geo field', () => {
const component = render(<FieldName fieldName={'test.test.test'} fieldType={'geo_point'} />);
expect(component).toMatchSnapshot();
});
test('renders a geo field', () => {
const component = render(<FieldName fieldName={'test.test.test'} fieldType={'geo_point'} />);
expect(component).toMatchSnapshot();
});

test('renders unknown field', () => {
const component = render(<FieldName fieldName={'test.test.test'} />);
expect(component).toMatchSnapshot();
});

test('renders with a search highlight', () => {
const component = render(
<FieldName fieldName={'test.test.test'} fieldType={'number'} highlight="te" />
);
expect(component).toMatchSnapshot();
});

test('FieldName renders unknown field', () => {
const component = render(<FieldName fieldName={'test.test.test'} />);
expect(component).toMatchSnapshot();
test('renders when mapping is provided', () => {
const component = render(
<FieldName
fieldName="test"
fieldType="number"
fieldMapping={dataView.getFieldByName('bytes')}
/>
);
expect(component).toMatchSnapshot();
});
});
Expand Up @@ -8,7 +8,7 @@

import React, { Fragment } from 'react';
import './field_name.scss';
import { EuiBadge, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';
import { EuiBadge, EuiFlexGroup, EuiFlexItem, EuiToolTip, EuiHighlight } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { FieldIcon, FieldIconProps } from '@kbn/react-field';
Expand All @@ -22,6 +22,7 @@ interface Props {
fieldMapping?: DataViewField;
fieldIconProps?: Omit<FieldIconProps, 'type'>;
scripted?: boolean;
highlight?: string;
}

export function FieldName({
Expand All @@ -30,6 +31,7 @@ export function FieldName({
fieldType,
fieldIconProps,
scripted = false,
highlight = '',
}: Props) {
const typeName = getFieldTypeName(fieldType);
const displayName =
Expand All @@ -52,7 +54,7 @@ export function FieldName({
delay="long"
anchorClassName="eui-textBreakAll"
>
<span>{displayName}</span>
<EuiHighlight search={highlight}>{displayName}</EuiHighlight>
</EuiToolTip>
</EuiFlexItem>

Expand Down
Expand Up @@ -238,7 +238,7 @@ export const DocViewerTable = ({
} else {
const fieldMapping = mapping(curFieldName);
const displayName = fieldMapping?.displayName ?? curFieldName;
if (displayName.includes(searchText)) {
if (displayName.toLowerCase().includes(searchText.toLowerCase())) {
// filter only unpinned fields
acc.restItems.push(fieldToItem(curFieldName));
}
Expand Down Expand Up @@ -270,6 +270,7 @@ export const DocViewerTable = ({
const headers = [
!isSingleDocView && (
<EuiTableHeaderCell
key="header-cell-actions"
align="left"
width={showActionsInsideTableCell ? 150 : 62}
isSorted={false}
Expand All @@ -284,14 +285,14 @@ export const DocViewerTable = ({
</EuiText>
</EuiTableHeaderCell>
),
<EuiTableHeaderCell align="left" width="30%" isSorted={false}>
<EuiTableHeaderCell key="header-cell-name" align="left" width="30%" isSorted={false}>
<EuiText size="xs">
<strong>
<FormattedMessage id="discover.fieldChooser.discoverField.name" defaultMessage="Field" />
</strong>
</EuiText>
</EuiTableHeaderCell>,
<EuiTableHeaderCell align="left" isSorted={false}>
<EuiTableHeaderCell key="header-cell-value" align="left" isSorted={false}>
<EuiText size="xs">
<strong>
<FormattedMessage id="discover.fieldChooser.discoverField.value" defaultMessage="Value" />
Expand All @@ -302,10 +303,11 @@ export const DocViewerTable = ({

const renderRows = useCallback(
(items: FieldRecord[]) => {
const highlight = searchText?.toLowerCase();
return items.map(
({
action: { flattenedField, onFilter },
field: { field, fieldMapping, displayName, fieldType, scripted, pinned },
field: { field, fieldMapping, fieldType, scripted, pinned },
value: { formattedValue, ignored },
}: FieldRecord) => {
return (
Expand Down Expand Up @@ -341,10 +343,11 @@ export const DocViewerTable = ({
mobileOptions={MOBILE_OPTIONS}
>
<FieldName
fieldName={displayName}
fieldName={field}
fieldType={fieldType}
fieldMapping={fieldMapping}
scripted={scripted}
highlight={highlight}
/>
</EuiTableRowCell>
<EuiTableRowCell
Expand All @@ -366,7 +369,7 @@ export const DocViewerTable = ({
}
);
},
[onToggleColumn, onTogglePinned, isSingleDocView, showActionsInsideTableCell]
[onToggleColumn, onTogglePinned, isSingleDocView, showActionsInsideTableCell, searchText]
);

const rowElements = [
Expand Down