Skip to content

Commit

Permalink
Adds a column for engine language to the engines table. (#84004)
Browse files Browse the repository at this point in the history
* Adds a column for engine language to the engines table.

* Handle Meta Engines and Universal language types

Co-authored-by: Jason Stoltzfus <jastoltz24@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 23, 2020
1 parent f4de383 commit 18e0476
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ import { EnginesTable } from './engines_table';
describe('EnginesTable', () => {
const onPaginate = jest.fn(); // onPaginate updates the engines API call upstream

const wrapper = mountWithIntl(
<EnginesTable
data={[
{
name: 'test-engine',
created_at: 'Fri, 1 Jan 1970 12:00:00 +0000',
document_count: 99999,
field_count: 10,
},
]}
pagination={{
totalEngines: 50,
pageIndex: 0,
onPaginate,
}}
/>
);
const data = [
{
name: 'test-engine',
created_at: 'Fri, 1 Jan 1970 12:00:00 +0000',
language: 'English',
isMeta: false,
document_count: 99999,
field_count: 10,
},
];
const pagination = {
totalEngines: 50,
pageIndex: 0,
onPaginate,
};
const props = {
data,
pagination,
};

const wrapper = mountWithIntl(<EnginesTable {...props} />);
const table = wrapper.find(EuiBasicTable);

it('renders', () => {
Expand All @@ -42,7 +46,8 @@ describe('EnginesTable', () => {

const tableContent = table.text();
expect(tableContent).toContain('test-engine');
expect(tableContent).toContain('January 1, 1970');
expect(tableContent).toContain('Jan 1, 1970');
expect(tableContent).toContain('English');
expect(tableContent).toContain('99,999');
expect(tableContent).toContain('10');

Expand Down Expand Up @@ -80,4 +85,57 @@ describe('EnginesTable', () => {

expect(emptyTable.prop('pagination').pageIndex).toEqual(0);
});

describe('language field', () => {
it('renders language when available', () => {
const wrapperWithLanguage = mountWithIntl(
<EnginesTable
data={[
{
...data[0],
language: 'German',
isMeta: false,
},
]}
pagination={pagination}
/>
);
const tableContent = wrapperWithLanguage.find(EuiBasicTable).text();
expect(tableContent).toContain('German');
});

it('renders the language as Universal if no language is set', () => {
const wrapperWithLanguage = mountWithIntl(
<EnginesTable
data={[
{
...data[0],
language: null,
isMeta: false,
},
]}
pagination={pagination}
/>
);
const tableContent = wrapperWithLanguage.find(EuiBasicTable).text();
expect(tableContent).toContain('Universal');
});

it('renders no language text if the engine is a Meta Engine', () => {
const wrapperWithLanguage = mountWithIntl(
<EnginesTable
data={[
{
...data[0],
language: null,
isMeta: true,
},
]}
pagination={pagination}
/>
);
const tableContent = wrapperWithLanguage.find(EuiBasicTable).text();
expect(tableContent).not.toContain('Universal');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import { EuiLinkTo } from '../../../shared/react_router_helpers';
import { getEngineRoute } from '../../routes';

import { ENGINES_PAGE_SIZE } from '../../../../../common/constants';
import { UNIVERSAL_LANGUAGE } from '../../constants';

interface EnginesTableData {
name: string;
created_at: string;
document_count: number;
field_count: number;
language: string | null;
isMeta: boolean;
}
interface EnginesTablePagination {
totalEngines: number;
Expand Down Expand Up @@ -84,10 +87,22 @@ export const EnginesTable: React.FC<EnginesTableProps> = ({
),
dataType: 'string',
render: (dateString: string) => (
// e.g., January 1, 1970
<FormattedDate value={new Date(dateString)} year="numeric" month="long" day="numeric" />
// e.g., Jan 1, 1970
<FormattedDate value={new Date(dateString)} year="numeric" month="short" day="numeric" />
),
},
{
field: 'language',
name: i18n.translate(
'xpack.enterpriseSearch.appSearch.enginesOverview.table.column.language',
{
defaultMessage: 'Language',
}
),
dataType: 'string',
render: (language: string, engine: EnginesTableData) =>
engine.isMeta ? '' : language || UNIVERSAL_LANGUAGE,
},
{
field: 'document_count',
name: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';

// This is the value used for an engine that has no explicit 'language' set, it works
// with all languages.
export const UNIVERSAL_LANGUAGE = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.universalLanguage',
{
defaultMessage: 'Universal',
}
);

0 comments on commit 18e0476

Please sign in to comment.