From 51f21d9b0f9791720c296083ca8857d983394518 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 25 Nov 2020 14:44:53 -0600 Subject: [PATCH 1/6] Migrate shared Schema components These components were not changed, with the exception of lint fixes and TypeScript changes (adding types). The only exceptions are: 1. The `formatFieldName` in `SchemaAddFieldModal`. In `ent-search`, this was a shared util, but since it was not used anywhere else, I just added the method as a function in this component. 2. The `IFieldCoercionErrors` interface is only used here so I did not add it to the shared types file and instead jut added it to this component. --- .../shared/constants/field_types.ts | 17 ++ .../applications/shared/schema/index.ts | 8 + .../shared/schema/schema_add_field_modal.tsx | 146 ++++++++++++++++++ .../shared/schema/schema_errors_accordion.tsx | 125 +++++++++++++++ .../shared/schema/schema_existing_field.tsx | 55 +++++++ 5 files changed, 351 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/constants/field_types.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/constants/field_types.ts b/x-pack/plugins/enterprise_search/public/applications/shared/constants/field_types.ts new file mode 100644 index 0000000000000..9b8d7b1742f48 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/constants/field_types.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +export const TEXT = 'text'; +export const NUMBER = 'number'; +export const DATE = 'date'; +export const GEOLOCATION = 'geolocation'; + +export const fieldTypeSelectOptions = [ + { value: TEXT, text: TEXT }, + { value: NUMBER, text: NUMBER }, + { value: DATE, text: DATE }, + { value: GEOLOCATION, text: GEOLOCATION }, +]; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/index.ts b/x-pack/plugins/enterprise_search/public/applications/shared/schema/index.ts new file mode 100644 index 0000000000000..3c5d718422aa8 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export { SchemaAddFieldModal } from './schema_add_field_modal'; +export { SchemaExistingField } from './schema_existing_field'; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx new file mode 100644 index 0000000000000..2246830e7baed --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx @@ -0,0 +1,146 @@ +/* + * 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 React, { ChangeEvent, FormEvent, useEffect, useState } from 'react'; + +import { + EuiButton, + EuiButtonEmpty, + EuiFieldText, + EuiFlexGroup, + EuiFlexItem, + EuiForm, + EuiFormRow, + EuiModal, + EuiModalBody, + EuiModalFooter, + EuiModalHeader, + EuiModalHeaderTitle, + EuiOverlayMask, + EuiSelect, + EuiSpacer, +} from '@elastic/eui'; + +import { TEXT, fieldTypeSelectOptions } from '../constants/field_types'; + +interface ISchemaAddFieldModalProps { + disableForm?: boolean; + addFieldFormErrors?: string[] | null; + addNewField(fieldName: string, newFieldType: string): void; + closeAddFieldModal(): void; +} + +export const SchemaAddFieldModal: React.FC = ({ + addNewField, + addFieldFormErrors, + closeAddFieldModal, + disableForm, +}) => { + const [loading, setLoading] = useState(false); + const [newFieldType, updateNewFieldType] = useState(TEXT); + const [formattedFieldName, setFormattedFieldName] = useState(''); + const [rawFieldName, setRawFieldName] = useState(''); + + useEffect(() => { + if (addFieldFormErrors) setLoading(false); + }, [addFieldFormErrors]); + + const handleChange = ({ currentTarget: { value } }: ChangeEvent) => { + setRawFieldName(value); + setFormattedFieldName(formatFieldName(value)); + }; + + const submitForm = (e: FormEvent) => { + e.preventDefault(); + addNewField(formattedFieldName, newFieldType); + setLoading(true); + }; + + const fieldNameNote = + rawFieldName !== formattedFieldName ? ( + <> + The field will be named {formattedFieldName} + + ) : ( + 'Field names can only contain lowercase letters, numbers, and underscores' + ); + + return ( + +
+ + + Add a New Field + + +

Once added, a field cannot be removed from your schema.

+ + + + + + + + + + + updateNewFieldType(e.target.value)} + data-test-subj="SchemaSelect" + /> + + + + +
+ + Cancel + + Add Field + + +
+
+
+ ); +}; + +const formatFieldName = (rawName: string) => + rawName + .trim() + .replace(/[^a-zA-Z0-9]+/g, '_') + .replace(/^[^a-zA-Z0-9]+/, '') + .replace(/[^a-zA-Z0-9]+$/, '') + .toLowerCase(); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx new file mode 100644 index 0000000000000..e570d3c32e24a --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx @@ -0,0 +1,125 @@ +/* + * 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 React from 'react'; +import { Link } from 'react-router-dom'; + +import { + EuiAccordion, + EuiFlexGroup, + EuiFlexItem, + EuiTable, + EuiTableBody, + EuiTableHeader, + EuiTableHeaderCell, + EuiTableRow, + EuiTableRowCell, +} from '@elastic/eui'; + +import { TruncatedContent } from '../truncate'; + +interface IFieldCoercionError { + external_id: string; + error: string; +} + +interface IFieldCoercionErrors { + [key: string]: IFieldCoercionError[]; +} + +interface ISchemaErrorsAccordionProps { + fieldCoercionErrors: IFieldCoercionErrors; + schema: { [key: string]: string }; + itemId?: string; + getRoute?(itemId: string, externalId: string): string; +} + +export const SchemaErrorsAccordion: React.FC = ({ + fieldCoercionErrors, + schema, + itemId, + getRoute, +}) => ( + <> + {Object.keys(fieldCoercionErrors).map((fieldName, fieldNameIndex) => { + const errorInfos = fieldCoercionErrors[fieldName]; + + const accordionHeader = ( + + + + + + + {schema[fieldName]} + + + + Review + + + ); + + return ( + + + + id + Error + + + + {errorInfos.map((error, errorIndex) => { + const showViewButton = getRoute && itemId; + const documentPath = getRoute && itemId ? getRoute(itemId, error.external_id) : ''; + + const viewButton = showViewButton && ( + + + + View + + + + ); + + return ( + + +
+ +
+
+ + {error.error} + + {showViewButton ? viewButton : } +
+ ); + })} +
+
+
+ ); + })} + +); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx new file mode 100644 index 0000000000000..82e837c27640a --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx @@ -0,0 +1,55 @@ +/* + * 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 React from 'react'; + +import classNames from 'classnames'; + +import { EuiSelect } from '@elastic/eui'; + +import { fieldTypeSelectOptions } from '../constants/field_types'; + +interface ISchemaExistingFieldProps { + disabled?: boolean; + fieldName: string; + fieldType?: string; + unconfirmed?: boolean; + hideName?: boolean; + updateExistingFieldType?(fieldName: string, fieldType: string): void; +} + +export const SchemaExistingField: React.FC = ({ + disabled, + fieldName, + fieldType, + unconfirmed, + hideName, + updateExistingFieldType, +}) => { + const fieldCssClass = classNames('c-stui-engine-schema-field', { + 'c-stui-engine-schema-field--recently-added': unconfirmed, + }); + + return ( +
+
{!hideName ? fieldName : ''}
+ {unconfirmed &&
Recently Added
} + {fieldType && updateExistingFieldType && ( +
+ updateExistingFieldType(fieldName, e.target.value)} + data-test-subj="SchemaSelect" + /> +
+ )} +
+ ); +}; From 96ff7e7e96d6a07502c8e9fd279e7a252548545f Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 25 Nov 2020 16:15:17 -0600 Subject: [PATCH 2/6] Use EuiLinkTo instead of Link --- .../applications/shared/schema/schema_errors_accordion.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx index e570d3c32e24a..49e6b774953ad 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx @@ -5,7 +5,6 @@ */ import React from 'react'; -import { Link } from 'react-router-dom'; import { EuiAccordion, @@ -19,6 +18,8 @@ import { EuiTableRowCell, } from '@elastic/eui'; +import { EuiLinkTo } from '../react_router_helpers'; + import { TruncatedContent } from '../truncate'; interface IFieldCoercionError { @@ -85,14 +86,14 @@ export const SchemaErrorsAccordion: React.FC = ({ const viewButton = showViewButton && ( - View - + ); From 03d7e770bfaffa63a533b2b232532938bd110334 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 25 Nov 2020 16:27:20 -0600 Subject: [PATCH 3/6] Add unit tests --- .../schema/schema_add_field_modal.test.tsx | 93 +++++++++++++++++++ .../schema/schema_errors_accordion.test.tsx | 48 ++++++++++ .../schema/schema_existing_field.test.tsx | 52 +++++++++++ 3 files changed, 193 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx new file mode 100644 index 0000000000000..35db2c4385dad --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx @@ -0,0 +1,93 @@ +/* + * 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 React from 'react'; +import { shallow, mount } from 'enzyme'; + +import { NUMBER } from '../constants/field_types'; + +import { SchemaAddFieldModal } from './'; + +import { EuiFieldText, EuiModal, EuiSelect } from '@elastic/eui'; + +describe('SchemaAddFieldModal', () => { + const addNewField = jest.fn(); + const closeAddFieldModal = jest.fn(); + + const props = { + addNewField, + closeAddFieldModal, + }; + + const errors = { + addFieldFormErrors: ['error1', 'error2'], + }; + + const setState = jest.fn(); + const setStateMock: any = (initState: any) => [initState, setState]; + + beforeEach(() => { + jest.spyOn(React, 'useState').mockImplementationOnce(setStateMock); + setState(false); + }); + + it('renders', () => { + const wrapper = shallow(); + expect(wrapper.find(EuiModal)).toHaveLength(1); + }); + + // No matter what I try I can't get this to actually achieve coverage. + it('sets loading state in useEffect', () => { + setState(true); + const wrapper = mount(); + const input = wrapper.find(EuiFieldText); + + expect(input.prop('isLoading')).toEqual(false); + expect(setState).toHaveBeenCalledTimes(3); + expect(setState).toHaveBeenCalledWith(false); + }); + + it('handles input change - with non-formatted name', () => { + jest.spyOn(React, 'useState').mockImplementationOnce(setStateMock); + const wrapper = shallow(); + const input = wrapper.find(EuiFieldText); + input.simulate('change', { currentTarget: { value: 'foobar' } }); + + expect(wrapper.find('[data-test-subj="SchemaAddFieldNameRow"]').prop('helpText')).toEqual( + 'Field names can only contain lowercase letters, numbers, and underscores' + ); + }); + + it('handles input change - with formatted name', () => { + jest.spyOn(React, 'useState').mockImplementationOnce(setStateMock); + const wrapper = shallow(); + const input = wrapper.find(EuiFieldText); + input.simulate('change', { currentTarget: { value: 'foo-bar' } }); + + expect(wrapper.find('[data-test-subj="SchemaAddFieldNameRow"]').prop('helpText')).toEqual( + + The field will be named foo_bar + + ); + }); + + it('handles option change', () => { + const wrapper = shallow(); + wrapper.find(EuiSelect).simulate('change', { target: { value: NUMBER } }); + + expect(wrapper.find('[data-test-subj="SchemaSelect"]').prop('value')).toEqual(NUMBER); + }); + + it('handles form submission', () => { + jest.spyOn(React, 'useState').mockImplementationOnce(setStateMock); + const wrapper = shallow(); + const preventDefault = jest.fn(); + wrapper.find('form').simulate('submit', { preventDefault }); + + expect(addNewField).toHaveBeenCalled(); + expect(setState).toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.test.tsx new file mode 100644 index 0000000000000..c63fbe17ea2ad --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.test.tsx @@ -0,0 +1,48 @@ +/* + * 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 React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiAccordion, EuiTableRow } from '@elastic/eui'; + +import { EuiLinkTo } from '../react_router_helpers'; +import { SchemaErrorsAccordion } from './schema_errors_accordion'; + +describe('SchemaErrorsAccordion', () => { + const props = { + fieldCoercionErrors: { + id: [ + { + external_id: 'foo', + error: 'this is an error', + }, + { + external_id: 'bar', + error: 'this is another error', + }, + ], + }, + schema: { + id: 'string', + name: 'boolean', + }, + }; + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiAccordion)).toHaveLength(1); + expect(wrapper.find(EuiTableRow)).toHaveLength(2); + expect(wrapper.find(EuiLinkTo)).toHaveLength(0); + }); + + it('renders document buttons', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiLinkTo)).toHaveLength(2); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx new file mode 100644 index 0000000000000..0176cfc181394 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx @@ -0,0 +1,52 @@ +/* + * 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 React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiSelect } from '@elastic/eui'; + +import { SchemaExistingField } from './'; + +describe('SchemaExistingField', () => { + const updateExistingFieldType = jest.fn(); + const props = { + fieldName: 'foo', + fieldType: 'field', + updateExistingFieldType, + }; + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiSelect)).toHaveLength(1); + }); + + it('renders no EuiSelect without props', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiSelect)).toHaveLength(0); + }); + + it('calls updateExistingFieldType when the select value is changed', () => { + const wrapper = shallow(); + wrapper.find(EuiSelect).simulate('change', { target: { value: 'bar' } }); + + expect(updateExistingFieldType).toHaveBeenCalledWith(props.fieldName, 'bar'); + }); + + it('doesn`t render fieldName when hidden', () => { + const wrapper = shallow(); + + expect(wrapper.find('.c-stui-engine-schema-field__name').exists()).toBeTruthy(); + }); + + it('renders unconfirmed message', () => { + const wrapper = shallow(); + + expect(wrapper.find('.c-stui-engine-schema-field__status').exists()).toBeTruthy(); + }); +}); From 06081e1fa129f4cf476050b7ac97a6d11b5e234e Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 25 Nov 2020 16:37:58 -0600 Subject: [PATCH 4/6] Better test for `hideName` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coverage was fine but wasn’t actually testing correctly --- .../applications/shared/schema/schema_existing_field.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx index 0176cfc181394..d3040da476a91 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.test.tsx @@ -41,7 +41,7 @@ describe('SchemaExistingField', () => { it('doesn`t render fieldName when hidden', () => { const wrapper = shallow(); - expect(wrapper.find('.c-stui-engine-schema-field__name').exists()).toBeTruthy(); + expect(wrapper.find('.c-stui-engine-schema-field__name').contains(props.fieldName)).toBeFalsy(); }); it('renders unconfirmed message', () => { From c02a69a2918b27c1c9b90b792c07533a2bf08d46 Mon Sep 17 00:00:00 2001 From: scottybollinger Date: Wed, 25 Nov 2020 16:59:33 -0600 Subject: [PATCH 5/6] Add i18n --- .../applications/shared/schema/constants.ts | 83 +++++++++++++++++++ .../schema/schema_add_field_modal.test.tsx | 4 +- .../shared/schema/schema_add_field_modal.tsx | 21 +++-- .../shared/schema/schema_errors_accordion.tsx | 15 +++- .../shared/schema/schema_existing_field.tsx | 4 +- 5 files changed, 115 insertions(+), 12 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/schema/constants.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/constants.ts b/x-pack/plugins/enterprise_search/public/applications/shared/schema/constants.ts new file mode 100644 index 0000000000000..7d7d36ad09a27 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/constants.ts @@ -0,0 +1,83 @@ +/* + * 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'; + +export const FIELD_NAME_CORRECT_NOTE = i18n.translate( + 'xpack.enterpriseSearch.schema.addFieldModal.fieldNameNote.correct', + { + defaultMessage: 'Field names can only contain lowercase letters, numbers, and underscores', + } +); + +export const FIELD_NAME_CORRECTED_PREFIX = i18n.translate( + 'xpack.enterpriseSearch.schema.addFieldModal.fieldNameNote.corrected', + { + defaultMessage: 'The field will be named', + } +); + +export const FIELD_NAME_MODAL_TITLE = i18n.translate( + 'xpack.enterpriseSearch.schema.addFieldModal.fieldNameNote.title', + { + defaultMessage: 'Add a New Field', + } +); + +export const FIELD_NAME_MODAL_DESCRIPTION = i18n.translate( + 'xpack.enterpriseSearch.schema.addFieldModal.fieldNameNote.description', + { + defaultMessage: 'Once added, a field cannot be removed from your schema.', + } +); + +export const FIELD_NAME_MODAL_CANCEL = i18n.translate( + 'xpack.enterpriseSearch.schema.addFieldModal.fieldNameNote.cancel', + { + defaultMessage: 'Cancel', + } +); + +export const FIELD_NAME_MODAL_ADD_FIELD = i18n.translate( + 'xpack.enterpriseSearch.schema.addFieldModal.fieldNameNote.addField', + { + defaultMessage: 'Add field', + } +); + +export const ERROR_TABLE_ID_HEADER = i18n.translate( + 'xpack.enterpriseSearch.schema.errorsTable.heading.id', + { + defaultMessage: 'id', + } +); + +export const ERROR_TABLE_ERROR_HEADER = i18n.translate( + 'xpack.enterpriseSearch.schema.errorsTable.heading.error', + { + defaultMessage: 'Error', + } +); + +export const ERROR_TABLE_REVIEW_CONTROL = i18n.translate( + 'xpack.enterpriseSearch.schema.errorsTable.control.review', + { + defaultMessage: 'Review', + } +); + +export const ERROR_TABLE_VIEW_LINK = i18n.translate( + 'xpack.enterpriseSearch.schema.errorsTable.link.view', + { + defaultMessage: 'View', + } +); + +export const RECENTY_ADDED = i18n.translate( + 'xpack.enterpriseSearch.schema.existingField.status.recentlyAdded', + { + defaultMessage: 'Recently Added', + } +); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx index 35db2c4385dad..949abc501c68a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx @@ -69,7 +69,9 @@ describe('SchemaAddFieldModal', () => { expect(wrapper.find('[data-test-subj="SchemaAddFieldNameRow"]').prop('helpText')).toEqual( - The field will be named foo_bar + The field will be named + {' '} + foo_bar ); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx index 2246830e7baed..5cdd8be4016eb 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.tsx @@ -26,6 +26,15 @@ import { import { TEXT, fieldTypeSelectOptions } from '../constants/field_types'; +import { + FIELD_NAME_CORRECT_NOTE, + FIELD_NAME_CORRECTED_PREFIX, + FIELD_NAME_MODAL_TITLE, + FIELD_NAME_MODAL_DESCRIPTION, + FIELD_NAME_MODAL_CANCEL, + FIELD_NAME_MODAL_ADD_FIELD, +} from './constants'; + interface ISchemaAddFieldModalProps { disableForm?: boolean; addFieldFormErrors?: string[] | null; @@ -62,10 +71,10 @@ export const SchemaAddFieldModal: React.FC = ({ const fieldNameNote = rawFieldName !== formattedFieldName ? ( <> - The field will be named {formattedFieldName} + {FIELD_NAME_CORRECTED_PREFIX} {formattedFieldName} ) : ( - 'Field names can only contain lowercase letters, numbers, and underscores' + FIELD_NAME_CORRECT_NOTE ); return ( @@ -73,10 +82,10 @@ export const SchemaAddFieldModal: React.FC = ({
- Add a New Field + {FIELD_NAME_MODAL_TITLE} -

Once added, a field cannot be removed from your schema.

+

{FIELD_NAME_MODAL_DESCRIPTION}

@@ -119,7 +128,7 @@ export const SchemaAddFieldModal: React.FC = ({
- Cancel + {FIELD_NAME_MODAL_CANCEL} = ({ isLoading={loading} data-test-subj="SchemaAddFieldAddFieldButton" > - Add Field + {FIELD_NAME_MODAL_ADD_FIELD}
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx index 49e6b774953ad..98b5dbdd7b278 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_errors_accordion.tsx @@ -22,6 +22,13 @@ import { EuiLinkTo } from '../react_router_helpers'; import { TruncatedContent } from '../truncate'; +import { + ERROR_TABLE_ID_HEADER, + ERROR_TABLE_ERROR_HEADER, + ERROR_TABLE_REVIEW_CONTROL, + ERROR_TABLE_VIEW_LINK, +} from './constants'; + interface IFieldCoercionError { external_id: string; error: string; @@ -59,7 +66,7 @@ export const SchemaErrorsAccordion: React.FC = ({ - Review + {ERROR_TABLE_REVIEW_CONTROL} ); @@ -75,8 +82,8 @@ export const SchemaErrorsAccordion: React.FC = ({ > - id - Error + {ERROR_TABLE_ID_HEADER} + {ERROR_TABLE_ERROR_HEADER} @@ -91,7 +98,7 @@ export const SchemaErrorsAccordion: React.FC = ({ to={documentPath} > - View + {ERROR_TABLE_VIEW_LINK} diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx index 82e837c27640a..99dd651f91f4b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_existing_field.tsx @@ -12,6 +12,8 @@ import { EuiSelect } from '@elastic/eui'; import { fieldTypeSelectOptions } from '../constants/field_types'; +import { RECENTY_ADDED } from './constants'; + interface ISchemaExistingFieldProps { disabled?: boolean; fieldName: string; @@ -36,7 +38,7 @@ export const SchemaExistingField: React.FC = ({ return (
{!hideName ? fieldName : ''}
- {unconfirmed &&
Recently Added
} + {unconfirmed &&
{RECENTY_ADDED}
} {fieldType && updateExistingFieldType && (
Date: Thu, 26 Nov 2020 19:12:56 -0600 Subject: [PATCH 6/6] =?UTF-8?q?FIx=20test=20that=20didn=E2=80=99t=20pass?= =?UTF-8?q?=20eslint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shared/schema/schema_add_field_modal.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx index 949abc501c68a..e10d56ddc09b0 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/schema/schema_add_field_modal.test.tsx @@ -9,6 +9,8 @@ import { shallow, mount } from 'enzyme'; import { NUMBER } from '../constants/field_types'; +import { FIELD_NAME_CORRECTED_PREFIX } from './constants'; + import { SchemaAddFieldModal } from './'; import { EuiFieldText, EuiModal, EuiSelect } from '@elastic/eui'; @@ -69,9 +71,7 @@ describe('SchemaAddFieldModal', () => { expect(wrapper.find('[data-test-subj="SchemaAddFieldNameRow"]').prop('helpText')).toEqual( - The field will be named - {' '} - foo_bar + {FIELD_NAME_CORRECTED_PREFIX} foo_bar ); });