From 71a4628a2f5f43a882ba69c174b475a796ef3186 Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Mon, 13 Apr 2020 18:43:13 +0300 Subject: [PATCH 1/4] MIgrated indexed_fields_table to typescript. --- .../indexed_fields_table.test.tsx.snap} | 12 +- .../table.test.tsx.snap} | 13 +- .../components/table/{index.js => index.ts} | 0 .../components/table/table.js | 231 --------------- .../table.test.js => table.test.tsx} | 72 +++-- .../components/table/table.tsx | 274 ++++++++++++++++++ .../{index.js => index.ts} | 0 ....test.js => indexed_fields_table.test.tsx} | 46 ++- ...elds_table.js => indexed_fields_table.tsx} | 49 ++-- ...ormat.test.js => get_field_format.test.ts} | 17 +- ...et_field_format.js => get_field_format.ts} | 3 +- .../lib/{index.js => index.ts} | 0 .../indexed_fields_table/types.ts | 25 ++ .../public/index_patterns/fields/field.ts | 1 + 14 files changed, 436 insertions(+), 307 deletions(-) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/{__jest__/__snapshots__/indexed_fields_table.test.js.snap => __snapshots__/indexed_fields_table.test.tsx.snap} (91%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/{__jest__/__snapshots__/table.test.js.snap => __snapshots__/table.test.tsx.snap} (92%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/{index.js => index.ts} (100%) delete mode 100644 src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.js rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/{__jest__/table.test.js => table.test.tsx} (66%) create mode 100644 src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/{index.js => index.ts} (100%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/{__jest__/indexed_fields_table.test.js => indexed_fields_table.test.tsx} (70%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/{indexed_fields_table.js => indexed_fields_table.tsx} (68%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/{__jest__/get_field_format.test.js => get_field_format.test.ts} (74%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/{get_field_format.js => get_field_format.ts} (84%) rename src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/{index.js => index.ts} (100%) create mode 100644 src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/types.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__jest__/__snapshots__/indexed_fields_table.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap similarity index 91% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__jest__/__snapshots__/indexed_fields_table.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap index dc77fe6c8a69d6..e6c81a3f67ec82 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__jest__/__snapshots__/indexed_fields_table.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__snapshots__/indexed_fields_table.test.tsx.snap @@ -16,10 +16,11 @@ exports[`IndexedFieldsTable should filter based on the query bar 1`] = ` "excluded": false, "format": undefined, "indexPattern": undefined, - "info": undefined, + "info": Array [], "name": "Elastic", "routes": undefined, "searchable": true, + "type": "name", }, ] } @@ -43,7 +44,7 @@ exports[`IndexedFieldsTable should filter based on the type filter 1`] = ` "excluded": false, "format": undefined, "indexPattern": undefined, - "info": undefined, + "info": Array [], "name": "timestamp", "routes": undefined, "type": "date", @@ -70,17 +71,18 @@ exports[`IndexedFieldsTable should render normally 1`] = ` "excluded": false, "format": undefined, "indexPattern": undefined, - "info": undefined, + "info": Array [], "name": "Elastic", "routes": undefined, "searchable": true, + "type": "name", }, Object { "displayName": "timestamp", "excluded": false, "format": undefined, "indexPattern": undefined, - "info": undefined, + "info": Array [], "name": "timestamp", "routes": undefined, "type": "date", @@ -90,7 +92,7 @@ exports[`IndexedFieldsTable should render normally 1`] = ` "excluded": false, "format": undefined, "indexPattern": undefined, - "info": undefined, + "info": Array [], "name": "conflictingField", "routes": undefined, "type": "conflict", diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__jest__/__snapshots__/table.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap similarity index 92% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__jest__/__snapshots__/table.test.js.snap rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap index f3aa2c5da4b67b..2d51b1722cfb21 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__jest__/__snapshots__/table.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__snapshots__/table.test.tsx.snap @@ -98,19 +98,26 @@ exports[`Table should render normally 1`] = ` Array [ Object { "displayName": "Elastic", - "info": Object {}, + "excluded": false, + "format": "", + "info": Array [], "name": "Elastic", "searchable": true, + "type": "name", }, Object { "displayName": "timestamp", - "info": Object {}, + "excluded": false, + "format": "YYYY-MM-DD", + "info": Array [], "name": "timestamp", "type": "date", }, Object { "displayName": "conflictingField", - "info": Object {}, + "excluded": false, + "format": "", + "info": Array [], "name": "conflictingField", "type": "conflict", }, diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/index.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.js deleted file mode 100644 index 29e160cf1c1826..00000000000000 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.js +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import React, { PureComponent } from 'react'; -import PropTypes from 'prop-types'; - -import { EuiIcon, EuiInMemoryTable, EuiIconTip } from '@elastic/eui'; - -import { i18n } from '@kbn/i18n'; - -export class Table extends PureComponent { - static propTypes = { - indexPattern: PropTypes.object.isRequired, - items: PropTypes.array.isRequired, - editField: PropTypes.func.isRequired, - }; - - renderBooleanTemplate(value, label) { - return value ? : ; - } - - renderFieldName(name, field) { - const { indexPattern } = this.props; - - const infoLabel = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.additionalInfoAriaLabel', - { defaultMessage: 'Additional field information' } - ); - const timeLabel = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.primaryTimeAriaLabel', - { defaultMessage: 'Primary time field' } - ); - const timeContent = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.primaryTimeTooltip', - { defaultMessage: 'This field represents the time that events occurred.' } - ); - - return ( - - {name} - {field.info && field.info.length ? ( - -   - ( -
{info}
- ))} - /> -
- ) : null} - {indexPattern.timeFieldName === name ? ( - -   - - - ) : null} -
- ); - } - - renderFieldType(type, isConflict) { - const label = i18n.translate('kbn.management.editIndexPattern.fields.table.multiTypeAria', { - defaultMessage: 'Multiple type field', - }); - const content = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.multiTypeTooltip', - { - defaultMessage: - 'The type of this field changes across indices. It is unavailable for many analysis functions.', - } - ); - - return ( - - {type} - {isConflict ? ( - -   - - - ) : ( - '' - )} - - ); - } - - render() { - const { items, editField } = this.props; - - const pagination = { - initialPageSize: 10, - pageSizeOptions: [5, 10, 25, 50], - }; - - const columns = [ - { - field: 'displayName', - name: i18n.translate('kbn.management.editIndexPattern.fields.table.nameHeader', { - defaultMessage: 'Name', - }), - dataType: 'string', - sortable: true, - render: (value, field) => { - return this.renderFieldName(value, field); - }, - width: '38%', - 'data-test-subj': 'indexedFieldName', - }, - { - field: 'type', - name: i18n.translate('kbn.management.editIndexPattern.fields.table.typeHeader', { - defaultMessage: 'Type', - }), - dataType: 'string', - sortable: true, - render: value => { - return this.renderFieldType(value, value === 'conflict'); - }, - 'data-test-subj': 'indexedFieldType', - }, - { - field: 'format', - name: i18n.translate('kbn.management.editIndexPattern.fields.table.formatHeader', { - defaultMessage: 'Format', - }), - dataType: 'string', - sortable: true, - }, - { - field: 'searchable', - name: i18n.translate('kbn.management.editIndexPattern.fields.table.searchableHeader', { - defaultMessage: 'Searchable', - }), - description: i18n.translate( - 'kbn.management.editIndexPattern.fields.table.searchableDescription', - { defaultMessage: 'These fields can be used in the filter bar' } - ), - dataType: 'boolean', - sortable: true, - render: value => - this.renderBooleanTemplate( - value, - i18n.translate('kbn.management.editIndexPattern.fields.table.isSearchableAria', { - defaultMessage: 'Is searchable', - }) - ), - }, - { - field: 'aggregatable', - name: i18n.translate('kbn.management.editIndexPattern.fields.table.aggregatableLabel', { - defaultMessage: 'Aggregatable', - }), - description: i18n.translate( - 'kbn.management.editIndexPattern.fields.table.aggregatableDescription', - { defaultMessage: 'These fields can be used in visualization aggregations' } - ), - dataType: 'boolean', - sortable: true, - render: value => - this.renderBooleanTemplate( - value, - i18n.translate('kbn.management.editIndexPattern.fields.table.isAggregatableAria', { - defaultMessage: 'Is aggregatable', - }) - ), - }, - { - field: 'excluded', - name: i18n.translate('kbn.management.editIndexPattern.fields.table.excludedLabel', { - defaultMessage: 'Excluded', - }), - description: i18n.translate( - 'kbn.management.editIndexPattern.fields.table.excludedDescription', - { defaultMessage: 'Fields that are excluded from _source when it is fetched' } - ), - dataType: 'boolean', - sortable: true, - render: value => - this.renderBooleanTemplate( - value, - i18n.translate('kbn.management.editIndexPattern.fields.table.isExcludedAria', { - defaultMessage: 'Is excluded', - }) - ), - }, - { - name: '', - actions: [ - { - name: i18n.translate('kbn.management.editIndexPattern.fields.table.editLabel', { - defaultMessage: 'Edit', - }), - description: i18n.translate( - 'kbn.management.editIndexPattern.fields.table.editDescription', - { defaultMessage: 'Edit' } - ), - icon: 'pencil', - onClick: editField, - type: 'icon', - 'data-test-subj': 'editFieldFormat', - }, - ], - width: '40px', - }, - ]; - - return ( - - ); - } -} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__jest__/table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx similarity index 66% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__jest__/table.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx index 4fd9ef7485bdf1..ab1d96bf60a33f 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/__jest__/table.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx @@ -19,31 +19,53 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; - -import { Table } from '../table'; +import { IIndexPattern } from '../../../../../../../../../../../plugins/data/public'; +import { IndexedFieldItem } from '../../types'; +import { Table } from './table'; const indexPattern = { timeFieldName: 'timestamp', -}; - -const items = [ - { name: 'Elastic', displayName: 'Elastic', searchable: true, info: {} }, - { name: 'timestamp', displayName: 'timestamp', type: 'date', info: {} }, - { name: 'conflictingField', displayName: 'conflictingField', type: 'conflict', info: {} }, +} as IIndexPattern; + +const items: IndexedFieldItem[] = [ + { + name: 'Elastic', + displayName: 'Elastic', + searchable: true, + info: [], + type: 'name', + excluded: false, + format: '', + }, + { + name: 'timestamp', + displayName: 'timestamp', + type: 'date', + info: [], + excluded: false, + format: 'YYYY-MM-DD', + }, + { + name: 'conflictingField', + displayName: 'conflictingField', + type: 'conflict', + info: [], + excluded: false, + format: '', + }, ]; describe('Table', () => { - it('should render normally', async () => { - const component = shallowWithI18nProvider( + test('should render normally', async () => { + const component = shallow( {}} /> ); expect(component).toMatchSnapshot(); }); - it('should render normal field name', async () => { - const component = shallowWithI18nProvider( + test('should render normal field name', async () => { + const component = shallow(
{}} /> ); @@ -51,8 +73,8 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - it('should render timestamp field name', async () => { - const component = shallowWithI18nProvider( + test('should render timestamp field name', async () => { + const component = shallow(
{}} /> ); @@ -60,8 +82,8 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - it('should render the boolean template (true)', async () => { - const component = shallowWithI18nProvider( + test('should render the boolean template (true)', async () => { + const component = shallow(
{}} /> ); @@ -69,8 +91,8 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - it('should render the boolean template (false)', async () => { - const component = shallowWithI18nProvider( + test('should render the boolean template (false)', async () => { + const component = shallow(
{}} /> ); @@ -78,8 +100,8 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - it('should render normal type', async () => { - const component = shallowWithI18nProvider( + test('should render normal type', async () => { + const component = shallow(
{}} /> ); @@ -87,8 +109,8 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - it('should render conflicting type', async () => { - const component = shallowWithI18nProvider( + test('should render conflicting type', async () => { + const component = shallow(
{}} /> ); @@ -96,10 +118,10 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - it('should allow edits', () => { + test('should allow edits', () => { const editField = jest.fn(); - const component = shallowWithI18nProvider( + const component = shallow(
); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx new file mode 100644 index 00000000000000..880c0b541040bd --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx @@ -0,0 +1,274 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React, { PureComponent } from 'react'; + +import { EuiIcon, EuiInMemoryTable, EuiIconTip, EuiBasicTableColumn } from '@elastic/eui'; + +import { i18n } from '@kbn/i18n'; + +import { IIndexPattern } from '../../../../../../../../../../../plugins/data/public'; +import { IndexedFieldItem } from '../../types'; + +// localized labels +const infoLabel = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.additionalInfoAriaLabel', + { defaultMessage: 'Additional field information' } +); + +const timeLabel = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.primaryTimeAriaLabel', + { defaultMessage: 'Primary time field' } +); + +const timeContent = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.primaryTimeTooltip', + { defaultMessage: 'This field represents the time that events occurred.' } +); + +const label = i18n.translate('kbn.management.editIndexPattern.fields.table.multiTypeAria', { + defaultMessage: 'Multiple type field', +}); + +const content = i18n.translate('kbn.management.editIndexPattern.fields.table.multiTypeTooltip', { + defaultMessage: + 'The type of this field changes across indices. It is unavailable for many analysis functions.', +}); + +const displayNameColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.nameHeader', + { + defaultMessage: 'Name', + } +); + +const typeNameColumn = i18n.translate('kbn.management.editIndexPattern.fields.table.typeHeader', { + defaultMessage: 'Type', +}); + +const formatNameColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.formatHeader', + { + defaultMessage: 'Format', + } +); + +const searchableNameColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.searchableHeader', + { + defaultMessage: 'Searchable', + } +); + +const searchableDescriptionColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.searchableDescription', + { defaultMessage: 'These fields can be used in the filter bar' } +); + +const isSearchableLabel = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.isSearchableAria', + { + defaultMessage: 'Is searchable', + } +); + +const aggregatableNameColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.aggregatableLabel', + { + defaultMessage: 'Aggregatable', + } +); + +const aggregatableDescriptionColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.aggregatableDescription', + { defaultMessage: 'These fields can be used in visualization aggregations' } +); + +const isAggregatableLabel = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.isAggregatableAria', + { + defaultMessage: 'Is aggregatable', + } +); + +const excludedNameColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.excludedLabel', + { + defaultMessage: 'Excluded', + } +); + +const excludedDescriptionColumn = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.excludedDescription', + { defaultMessage: 'Fields that are excluded from _source when it is fetched' } +); + +const isExcludedLabel = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.isExcludedAria', + { + defaultMessage: 'Is excluded', + } +); + +const editNameAction = i18n.translate('kbn.management.editIndexPattern.fields.table.editLabel', { + defaultMessage: 'Edit', +}); + +const editDescriptionAction = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.editDescription', + { defaultMessage: 'Edit' } +); + +interface IndexedFieldProps { + indexPattern: IIndexPattern; + items: IndexedFieldItem[]; + editField: (field: IndexedFieldItem) => void; +} + +export class Table extends PureComponent { + renderBooleanTemplate(value: string, arialLabel: string) { + return value ? : ; + } + + renderFieldName(name: string, field: IndexedFieldItem) { + const { indexPattern } = this.props; + + return ( + + {name} + {field.info && field.info.length ? ( + +   + ( +
{info}
+ ))} + /> +
+ ) : null} + {indexPattern.timeFieldName === name ? ( + +   + + + ) : null} +
+ ); + } + + renderFieldType(type: string, isConflict: boolean) { + return ( + + {type} + {isConflict ? ( + +   + + + ) : ( + '' + )} + + ); + } + + render() { + const { items, editField } = this.props; + + const pagination = { + initialPageSize: 10, + pageSizeOptions: [5, 10, 25, 50], + }; + + const columns: Array> = [ + { + field: 'displayName', + name: displayNameColumn, + dataType: 'string', + sortable: true, + render: (value: string, field: IndexedFieldItem) => { + return this.renderFieldName(value, field); + }, + width: '38%', + 'data-test-subj': 'indexedFieldName', + }, + { + field: 'type', + name: typeNameColumn, + dataType: 'string', + sortable: true, + render: (value: string) => { + return this.renderFieldType(value, value === 'conflict'); + }, + 'data-test-subj': 'indexedFieldType', + }, + { + field: 'format', + name: formatNameColumn, + dataType: 'string', + sortable: true, + }, + { + field: 'searchable', + name: searchableNameColumn, + description: searchableDescriptionColumn, + dataType: 'boolean', + sortable: true, + render: (value: string) => this.renderBooleanTemplate(value, isSearchableLabel), + }, + { + field: 'aggregatable', + name: aggregatableNameColumn, + description: aggregatableDescriptionColumn, + dataType: 'boolean', + sortable: true, + render: (value: string) => this.renderBooleanTemplate(value, isAggregatableLabel), + }, + { + field: 'excluded', + name: excludedNameColumn, + description: excludedDescriptionColumn, + dataType: 'boolean', + sortable: true, + render: (value: string) => this.renderBooleanTemplate(value, isExcludedLabel), + }, + { + name: '', + actions: [ + { + name: editNameAction, + description: editDescriptionAction, + icon: 'pencil', + onClick: editField, + type: 'icon', + 'data-test-subj': 'editFieldFormat', + }, + ], + width: '40px', + }, + ]; + + return ( + + ); + } +} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/index.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__jest__/indexed_fields_table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx similarity index 70% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__jest__/indexed_fields_table.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx index 26e271ea477daf..8e877c4fe8a16e 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/__jest__/indexed_fields_table.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx @@ -19,8 +19,8 @@ import React from 'react'; import { shallow } from 'enzyme'; - -import { IndexedFieldsTable } from '../indexed_fields_table'; +import { IndexPatternField, IIndexPattern } from '../../../../../../../../../plugins/data/public'; +import { IndexedFieldsTable } from './indexed_fields_table'; jest.mock('@elastic/eui', () => ({ EuiFlexGroup: 'eui-flex-group', @@ -29,7 +29,7 @@ jest.mock('@elastic/eui', () => ({ EuiInMemoryTable: 'eui-in-memory-table', })); -jest.mock('../components/table', () => ({ +jest.mock('./components/table', () => ({ // Note: this seems to fix React complaining about non lowercase attributes Table: () => { return 'table'; @@ -37,27 +37,37 @@ jest.mock('../components/table', () => ({ })); const helpers = { - redirectToRoute: () => {}, + redirectToRoute: (obj: any, route: string) => {}, + getFieldInfo: () => [], }; const fields = [ - { name: 'Elastic', displayName: 'Elastic', searchable: true }, + { + name: 'Elastic', + displayName: 'Elastic', + searchable: true, + type: 'name', + }, { name: 'timestamp', displayName: 'timestamp', type: 'date' }, { name: 'conflictingField', displayName: 'conflictingField', type: 'conflict' }, -]; +] as IndexPatternField[]; -const indexPattern = { +const indexPattern = ({ getNonScriptedFields: () => fields, -}; +} as unknown) as IIndexPattern; describe('IndexedFieldsTable', () => { - it('should render normally', async () => { + test('should render normally', async () => { const component = shallow( {}} + fieldWildcardMatcher={() => { + return () => false; + }} + indexedFieldTypeFilter="" + fieldFilter="" /> ); @@ -67,13 +77,17 @@ describe('IndexedFieldsTable', () => { expect(component).toMatchSnapshot(); }); - it('should filter based on the query bar', async () => { + test('should filter based on the query bar', async () => { const component = shallow( {}} + fieldWildcardMatcher={() => { + return () => false; + }} + indexedFieldTypeFilter="" + fieldFilter="" /> ); @@ -84,13 +98,17 @@ describe('IndexedFieldsTable', () => { expect(component).toMatchSnapshot(); }); - it('should filter based on the type filter', async () => { + test('should filter based on the type filter', async () => { const component = shallow( {}} + fieldWildcardMatcher={() => { + return () => false; + }} + indexedFieldTypeFilter="" + fieldFilter="" /> ); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx similarity index 68% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx index 652efbe98067f1..47b2c4c7358010 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx @@ -18,26 +18,33 @@ */ import React, { Component } from 'react'; -import PropTypes from 'prop-types'; import { createSelector } from 'reselect'; - +import { IndexPatternField, IIndexPattern } from '../../../../../../../../../plugins/data/public'; import { Table } from './components/table'; import { getFieldFormat } from './lib'; +import { IndexedFieldItem } from './types'; -export class IndexedFieldsTable extends Component { - static propTypes = { - fields: PropTypes.array.isRequired, - indexPattern: PropTypes.object.isRequired, - fieldFilter: PropTypes.string, - indexedFieldTypeFilter: PropTypes.string, - helpers: PropTypes.shape({ - redirectToRoute: PropTypes.func.isRequired, - getFieldInfo: PropTypes.func, - }), - fieldWildcardMatcher: PropTypes.func.isRequired, +interface IndexedFieldsTableProps { + fields: IndexPatternField[]; + indexPattern: IIndexPattern; + fieldFilter: string; + indexedFieldTypeFilter: string; + helpers: { + redirectToRoute: (obj: any, route: string) => void; + getFieldInfo: (indexPattern: IIndexPattern, field: string) => string[]; }; + fieldWildcardMatcher: (filters: any[]) => (val: any) => boolean; +} + +interface IndexedFieldsTableState { + fields: IndexedFieldItem[]; +} - constructor(props) { +export class IndexedFieldsTable extends Component< + IndexedFieldsTableProps, + IndexedFieldsTableState +> { + constructor(props: IndexedFieldsTableProps) { super(props); this.state = { @@ -45,7 +52,7 @@ export class IndexedFieldsTable extends Component { }; } - UNSAFE_componentWillReceiveProps(nextProps) { + UNSAFE_componentWillReceiveProps(nextProps: IndexedFieldsTableProps) { if (nextProps.fields !== this.props.fields) { this.setState({ fields: this.mapFields(nextProps.fields), @@ -53,10 +60,11 @@ export class IndexedFieldsTable extends Component { } } - mapFields(fields) { + mapFields(fields: IndexPatternField[]): IndexedFieldItem[] { const { indexPattern, fieldWildcardMatcher, helpers } = this.props; const sourceFilters = - indexPattern.sourceFilters && indexPattern.sourceFilters.map(f => f.value); + indexPattern.sourceFilters && + indexPattern.sourceFilters.map((f: Record) => f.value); const fieldWildcardMatch = fieldWildcardMatcher(sourceFilters || []); return ( @@ -77,9 +85,10 @@ export class IndexedFieldsTable extends Component { } getFilteredFields = createSelector( - state => state.fields, - (state, props) => props.fieldFilter, - (state, props) => props.indexedFieldTypeFilter, + (state: IndexedFieldsTableState) => state.fields, + (state: IndexedFieldsTableState, props: IndexedFieldsTableProps) => props.fieldFilter, + (state: IndexedFieldsTableState, props: IndexedFieldsTableProps) => + props.indexedFieldTypeFilter, (fields, fieldFilter, indexedFieldTypeFilter) => { if (fieldFilter) { const normalizedFieldFilter = fieldFilter.toLowerCase(); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/__jest__/get_field_format.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.test.ts similarity index 74% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/__jest__/get_field_format.test.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.test.ts index 7090f701999197..fc7477c074ac2d 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/__jest__/get_field_format.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.test.ts @@ -17,9 +17,10 @@ * under the License. */ -import { getFieldFormat } from '../get_field_format'; +import { IIndexPattern } from '../../../../../../../../../../plugins/data/public'; +import { getFieldFormat } from './get_field_format'; -const indexPattern = { +const indexPattern = ({ fieldFormatMap: { Elastic: { type: { @@ -27,26 +28,26 @@ const indexPattern = { }, }, }, -}; +} as unknown) as IIndexPattern; describe('getFieldFormat', () => { - it('should handle no arguments', () => { + test('should handle no arguments', () => { expect(getFieldFormat()).toEqual(''); }); - it('should handle no field name', () => { + test('should handle no field name', () => { expect(getFieldFormat(indexPattern)).toEqual(''); }); - it('should handle empty name', () => { + test('should handle empty name', () => { expect(getFieldFormat(indexPattern, '')).toEqual(''); }); - it('should handle undefined field name', () => { + test('should handle undefined field name', () => { expect(getFieldFormat(indexPattern, 'none')).toEqual(undefined); }); - it('should retrieve field format', () => { + test('should retrieve field format', () => { expect(getFieldFormat(indexPattern, 'Elastic')).toEqual('string'); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.ts similarity index 84% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.ts index 9402694bb13718..1d6f267430f076 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/get_field_format.ts @@ -18,8 +18,9 @@ */ import { get } from 'lodash'; +import { IIndexPattern } from '../../../../../../../../../../plugins/data/public'; -export function getFieldFormat(indexPattern, fieldName) { +export function getFieldFormat(indexPattern?: IIndexPattern, fieldName?: string): string { return indexPattern && fieldName ? get(indexPattern, ['fieldFormatMap', fieldName, 'type', 'title']) : ''; diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/index.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/index.ts similarity index 100% rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/index.js rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/lib/index.ts diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/types.ts b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/types.ts new file mode 100644 index 00000000000000..f27f4608bf5d58 --- /dev/null +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/types.ts @@ -0,0 +1,25 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { IFieldType } from '../../../../../../../../../plugins/data/public'; + +export interface IndexedFieldItem extends IFieldType { + info: string[]; + excluded: boolean; +} diff --git a/src/plugins/data/public/index_patterns/fields/field.ts b/src/plugins/data/public/index_patterns/fields/field.ts index 1554565d1403ee..03a5b61f9b116b 100644 --- a/src/plugins/data/public/index_patterns/fields/field.ts +++ b/src/plugins/data/public/index_patterns/fields/field.ts @@ -44,6 +44,7 @@ export class Field implements IFieldType { scripted?: boolean; subType?: IFieldSubType; displayName?: string; + indexPattern?: IndexPattern; format: any; routes: Record = { edit: '/management/kibana/index_patterns/{{indexPattern.id}}/field/{{name}}', From 98c6b3a8f6f547f943ab87ba458a9c6f63cef68d Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Tue, 14 Apr 2020 11:27:53 +0300 Subject: [PATCH 2/4] Updated docs --- ...gins-data-public.indexpatternfield.indexpattern.md | 11 +++++++++++ ...na-plugin-plugins-data-public.indexpatternfield.md | 1 + src/plugins/data/public/public.api.md | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md new file mode 100644 index 00000000000000..d1a1ee0905c6e3 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IndexPatternField](./kibana-plugin-plugins-data-public.indexpatternfield.md) > [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) + +## IndexPatternField.indexPattern property + +Signature: + +```typescript +indexPattern?: IndexPattern; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md index 430590c7a25058..ae458c553421a9 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternfield.md @@ -27,6 +27,7 @@ export declare class Field implements IFieldType | [esTypes](./kibana-plugin-plugins-data-public.indexpatternfield.estypes.md) | | string[] | | | [filterable](./kibana-plugin-plugins-data-public.indexpatternfield.filterable.md) | | boolean | | | [format](./kibana-plugin-plugins-data-public.indexpatternfield.format.md) | | any | | +| [indexPattern](./kibana-plugin-plugins-data-public.indexpatternfield.indexpattern.md) | | IndexPattern | | | [lang](./kibana-plugin-plugins-data-public.indexpatternfield.lang.md) | | string | | | [name](./kibana-plugin-plugins-data-public.indexpatternfield.name.md) | | string | | | [routes](./kibana-plugin-plugins-data-public.indexpatternfield.routes.md) | | Record<string, string> | | diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index cef82b27b1b5bc..a5db1a63652620 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -943,6 +943,8 @@ export class IndexPatternField implements IFieldType { // (undocumented) format: any; // (undocumented) + indexPattern?: IndexPattern; + // (undocumented) lang?: string; // (undocumented) name: string; From b3544ec206a28c3a5a1406a318e220b124f6696e Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Wed, 15 Apr 2020 11:11:37 +0300 Subject: [PATCH 3/4] Fixed comments --- .../components/table/table.test.tsx | 14 +-- .../components/table/table.tsx | 115 ++++++++++-------- .../indexed_fields_table.tsx | 4 +- 3 files changed, 70 insertions(+), 63 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx index ab1d96bf60a33f..d0479a9a9e0329 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.test.tsx @@ -56,7 +56,7 @@ const items: IndexedFieldItem[] = [ ]; describe('Table', () => { - test('should render normally', async () => { + test('should render normally', () => { const component = shallow(
{}} /> ); @@ -64,7 +64,7 @@ describe('Table', () => { expect(component).toMatchSnapshot(); }); - test('should render normal field name', async () => { + test('should render normal field name', () => { const component = shallow(
{}} /> ); @@ -73,7 +73,7 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - test('should render timestamp field name', async () => { + test('should render timestamp field name', () => { const component = shallow(
{}} /> ); @@ -82,7 +82,7 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - test('should render the boolean template (true)', async () => { + test('should render the boolean template (true)', () => { const component = shallow(
{}} /> ); @@ -91,7 +91,7 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - test('should render the boolean template (false)', async () => { + test('should render the boolean template (false)', () => { const component = shallow(
{}} /> ); @@ -100,7 +100,7 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - test('should render normal type', async () => { + test('should render normal type', () => { const component = shallow(
{}} /> ); @@ -109,7 +109,7 @@ describe('Table', () => { expect(tableCell).toMatchSnapshot(); }); - test('should render conflicting type', async () => { + test('should render conflicting type', () => { const component = shallow(
{}} /> ); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx index 880c0b541040bd..aa8e8b8e13a07a 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/components/table/table.tsx @@ -27,110 +27,107 @@ import { IIndexPattern } from '../../../../../../../../../../../plugins/data/pub import { IndexedFieldItem } from '../../types'; // localized labels -const infoLabel = i18n.translate( +const additionalInfoAriaLabel = i18n.translate( 'kbn.management.editIndexPattern.fields.table.additionalInfoAriaLabel', { defaultMessage: 'Additional field information' } ); -const timeLabel = i18n.translate( +const primaryTimeAriaLabel = i18n.translate( 'kbn.management.editIndexPattern.fields.table.primaryTimeAriaLabel', { defaultMessage: 'Primary time field' } ); -const timeContent = i18n.translate( +const primaryTimeTooltip = i18n.translate( 'kbn.management.editIndexPattern.fields.table.primaryTimeTooltip', { defaultMessage: 'This field represents the time that events occurred.' } ); -const label = i18n.translate('kbn.management.editIndexPattern.fields.table.multiTypeAria', { - defaultMessage: 'Multiple type field', -}); - -const content = i18n.translate('kbn.management.editIndexPattern.fields.table.multiTypeTooltip', { - defaultMessage: - 'The type of this field changes across indices. It is unavailable for many analysis functions.', -}); +const multiTypeAriaLabel = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.multiTypeAria', + { + defaultMessage: 'Multiple type field', + } +); -const displayNameColumn = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.nameHeader', +const multiTypeTooltip = i18n.translate( + 'kbn.management.editIndexPattern.fields.table.multiTypeTooltip', { - defaultMessage: 'Name', + defaultMessage: + 'The type of this field changes across indices. It is unavailable for many analysis functions.', } ); -const typeNameColumn = i18n.translate('kbn.management.editIndexPattern.fields.table.typeHeader', { +const nameHeader = i18n.translate('kbn.management.editIndexPattern.fields.table.nameHeader', { + defaultMessage: 'Name', +}); + +const typeHeader = i18n.translate('kbn.management.editIndexPattern.fields.table.typeHeader', { defaultMessage: 'Type', }); -const formatNameColumn = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.formatHeader', - { - defaultMessage: 'Format', - } -); +const formatHeader = i18n.translate('kbn.management.editIndexPattern.fields.table.formatHeader', { + defaultMessage: 'Format', +}); -const searchableNameColumn = i18n.translate( +const searchableHeader = i18n.translate( 'kbn.management.editIndexPattern.fields.table.searchableHeader', { defaultMessage: 'Searchable', } ); -const searchableDescriptionColumn = i18n.translate( +const searchableDescription = i18n.translate( 'kbn.management.editIndexPattern.fields.table.searchableDescription', { defaultMessage: 'These fields can be used in the filter bar' } ); -const isSearchableLabel = i18n.translate( +const isSearchableAriaLabel = i18n.translate( 'kbn.management.editIndexPattern.fields.table.isSearchableAria', { defaultMessage: 'Is searchable', } ); -const aggregatableNameColumn = i18n.translate( +const aggregatableLabel = i18n.translate( 'kbn.management.editIndexPattern.fields.table.aggregatableLabel', { defaultMessage: 'Aggregatable', } ); -const aggregatableDescriptionColumn = i18n.translate( +const aggregatableDescription = i18n.translate( 'kbn.management.editIndexPattern.fields.table.aggregatableDescription', { defaultMessage: 'These fields can be used in visualization aggregations' } ); -const isAggregatableLabel = i18n.translate( +const isAggregatableAriaLabel = i18n.translate( 'kbn.management.editIndexPattern.fields.table.isAggregatableAria', { defaultMessage: 'Is aggregatable', } ); -const excludedNameColumn = i18n.translate( - 'kbn.management.editIndexPattern.fields.table.excludedLabel', - { - defaultMessage: 'Excluded', - } -); +const excludedLabel = i18n.translate('kbn.management.editIndexPattern.fields.table.excludedLabel', { + defaultMessage: 'Excluded', +}); -const excludedDescriptionColumn = i18n.translate( +const excludedDescription = i18n.translate( 'kbn.management.editIndexPattern.fields.table.excludedDescription', { defaultMessage: 'Fields that are excluded from _source when it is fetched' } ); -const isExcludedLabel = i18n.translate( +const isExcludedAriaLabel = i18n.translate( 'kbn.management.editIndexPattern.fields.table.isExcludedAria', { defaultMessage: 'Is excluded', } ); -const editNameAction = i18n.translate('kbn.management.editIndexPattern.fields.table.editLabel', { +const editLabel = i18n.translate('kbn.management.editIndexPattern.fields.table.editLabel', { defaultMessage: 'Edit', }); -const editDescriptionAction = i18n.translate( +const editDescription = i18n.translate( 'kbn.management.editIndexPattern.fields.table.editDescription', { defaultMessage: 'Edit' } ); @@ -158,7 +155,7 @@ export class Table extends PureComponent { (
{info}
))} @@ -168,7 +165,12 @@ export class Table extends PureComponent { {indexPattern.timeFieldName === name ? (   - + ) : null} @@ -182,7 +184,12 @@ export class Table extends PureComponent { {isConflict ? (   - + ) : ( '' @@ -202,7 +209,7 @@ export class Table extends PureComponent { const columns: Array> = [ { field: 'displayName', - name: displayNameColumn, + name: nameHeader, dataType: 'string', sortable: true, render: (value: string, field: IndexedFieldItem) => { @@ -213,7 +220,7 @@ export class Table extends PureComponent { }, { field: 'type', - name: typeNameColumn, + name: typeHeader, dataType: 'string', sortable: true, render: (value: string) => { @@ -223,40 +230,40 @@ export class Table extends PureComponent { }, { field: 'format', - name: formatNameColumn, + name: formatHeader, dataType: 'string', sortable: true, }, { field: 'searchable', - name: searchableNameColumn, - description: searchableDescriptionColumn, + name: searchableHeader, + description: searchableDescription, dataType: 'boolean', sortable: true, - render: (value: string) => this.renderBooleanTemplate(value, isSearchableLabel), + render: (value: string) => this.renderBooleanTemplate(value, isSearchableAriaLabel), }, { field: 'aggregatable', - name: aggregatableNameColumn, - description: aggregatableDescriptionColumn, + name: aggregatableLabel, + description: aggregatableDescription, dataType: 'boolean', sortable: true, - render: (value: string) => this.renderBooleanTemplate(value, isAggregatableLabel), + render: (value: string) => this.renderBooleanTemplate(value, isAggregatableAriaLabel), }, { field: 'excluded', - name: excludedNameColumn, - description: excludedDescriptionColumn, + name: excludedLabel, + description: excludedDescription, dataType: 'boolean', sortable: true, - render: (value: string) => this.renderBooleanTemplate(value, isExcludedLabel), + render: (value: string) => this.renderBooleanTemplate(value, isExcludedAriaLabel), }, { name: '', actions: [ { - name: editNameAction, - description: editDescriptionAction, + name: editLabel, + description: editDescription, icon: 'pencil', onClick: editField, type: 'icon', diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx index 47b2c4c7358010..93d5ccf39b2839 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx @@ -27,8 +27,8 @@ import { IndexedFieldItem } from './types'; interface IndexedFieldsTableProps { fields: IndexPatternField[]; indexPattern: IIndexPattern; - fieldFilter: string; - indexedFieldTypeFilter: string; + fieldFilter?: string; + indexedFieldTypeFilter?: string; helpers: { redirectToRoute: (obj: any, route: string) => void; getFieldInfo: (indexPattern: IIndexPattern, field: string) => string[]; From e265727d3b155f30758a078a53b906b52cf0fb4f Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Wed, 15 Apr 2020 14:48:35 +0300 Subject: [PATCH 4/4] Fixed types --- .../indexed_fields_table/indexed_fields_table.test.tsx | 2 +- .../indexed_fields_table/indexed_fields_table.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx index 8e877c4fe8a16e..f8b78a92e098eb 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.test.tsx @@ -37,7 +37,7 @@ jest.mock('./components/table', () => ({ })); const helpers = { - redirectToRoute: (obj: any, route: string) => {}, + redirectToRoute: (obj: any) => {}, getFieldInfo: () => [], }; diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx index 5cd24e10520d69..7c2bb565615d71 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/indexed_fields_table/indexed_fields_table.tsx @@ -30,7 +30,7 @@ interface IndexedFieldsTableProps { fieldFilter?: string; indexedFieldTypeFilter?: string; helpers: { - redirectToRoute: (obj: any, route: string) => void; + redirectToRoute: (obj: any) => void; getFieldInfo: (indexPattern: IIndexPattern, field: string) => string[]; }; fieldWildcardMatcher: (filters: any[]) => (val: any) => boolean;