From e97b96eb92352d29ad2de753103d26f4d38083fb Mon Sep 17 00:00:00 2001 From: KHeo Date: Tue, 17 Sep 2019 16:53:52 +0900 Subject: [PATCH 01/10] Prettierize. --- .../components/header/header.js | 52 ++-- .../components/header/header.js | 18 +- .../step_index_pattern/step_index_pattern.js | 75 +++--- .../advanced_options/advanced_options.js | 63 +++-- .../components/time_field/time_field.js | 39 ++- .../step_time_field/step_time_field.js | 101 ++++---- .../components/table/table.js | 135 ++++++---- .../components/table/table.js | 167 +++++++------ .../components/add_filter/add_filter.js | 24 +- .../components/table/table.js | 51 ++-- .../objects_table/components/flyout/flyout.js | 232 ++++++++--------- .../components/relationships/relationships.js | 72 +++--- .../objects_table/components/table/table.js | 132 +++++----- .../components/objects_table/objects_table.js | 135 +++++----- .../settings/components/field/field.js | 234 ++++++++++-------- .../sections/settings/components/form/form.js | 17 +- .../settings/components/search/search.js | 24 +- 17 files changed, 802 insertions(+), 769 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js index 40a5fa23a23ad..6b0552f736667 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js @@ -39,7 +39,7 @@ const HeaderUi = ({ isIncludingSystemIndices, onChangeIncludingSystemIndices, isBeta, - intl + intl, }) => (
@@ -48,20 +48,20 @@ const HeaderUi = ({ id="kbn.management.createIndexPatternHeader" defaultMessage="Create {indexPatternName}" values={{ - indexPatternName + indexPatternName, }} /> - { isBeta ? ( + {isBeta ? ( {' '} - ) : null } + ) : null} @@ -77,31 +77,29 @@ const HeaderUi = ({

- { - showSystemIndices ? ( - - + } - id="checkboxShowSystemIndices" - checked={isIncludingSystemIndices} - onChange={onChangeIncludingSystemIndices} - /> - - ) : null - } + /> + } + id="checkboxShowSystemIndices" + checked={isIncludingSystemIndices} + onChange={onChangeIncludingSystemIndices} + /> + + ) : null}
- { - prompt ? ( - - - {prompt} - - ) : null - } - + {prompt ? ( + + + {prompt} + + ) : null} +
); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/header.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/header.js index aab39f8851ef7..14a5588f748f7 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/header.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/header.js @@ -52,17 +52,17 @@ export const HeaderComponent = ({ /> - + - + } + label={ + + } isInvalid={isInputInvalid} error={errors} helpText={ @@ -88,7 +88,7 @@ export const HeaderComponent = ({ name="indexPattern" placeholder={intl.formatMessage({ id: 'kbn.management.createIndexPattern.step.indexPatternPlaceholder', - defaultMessage: 'index-name-*' + defaultMessage: 'index-name-*', })} value={query} isInvalid={isInputInvalid} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index 60b5cb2dd8dae..e110e1b7755a8 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -26,18 +26,14 @@ import { containsIllegalCharacters, getMatchedIndices, canAppendWildcard, - ensureMinimumTime + ensureMinimumTime, } from '../../lib'; import { LoadingIndices } from './components/loading_indices'; import { StatusMessage } from './components/status_message'; import { IndicesList } from './components/indices_list'; import { Header } from './components/header'; -import { - EuiPanel, - EuiSpacer, - EuiCallOut, -} from '@elastic/eui'; +import { EuiPanel, EuiSpacer, EuiCallOut } from '@elastic/eui'; import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; import chrome from 'ui/chrome'; @@ -53,11 +49,11 @@ export class StepIndexPatternComponent extends Component { indexPatternCreationType: PropTypes.object.isRequired, goToNextStep: PropTypes.func.isRequired, initialQuery: PropTypes.string, - } + }; static defaultProps = { initialQuery: uiSettings.get('indexPattern:placeholder'), - } + }; constructor(props) { super(props); @@ -90,13 +86,15 @@ export class StepIndexPatternComponent extends Component { const { savedObjects } = await this.props.savedObjectsClient.find({ type: 'index-pattern', fields: ['title'], - perPage: 10000 + perPage: 10000, }); - const existingIndexPatterns = savedObjects.map(obj => obj && obj.attributes ? obj.attributes.title : ''); + const existingIndexPatterns = savedObjects.map(obj => + obj && obj.attributes ? obj.attributes.title : '' + ); this.setState({ existingIndexPatterns }); - } + }; - fetchIndices = async (query) => { + fetchIndices = async query => { const { esService, indexPatternCreationType } = this.props; const { existingIndexPatterns } = this.state; @@ -108,7 +106,9 @@ export class StepIndexPatternComponent extends Component { this.setState({ isLoadingIndices: true, indexPatternExists: false }); if (query.endsWith('*')) { - const exactMatchedIndices = await ensureMinimumTime(getIndices(esService, indexPatternCreationType, query, MAX_SEARCH_SIZE)); + const exactMatchedIndices = await ensureMinimumTime( + getIndices(esService, indexPatternCreationType, query, MAX_SEARCH_SIZE) + ); // If the search changed, discard this state if (query !== this.lastQuery) { return; @@ -117,10 +117,7 @@ export class StepIndexPatternComponent extends Component { return; } - const [ - partialMatchedIndices, - exactMatchedIndices, - ] = await ensureMinimumTime([ + const [partialMatchedIndices, exactMatchedIndices] = await ensureMinimumTime([ getIndices(esService, indexPatternCreationType, `${query}*`, MAX_SEARCH_SIZE), getIndices(esService, indexPatternCreationType, query, MAX_SEARCH_SIZE), ]); @@ -133,9 +130,9 @@ export class StepIndexPatternComponent extends Component { this.setState({ partialMatchedIndices, exactMatchedIndices, - isLoadingIndices: false + isLoadingIndices: false, }); - } + }; onQueryChanged = e => { const { appendedWildcard } = this.state; @@ -156,7 +153,7 @@ export class StepIndexPatternComponent extends Component { this.lastQuery = query; this.setState({ query, showingIndexPatternQueryErrors: !!query.length }); this.fetchIndices(query); - } + }; renderLoadingState() { const { isLoadingIndices } = this.state; @@ -165,9 +162,7 @@ export class StepIndexPatternComponent extends Component { return null; } - return ( - - ); + return ; } renderStatusMessage(matchedIndices) { @@ -195,9 +190,7 @@ export class StepIndexPatternComponent extends Component { return null; } - const indicesToList = query.length - ? visibleIndices - : allIndices; + const indicesToList = query.length ? visibleIndices : allIndices; return ( } + title={ + + } iconType="help" color="warning" /> @@ -230,11 +225,18 @@ export class StepIndexPatternComponent extends Component { renderHeader({ exactMatchedIndices: indices }) { const { goToNextStep, indexPatternCreationType, intl } = this.props; - const { query, showingIndexPatternQueryErrors, indexPatternExists, indexPatternName } = this.state; + const { + query, + showingIndexPatternQueryErrors, + indexPatternExists, + indexPatternName, + } = this.state; let containsErrors = false; const errors = []; - const characterList = this.ILLEGAL_CHARACTERS.slice(0, this.ILLEGAL_CHARACTERS.length - 1).join(', '); + const characterList = this.ILLEGAL_CHARACTERS.slice(0, this.ILLEGAL_CHARACTERS.length - 1).join( + ', ' + ); const checkIndices = indexPatternCreationType.checkIndicesForErrors(indices); if (!query || !query.length || query === '.' || query === '..') { @@ -244,7 +246,8 @@ export class StepIndexPatternComponent extends Component { const errorMessage = intl.formatMessage( { id: 'kbn.management.createIndexPattern.step.invalidCharactersErrorMessage', - defaultMessage: 'A {indexPatternName} cannot contain spaces or the characters: {characterList}' + defaultMessage: + 'A {indexPatternName} cannot contain spaces or the characters: {characterList}', }, { characterList, indexPatternName } ); @@ -288,11 +291,11 @@ export class StepIndexPatternComponent extends Component { return ( {this.renderHeader(matchedIndices)} - + {this.renderLoadingState(matchedIndices)} {this.renderIndexPatternExists()} {this.renderStatusMessage(matchedIndices)} - + {this.renderList(matchedIndices)} ); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js index 3126dcf5430f6..7e7326f47073e 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js @@ -19,13 +19,7 @@ import React from 'react'; -import { - EuiForm, - EuiFormRow, - EuiFieldText, - EuiButtonEmpty, - EuiSpacer, -} from '@elastic/eui'; +import { EuiForm, EuiFormRow, EuiFieldText, EuiButtonEmpty, EuiSpacer } from '@elastic/eui'; import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; @@ -41,35 +35,35 @@ export const AdvancedOptionsComponent = ({ iconType={isVisible ? 'arrowDown' : 'arrowRight'} onClick={toggleAdvancedOptions} > - { isVisible - ? ( - - ) - : ( - - ) - } - + {isVisible ? ( + + ) : ( + + )} - - { isVisible ? + + {isVisible ? ( } - helpText={ + } + helpText={ + } + /> + } > - : null - } + ) : null} ); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js index 77a541d1ff7af..b1304a2462691 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js @@ -44,7 +44,7 @@ export const TimeFieldComponent = ({ intl, }) => ( - { isVisible ? + {isVisible ? ( @@ -57,21 +57,16 @@ export const TimeFieldComponent = ({ - { isLoading ? ( - - ) - : ( - - - - ) - } + {isLoading ? ( + + ) : ( + + + + )} } @@ -92,7 +87,7 @@ export const TimeFieldComponent = ({ } > - { isLoading ? ( + {isLoading ? ( @@ -119,7 +114,7 @@ export const TimeFieldComponent = ({ /> )} - : + ) : (

- } + )} ); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js index 37591d484d201..c45d80edfaff1 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js @@ -45,15 +45,12 @@ export class StepTimeFieldComponent extends Component { goToPreviousStep: PropTypes.func.isRequired, createIndexPattern: PropTypes.func.isRequired, indexPatternCreationType: PropTypes.object.isRequired, - } + }; constructor(props) { super(props); - const { - getIndexPatternType, - getIndexPatternName, - } = props.indexPatternCreationType; + const { getIndexPatternType, getIndexPatternName } = props.indexPatternCreationType; this.state = { error: '', @@ -94,9 +91,9 @@ export class StepTimeFieldComponent extends Component { const timeFields = extractTimeFields(fields); this.setState({ timeFields, isFetchingTimeFields: false }); - } + }; - onTimeFieldChanged = (e) => { + onTimeFieldChanged = e => { const value = e.target.value; // Find the time field based on the selected value @@ -109,17 +106,17 @@ export class StepTimeFieldComponent extends Component { selectedTimeField: timeField ? timeField.fieldName : undefined, timeFieldSet: validSelection, }); - } + }; - onChangeIndexPatternId = (e) => { + onChangeIndexPatternId = e => { this.setState({ indexPatternId: e.target.value }); - } + }; toggleAdvancedOptions = () => { this.setState(state => ({ - isAdvancedOptionsVisible: !state.isAdvancedOptionsVisible + isAdvancedOptionsVisible: !state.isAdvancedOptionsVisible, })); - } + }; createIndexPattern = async () => { const { createIndexPattern } = this.props; @@ -134,18 +131,18 @@ export class StepTimeFieldComponent extends Component { isCreating: false, }); } - } + }; formatErrorMessage(message) { // `createIndexPattern` throws "Conflict" when index pattern ID already exists. - return message === 'Conflict' - ? ( - - ) - : message; + return message === 'Conflict' ? ( + + ) : ( + message + ); } render() { @@ -165,7 +162,7 @@ export class StepTimeFieldComponent extends Component { - + @@ -180,53 +177,43 @@ export class StepTimeFieldComponent extends Component { ); } - const { - indexPattern, - goToPreviousStep, - } = this.props; + const { indexPattern, goToPreviousStep } = this.props; - const timeFieldOptions = timeFields ? - [ + const timeFieldOptions = timeFields + ? [ { text: '', value: '' }, ...timeFields.map(timeField => ({ text: timeField.display, value: timeField.fieldName, disabled: timeFields.isDisabled, - })) + })), ] : []; const showTimeField = !timeFields || timeFields.length > 1; const submittable = !showTimeField || timeFieldSet; - const error = this.state.error - ? ( - <> - - )} - color="danger" - iconType="cross" - > -

- {this.formatErrorMessage(this.state.error)} -

-
- - - ) - : null; + const error = this.state.error ? ( + <> + + } + color="danger" + iconType="cross" + > +

{this.formatErrorMessage(this.state.error)}

+
+ + + ) : null; return ( -
- +
+ - + - + {error} : ; + return value ? : ; } renderFieldName(name, field) { @@ -45,15 +41,15 @@ export class TableComponent extends PureComponent { const infoLabel = intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.additionalInfoAriaLabel', - defaultMessage: 'Additional field information' + defaultMessage: 'Additional field information', }); const timeLabel = intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.primaryTimeAriaLabel', - defaultMessage: 'Primary time field' + defaultMessage: 'Primary time field', }); const timeContent = intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.primaryTimeTooltip', - defaultMessage: 'This field represents the time that events occurred.' + defaultMessage: 'This field represents the time that events occurred.', }); return ( @@ -66,19 +62,16 @@ export class TableComponent extends PureComponent { type="questionInCircle" color="primary" aria-label={infoLabel} - content={field.info.map((info, i) =>
{info}
)} + content={field.info.map((info, i) => ( +
{info}
+ ))} />
) : null} {indexPattern.timeFieldName === name ? (   - + ) : null}
@@ -89,11 +82,12 @@ export class TableComponent extends PureComponent { const { intl } = this.props; const label = intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.multiTypeAria', - defaultMessage: 'Multiple type field' + defaultMessage: 'Multiple type field', }); const content = intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.multiTypeTooltip', - defaultMessage: 'The type of this field changes across indices. It is unavailable for many analysis functions.' + defaultMessage: + 'The type of this field changes across indices. It is unavailable for many analysis functions.', }); return ( @@ -102,14 +96,11 @@ export class TableComponent extends PureComponent { {isConflict ? (   - + - ) : ''} + ) : ( + '' + )} ); } @@ -119,13 +110,16 @@ export class TableComponent extends PureComponent { const pagination = { initialPageSize: 10, - pageSizeOptions: [5, 10, 25, 50] + pageSizeOptions: [5, 10, 25, 50], }; const columns = [ { field: 'displayName', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.nameHeader', defaultMessage: 'Name' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.nameHeader', + defaultMessage: 'Name', + }), dataType: 'string', sortable: true, render: (value, field) => { @@ -136,77 +130,112 @@ export class TableComponent extends PureComponent { }, { field: 'type', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.typeHeader', defaultMessage: 'Type' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.typeHeader', + defaultMessage: 'Type', + }), dataType: 'string', sortable: true, - render: (value) => { + render: value => { return this.renderFieldType(value, value === 'conflict'); }, 'data-test-subj': 'indexedFieldType', }, { field: 'format', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.formatHeader', defaultMessage: 'Format' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.formatHeader', + defaultMessage: 'Format', + }), dataType: 'string', sortable: true, }, { field: 'searchable', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.searchableHeader', defaultMessage: 'Searchable' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.searchableHeader', + defaultMessage: 'Searchable', + }), description: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.searchableDescription', - defaultMessage: 'These fields can be used in the filter bar' }), + defaultMessage: 'These fields can be used in the filter bar', + }), dataType: 'boolean', sortable: true, - render: (value) => this.renderBooleanTemplate(value, intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.isSearchableAria', defaultMessage: 'Is searchable' })), + render: value => + this.renderBooleanTemplate( + value, + intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.isSearchableAria', + defaultMessage: 'Is searchable', + }) + ), }, { field: 'aggregatable', name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.aggregatableLabel', defaultMessage: 'Aggregatable' }), + id: 'kbn.management.editIndexPattern.fields.table.aggregatableLabel', + defaultMessage: 'Aggregatable', + }), description: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.aggregatableDescription', - defaultMessage: 'These fields can be used in visualization aggregations' }), + defaultMessage: 'These fields can be used in visualization aggregations', + }), dataType: 'boolean', sortable: true, - render: (value) => this.renderBooleanTemplate(value, intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.isAggregatableAria', defaultMessage: 'Is aggregatable' })), + render: value => + this.renderBooleanTemplate( + value, + intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.isAggregatableAria', + defaultMessage: 'Is aggregatable', + }) + ), }, { field: 'excluded', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.excludedLabel', defaultMessage: 'Excluded' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.excludedLabel', + defaultMessage: 'Excluded', + }), description: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.excludedDescription', - defaultMessage: 'Fields that are excluded from _source when it is fetched' }), + defaultMessage: 'Fields that are excluded from _source when it is fetched', + }), dataType: 'boolean', sortable: true, - render: (value) => this.renderBooleanTemplate(value, intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.isExcludedAria', defaultMessage: 'Is excluded' })), + render: value => + this.renderBooleanTemplate( + value, + intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.isExcludedAria', + defaultMessage: 'Is excluded', + }) + ), }, { name: '', actions: [ { - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.fields.table.editLabel', defaultMessage: 'Edit' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.fields.table.editLabel', + defaultMessage: 'Edit', + }), description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.editDescription', defaultMessage: 'Edit' }), + id: 'kbn.management.editIndexPattern.fields.table.editDescription', + defaultMessage: 'Edit', + }), icon: 'pencil', onClick: editField, type: 'icon', }, ], width: '40px', - } + }, ]; return ( - + ); } } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js index d786d64a67a5f..be4319b36575c 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js @@ -20,9 +20,7 @@ import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; -import { - EuiInMemoryTable, -} from '@elastic/eui'; +import { EuiInMemoryTable } from '@elastic/eui'; import { injectI18n } from '@kbn/i18n/react'; @@ -32,77 +30,109 @@ export class TableComponent extends PureComponent { items: PropTypes.array.isRequired, editField: PropTypes.func.isRequired, deleteField: PropTypes.func.isRequired, - } + }; - renderFormatCell = (value) => { + renderFormatCell = value => { const { indexPattern } = this.props; - const title = indexPattern.fieldFormatMap[value] && indexPattern.fieldFormatMap[value].type - ? indexPattern.fieldFormatMap[value].type.title - : ''; + const title = + indexPattern.fieldFormatMap[value] && indexPattern.fieldFormatMap[value].type + ? indexPattern.fieldFormatMap[value].type.title + : ''; - return ( - {title} - ); - } + return {title}; + }; render() { - const { - items, - editField, - deleteField, - intl, - } = this.props; + const { items, editField, deleteField, intl } = this.props; - const columns = [{ - field: 'displayName', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.scripted.table.nameHeader', defaultMessage: 'Name' }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.nameDescription', defaultMessage: 'Name of the field' }), - dataType: 'string', - sortable: true, - width: '38%', - }, { - field: 'lang', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.scripted.table.langHeader', defaultMessage: 'Lang' }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.langDescription', - defaultMessage: 'Language used for the field' }), - dataType: 'string', - sortable: true, - 'data-test-subj': 'scriptedFieldLang', - }, { - field: 'script', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.scripted.table.scriptHeader', defaultMessage: 'Script' }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.scriptDescription', defaultMessage: 'Script for the field' }), - dataType: 'string', - sortable: true, - }, { - field: 'name', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.scripted.table.formatHeader', defaultMessage: 'Format' }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.formatDescription', defaultMessage: 'Format used for the field' }), - render: this.renderFormatCell, - sortable: false, - }, { - name: '', - actions: [{ - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.scripted.table.editHeader', defaultMessage: 'Edit' }), + const columns = [ + { + field: 'displayName', + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.nameHeader', + defaultMessage: 'Name', + }), + description: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.nameDescription', + defaultMessage: 'Name of the field', + }), + dataType: 'string', + sortable: true, + width: '38%', + }, + { + field: 'lang', + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.langHeader', + defaultMessage: 'Lang', + }), + description: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.langDescription', + defaultMessage: 'Language used for the field', + }), + dataType: 'string', + sortable: true, + 'data-test-subj': 'scriptedFieldLang', + }, + { + field: 'script', + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.scriptHeader', + defaultMessage: 'Script', + }), description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.editDescription', defaultMessage: 'Edit this field' }), - icon: 'pencil', - onClick: editField, - }, { - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.scripted.table.deleteHeader', defaultMessage: 'Delete' }), + id: 'kbn.management.editIndexPattern.scripted.table.scriptDescription', + defaultMessage: 'Script for the field', + }), + dataType: 'string', + sortable: true, + }, + { + field: 'name', + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.formatHeader', + defaultMessage: 'Format', + }), description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.deleteDescription', defaultMessage: 'Delete this field' }), - icon: 'trash', - color: 'danger', - onClick: deleteField, - }], - width: '40px', - }]; + id: 'kbn.management.editIndexPattern.scripted.table.formatDescription', + defaultMessage: 'Format used for the field', + }), + render: this.renderFormatCell, + sortable: false, + }, + { + name: '', + actions: [ + { + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.editHeader', + defaultMessage: 'Edit', + }), + description: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.editDescription', + defaultMessage: 'Edit this field', + }), + icon: 'pencil', + onClick: editField, + }, + { + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.deleteHeader', + defaultMessage: 'Delete', + }), + description: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.scripted.table.deleteDescription', + defaultMessage: 'Delete this field', + }), + icon: 'trash', + color: 'danger', + onClick: deleteField, + }, + ], + width: '40px', + }, + ]; const pagination = { initialPageSize: 10, @@ -110,12 +140,7 @@ export class TableComponent extends PureComponent { }; return ( - + ); } } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js index 47084161a484a..311ebb413250f 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js @@ -20,19 +20,14 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { - EuiFlexGroup, - EuiFlexItem, - EuiFieldText, - EuiButton, -} from '@elastic/eui'; +import { EuiFlexGroup, EuiFlexItem, EuiFieldText, EuiButton } from '@elastic/eui'; import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; export class AddFilterComponent extends Component { static propTypes = { onAddFilter: PropTypes.func.isRequired, - } + }; constructor(props) { super(props); @@ -44,14 +39,15 @@ export class AddFilterComponent extends Component { onAddFilter = () => { this.props.onAddFilter(this.state.filter); this.setState({ filter: '' }); - } + }; render() { const { filter } = this.state; const { intl } = this.props; const placeholder = intl.formatMessage({ id: 'kbn.management.editIndexPattern.sourcePlaceholder', - defaultMessage: 'source filter, accepts wildcards (e.g., `user*` to filter fields starting with \'user\')' + defaultMessage: + 'source filter, accepts wildcards (e.g., `user*` to filter fields starting with \'user\')', }); return ( @@ -65,11 +61,11 @@ export class AddFilterComponent extends Component { /> - - + + diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js index 768e9d330e0ac..c08c787248a79 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js @@ -51,8 +51,7 @@ export class TableComponent extends Component { startEditingFilter = (id, value) => this.setState({ editingFilterId: id, editingFilterValue: value }); stopEditingFilter = () => this.setState({ editingFilterId: null }); - onEditingFilterChange = e => - this.setState({ editingFilterValue: e.target.value }); + onEditingFilterChange = e => this.setState({ editingFilterValue: e.target.value }); onEditFieldKeyDown = ({ keyCode }) => { if (keyCodes.ENTER === keyCode) { @@ -68,20 +67,19 @@ export class TableComponent extends Component { }; getColumns() { - const { - deleteFilter, - fieldWildcardMatcher, - indexPattern, - saveFilter, - intl, - } = this.props; + const { deleteFilter, fieldWildcardMatcher, indexPattern, saveFilter, intl } = this.props; return [ { field: 'value', - name: intl.formatMessage({ id: 'kbn.management.editIndexPattern.source.table.filterHeader', defaultMessage: 'Filter' }), + name: intl.formatMessage({ + id: 'kbn.management.editIndexPattern.source.table.filterHeader', + defaultMessage: 'Filter', + }), description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.filterDescription', defaultMessage: 'Filter name' }), + id: 'kbn.management.editIndexPattern.source.table.filterDescription', + defaultMessage: 'Filter name', + }), dataType: 'string', sortable: true, render: (value, filter) => { @@ -102,17 +100,18 @@ export class TableComponent extends Component { { field: 'value', name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.matchesHeader', defaultMessage: 'Matches' }), + id: 'kbn.management.editIndexPattern.source.table.matchesHeader', + defaultMessage: 'Matches', + }), description: intl.formatMessage({ id: 'kbn.management.editIndexPattern.source.table.matchesDescription', - defaultMessage: 'Language used for the field' }), + defaultMessage: 'Language used for the field', + }), dataType: 'string', sortable: true, render: (value, filter) => { const realtimeValue = - this.state.editingFilterId === filter.clientId - ? this.state.editingFilterValue - : value; + this.state.editingFilterId === filter.clientId ? this.state.editingFilterValue : value; const matcher = fieldWildcardMatcher([realtimeValue]); const matches = indexPattern .getNonScriptedFields() @@ -152,7 +151,9 @@ export class TableComponent extends Component { }} iconType="checkInCircleFilled" aria-label={intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.saveAria', defaultMessage: 'Save' })} + id: 'kbn.management.editIndexPattern.source.table.saveAria', + defaultMessage: 'Save', + })} /> ); @@ -175,16 +178,18 @@ export class TableComponent extends Component { onClick={() => deleteFilter(filter)} iconType="trash" aria-label={intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.deleteAria', defaultMessage: 'Delete' })} + id: 'kbn.management.editIndexPattern.source.table.deleteAria', + defaultMessage: 'Delete', + })} /> - this.startEditingFilter(filter.clientId, filter.value) - } + onClick={() => this.startEditingFilter(filter.clientId, filter.value)} iconType="pencil" aria-label={intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.editAria', defaultMessage: 'Edit' })} + id: 'kbn.management.editIndexPattern.source.table.editAria', + defaultMessage: 'Edit', + })} /> ); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js index 625a32485de0f..8a25e40ba58b9 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js @@ -97,10 +97,7 @@ class FlyoutUI extends Component { } fetchIndexPatterns = async () => { - const indexPatterns = await this.props.indexPatterns.getFields([ - 'id', - 'title', - ]); + const indexPatterns = await this.props.indexPatterns.getFields(['id', 'title']); this.setState({ indexPatterns }); }; @@ -153,7 +150,7 @@ class FlyoutUI extends Component { this.resolveImportErrors(); } }); - } + }; /** * Get Conflict Resolutions @@ -163,10 +160,10 @@ class FlyoutUI extends Component { * @param {array} objects List of objects to request the user if they wish to overwrite it * @return {Promise} An object with the key being "type:id" and value the resolution chosen by the user */ - getConflictResolutions = async (objects) => { + getConflictResolutions = async objects => { const resolutions = {}; for (const { type, id, title } of objects) { - const overwrite = await new Promise((resolve) => { + const overwrite = await new Promise(resolve => { this.setState({ conflictingRecord: { id, @@ -180,7 +177,7 @@ class FlyoutUI extends Component { this.setState({ conflictingRecord: undefined }); } return resolutions; - } + }; /** * Resolve Import Errors @@ -211,7 +208,7 @@ class FlyoutUI extends Component { }), }); } - } + }; legacyImport = async () => { const { services, indexPatterns, intl, confirmModalPromise } = this.props; @@ -247,17 +244,17 @@ class FlyoutUI extends Component { return; } - contents = contents.filter(content => - POSSIBLE_TYPES.includes(content._type) - ).map(doc => ({ - ...doc, - // The server assumes that documents with no migrationVersion are up to date. - // That assumption enables Kibana and other API consumers to not have to build - // up migrationVersion prior to creating new objects. But it means that imports - // need to set migrationVersion to something other than undefined, so that imported - // docs are not seen as automatically up-to-date. - _migrationVersion: doc._migrationVersion || {}, - })); + contents = contents + .filter(content => POSSIBLE_TYPES.includes(content._type)) + .map(doc => ({ + ...doc, + // The server assumes that documents with no migrationVersion are up to date. + // That assumption enables Kibana and other API consumers to not have to build + // up migrationVersion prior to creating new objects. But it means that imports + // need to set migrationVersion to something other than undefined, so that imported + // docs are not seen as automatically up-to-date. + _migrationVersion: doc._migrationVersion || {}, + })); const { conflictedIndexPatterns, @@ -277,7 +274,8 @@ class FlyoutUI extends Component { conflictedIndexPatterns .map(({ doc, obj }) => { return { doc, obj: obj._serialize() }; - }).forEach(({ doc, obj }) => + }) + .forEach(({ doc, obj }) => obj.references.forEach(ref => { byId[ref.id] = byId[ref.id] != null ? byId[ref.id].concat({ doc, obj }) : [{ doc, obj }]; }) @@ -334,7 +332,7 @@ class FlyoutUI extends Component { isOverwriteAllChecked, conflictedSavedObjectsLinkedToSavedSearches, conflictedSearchDocs, - failedImports + failedImports, } = this.state; const { services, indexPatterns, intl } = this.props; @@ -354,7 +352,8 @@ class FlyoutUI extends Component { // Do not Promise.all these calls as the order matters this.setState({ loadingMessage: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.resolvingConflictsLoadingMessage', + id: + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.resolvingConflictsLoadingMessage', defaultMessage: 'Resolving conflicts…', }), }); @@ -367,7 +366,8 @@ class FlyoutUI extends Component { } this.setState({ loadingMessage: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savingConflictsLoadingMessage', + id: + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savingConflictsLoadingMessage', defaultMessage: 'Saving conflicts…', }), }); @@ -377,7 +377,8 @@ class FlyoutUI extends Component { ); this.setState({ loadingMessage: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savedSearchAreLinkedProperlyLoadingMessage', + id: + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savedSearchAreLinkedProperlyLoadingMessage', defaultMessage: 'Ensure saved searches are linked properly…', }), }); @@ -389,7 +390,8 @@ class FlyoutUI extends Component { ); this.setState({ loadingMessage: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.retryingFailedObjectsLoadingMessage', + id: + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.retryingFailedObjectsLoadingMessage', defaultMessage: 'Retrying failed objects…', }), }); @@ -471,17 +473,21 @@ class FlyoutUI extends Component { { field: 'list', name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsName', + id: + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsName', defaultMessage: 'Sample of affected objects', }), description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsDescription', + id: + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsDescription', defaultMessage: 'Sample of affected objects', }), render: list => { return (
    - {take(list, 3).map((obj, key) =>
  • {obj.title}
  • )} + {take(list, 3).map((obj, key) => ( +
  • {obj.title}
  • + ))}
); }, @@ -489,7 +495,8 @@ class FlyoutUI extends Component { { field: 'existingIndexPatternId', name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnNewIndexPatternName', + id: + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnNewIndexPatternName', defaultMessage: 'New index pattern', }), render: id => { @@ -520,11 +527,7 @@ class FlyoutUI extends Component { }; return ( - + ); } @@ -538,9 +541,12 @@ class FlyoutUI extends Component { return ( - )} + title={ + + } color="danger" >

{error}

@@ -576,12 +582,18 @@ class FlyoutUI extends Component { } // Kept backwards compatible logic - if (failedImports.length && (!this.hasUnmatchedReferences || (isLegacyFile === false && status === 'success'))) { + if ( + failedImports.length && + (!this.hasUnmatchedReferences || (isLegacyFile === false && status === 'success')) + ) { return ( - )} + title={ + + } color="warning" iconType="help" > @@ -589,40 +601,46 @@ class FlyoutUI extends Component {

- {failedImports.map(({ error, obj }) => { - if (error.type === 'missing_references') { - return error.references.map((reference) => { + {failedImports + .map(({ error, obj }) => { + if (error.type === 'missing_references') { + return error.references.map(reference => { + return intl.formatMessage( + { + id: + 'kbn.management.objects.objectsTable.flyout.importFailedMissingReference', + defaultMessage: '{type} [id={id}] could not locate {refType} [id={refId}]', + }, + { + id: obj.id, + type: obj.type, + refId: reference.id, + refType: reference.type, + } + ); + }); + } else if (error.type === 'unsupported_type') { return intl.formatMessage( { - id: 'kbn.management.objects.objectsTable.flyout.importFailedMissingReference', - defaultMessage: '{type} [id={id}] could not locate {refType} [id={refId}]', + id: 'kbn.management.objects.objectsTable.flyout.importFailedUnsupportedType', + defaultMessage: '{type} [id={id}] unsupported type', }, { id: obj.id, type: obj.type, - refId: reference.id, - refType: reference.type, } ); - }); - } else if (error.type === 'unsupported_type') { - return intl.formatMessage( - { - id: 'kbn.management.objects.objectsTable.flyout.importFailedUnsupportedType', - defaultMessage: '{type} [id={id}] unsupported type', - }, - { - id: obj.id, - type: obj.type, - }, - ); - } - return getField(error, 'body.message', error.message || ''); - }).join(' ')} + } + return getField(error, 'body.message', error.message || ''); + }) + .join(' ')}

); @@ -633,12 +651,12 @@ class FlyoutUI extends Component { return ( - )} + } color="primary" /> ); @@ -647,12 +665,12 @@ class FlyoutUI extends Component { return ( - )} + } color="success" iconType="check" > @@ -674,32 +692,32 @@ class FlyoutUI extends Component { return ( - )} + } > - )} + } onChange={this.setImportFile} /> - )} + } data-test-subj="importSavedObjectsOverwriteToggle" checked={isOverwriteAllChecked} onChange={this.changeOverwriteAll} @@ -717,12 +735,7 @@ class FlyoutUI extends Component { if (status === 'success') { confirmButton = ( - + - )} + } color="warning" iconType="help" > @@ -811,12 +821,12 @@ class FlyoutUI extends Component { if (this.hasUnmatchedReferences) { indexPatternConflictsWarning = ( - )} + } color="warning" iconType="help" > @@ -824,7 +834,7 @@ class FlyoutUI extends Component { - ) + ), }} />

-
); +
+ ); } if (!legacyFileWarning && !indexPatternConflictsWarning) { @@ -847,18 +858,18 @@ class FlyoutUI extends Component { return ( - {legacyFileWarning && + {legacyFileWarning && ( {legacyFileWarning} - } - {indexPatternConflictsWarning && + )} + {indexPatternConflictsWarning && ( {indexPatternConflictsWarning} - } + )} ); } @@ -882,22 +893,18 @@ class FlyoutUI extends Component { title={intl.formatMessage( { id: 'kbn.management.objects.objectsTable.flyout.confirmOverwriteTitle', - defaultMessage: 'Overwrite {type}?' + defaultMessage: 'Overwrite {type}?', }, { type: this.state.conflictingRecord.type } )} - cancelButtonText={intl.formatMessage( - { - id: 'kbn.management.objects.objectsTable.flyout.confirmOverwriteCancelButtonText', - defaultMessage: 'Cancel', - }, - )} - confirmButtonText={intl.formatMessage( - { - id: 'kbn.management.objects.objectsTable.flyout.confirmOverwriteOverwriteButtonText', - defaultMessage: 'Overwrite', - }, - )} + cancelButtonText={intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.flyout.confirmOverwriteCancelButtonText', + defaultMessage: 'Cancel', + })} + confirmButtonText={intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.flyout.confirmOverwriteOverwriteButtonText', + defaultMessage: 'Overwrite', + })} buttonColor="danger" onCancel={this.overwriteSkipped.bind(this)} onConfirm={this.overwriteConfirmed.bind(this)} @@ -908,12 +915,15 @@ class FlyoutUI extends Component { id="kbn.management.objects.objectsTable.flyout.confirmOverwriteBody" defaultMessage="Are you sure you want to overwrite {title}?" values={{ - title: this.state.conflictingRecord.title || getDefaultTitle(this.state.conflictingRecord) + title: + this.state.conflictingRecord.title || + getDefaultTitle(this.state.conflictingRecord), }} />

- ); + + ); } return ( diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js index 3e7afe4a4d690..c5ed65606489b 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js @@ -89,9 +89,12 @@ class RelationshipsUI extends Component { return ( - )} + title={ + + } color="danger" > {error} @@ -120,18 +123,14 @@ class RelationshipsUI extends Component { }), width: '50px', align: 'center', - description: - intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnTypeDescription', - defaultMessage: 'Type of the saved object', - }), + description: intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.relationships.columnTypeDescription', + defaultMessage: 'Type of the saved object', + }), sortable: false, render: (type, object) => { return ( - + {title || getDefaultTitle(object)} - ); + return {title || getDefaultTitle(object)}; } return ( {title || getDefaultTitle(object)} @@ -207,14 +203,15 @@ class RelationshipsUI extends Component { actions: [ { name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionName', + id: + 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionName', defaultMessage: 'Inspect', }), - description: - intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionDescription', - defaultMessage: 'Inspect this saved object', - }), + description: intl.formatMessage({ + id: + 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionDescription', + defaultMessage: 'Inspect this saved object', + }), type: 'icon', icon: 'inspect', onClick: object => goInspectObject(object), @@ -241,7 +238,8 @@ class RelationshipsUI extends Component { type: 'field_value_selection', field: 'relationship', name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.name', + id: + 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.name', defaultMessage: 'Direct relationship', }), multiSelect: 'or', @@ -250,7 +248,8 @@ class RelationshipsUI extends Component { value: 'parent', name: 'parent', view: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.parentAsValue.view', + id: + 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.parentAsValue.view', defaultMessage: 'Parent', }), }, @@ -258,7 +257,8 @@ class RelationshipsUI extends Component { value: 'child', name: 'child', view: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.childAsValue.view', + id: + 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.childAsValue.view', defaultMessage: 'Child', }), }, @@ -281,14 +281,18 @@ class RelationshipsUI extends Component {

- {intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.relationshipsTitle', - defaultMessage: 'Here are the saved objects related to {title}. ' + - 'Deleting this {type} affects its parent objects, but not its children.', - }, { - type: savedObject.type, - title: savedObject.meta.title || getDefaultTitle(savedObject) - })} + {intl.formatMessage( + { + id: 'kbn.management.objects.objectsTable.relationships.relationshipsTitle', + defaultMessage: + 'Here are the saved objects related to {title}. ' + + 'Deleting this {type} affects its parent objects, but not its children.', + }, + { + type: savedObject.type, + title: savedObject.meta.title || getDefaultTitle(savedObject), + } + )}

diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js index 672cb23baf5a2..b1887c32a9a1d 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js @@ -34,7 +34,7 @@ import { EuiPopover, EuiSwitch, EuiFormRow, - EuiText + EuiText, } from '@elastic/eui'; import { getDefaultTitle, getSavedObjectLabel } from '../../../../lib'; import { i18n } from '@kbn/i18n'; @@ -59,7 +59,7 @@ class TableUI extends PureComponent { items: PropTypes.array.isRequired, itemId: PropTypes.oneOfType([ PropTypes.string, // the name of the item id property - PropTypes.func // (item) => string + PropTypes.func, // (item) => string ]), totalItemCount: PropTypes.number.isRequired, onQueryChange: PropTypes.func.isRequired, @@ -75,7 +75,7 @@ class TableUI extends PureComponent { isExportPopoverOpen: false, isIncludeReferencesDeepChecked: true, activeAction: null, - } + }; constructor(props) { super(props); @@ -96,30 +96,30 @@ class TableUI extends PureComponent { parseErrorMessage: null, }); this.props.onQueryChange({ query }); - } + }; closeExportPopover = () => { this.setState({ isExportPopoverOpen: false }); - } + }; toggleExportPopoverVisibility = () => { this.setState(state => ({ - isExportPopoverOpen: !state.isExportPopoverOpen + isExportPopoverOpen: !state.isExportPopoverOpen, })); - } + }; toggleIsIncludeReferencesDeepChecked = () => { this.setState(state => ({ isIncludeReferencesDeepChecked: !state.isIncludeReferencesDeepChecked, })); - } + }; onExportClick = () => { const { onExport } = this.props; const { isIncludeReferencesDeepChecked } = this.state; onExport(isIncludeReferencesDeepChecked); this.setState({ isExportPopoverOpen: false }); - } + }; render() { const { @@ -150,7 +150,10 @@ class TableUI extends PureComponent { { type: 'field_value_selection', field: 'type', - name: intl.formatMessage({ id: 'kbn.management.objects.objectsTable.table.typeFilterName', defaultMessage: 'Type' }), + name: intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.table.typeFilterName', + defaultMessage: 'Type', + }), multiSelect: 'or', options: filterOptions, }, @@ -167,20 +170,20 @@ class TableUI extends PureComponent { const columns = [ { field: 'type', - name: intl.formatMessage({ id: 'kbn.management.objects.objectsTable.table.columnTypeName', defaultMessage: 'Type' }), + name: intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.table.columnTypeName', + defaultMessage: 'Type', + }), width: '50px', align: 'center', - description: - intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnTypeDescription', defaultMessage: 'Type of the saved object' - }), + description: intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.table.columnTypeDescription', + defaultMessage: 'Type of the saved object', + }), sortable: false, render: (type, object) => { return ( - + {title || getDefaultTitle(object)} - ); + return {title || getDefaultTitle(object)}; } return ( {title || getDefaultTitle(object)} @@ -213,34 +217,37 @@ class TableUI extends PureComponent { }, }, { - name: intl.formatMessage({ id: 'kbn.management.objects.objectsTable.table.columnActionsName', defaultMessage: 'Actions' }), + name: intl.formatMessage({ + id: 'kbn.management.objects.objectsTable.table.columnActionsName', + defaultMessage: 'Actions', + }), actions: [ { name: intl.formatMessage({ id: 'kbn.management.objects.objectsTable.table.columnActions.inspectActionName', - defaultMessage: 'Inspect' + defaultMessage: 'Inspect', + }), + description: intl.formatMessage({ + id: + 'kbn.management.objects.objectsTable.table.columnActions.inspectActionDescription', + defaultMessage: 'Inspect this saved object', }), - description: - intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnActions.inspectActionDescription', - defaultMessage: 'Inspect this saved object' - }), type: 'icon', icon: 'inspect', onClick: object => goInspectObject(object), available: object => !!object.meta.editUrl, }, { - name: - intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionName', - defaultMessage: 'Relationships' - }), - description: - intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionDescription', - defaultMessage: 'View the relationships this saved object has to other saved objects' - }), + name: intl.formatMessage({ + id: + 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionName', + defaultMessage: 'Relationships', + }), + description: intl.formatMessage({ + id: + 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionDescription', + defaultMessage: 'View the relationships this saved object has to other saved objects', + }), type: 'icon', icon: 'kqlSelector', onClick: object => onShowRelationships(object), @@ -248,9 +255,9 @@ class TableUI extends PureComponent { ...this.extraActions.map(action => { return { ...action.euiAction, - onClick: (object) => { + onClick: object => { this.setState({ - activeAction: action + activeAction: action, }); action.registerOnFinishCallback(() => { @@ -260,9 +267,9 @@ class TableUI extends PureComponent { }); action.euiAction.onClick(object); - } + }, }; - }) + }), ], }, ]; @@ -274,9 +281,7 @@ class TableUI extends PureComponent { defaultMessage: 'Unable to parse query', }); queryParseError = ( - - {`${parseErrorMsg}. ${this.state.parseErrorMessage}`} - + {`${parseErrorMsg}. ${this.state.parseErrorMessage}`} ); } @@ -309,17 +314,13 @@ class TableUI extends PureComponent { iconType="trash" color="danger" onClick={onDelete} - isDisabled={ - selectedSavedObjects.length === 0 || - !this.props.canDelete - } + isDisabled={selectedSavedObjects.length === 0 || !this.props.canDelete} title={ this.props.canDelete ? undefined - : i18n.translate( - 'kbn.management.objects.objectsTable.table.deleteButtonTitle', - { defaultMessage: 'Unable to delete saved objects' } - ) + : i18n.translate('kbn.management.objects.objectsTable.table.deleteButtonTitle', { + defaultMessage: 'Unable to delete saved objects', + }) } data-test-subj="savedObjectsManagementDelete" > @@ -335,32 +336,27 @@ class TableUI extends PureComponent { closePopover={this.closeExportPopover} > - )} + } > - )} + } checked={this.state.isIncludeReferencesDeepChecked} onChange={this.toggleIsIncludeReferencesDeepChecked} /> - + { - this.setState({ - isSearching: true, - }, this.debouncedFetch); - } + this.setState( + { + isSearching: true, + }, + this.debouncedFetch + ); + }; debouncedFetch = debounce(async () => { const { intl } = this.props; @@ -181,9 +184,7 @@ class ObjectsTableUI extends Component { perPage, page: page + 1, fields: ['id'], - type: this.savedObjectTypes.filter( - type => !visibleTypes || visibleTypes.includes(type) - ), + type: this.savedObjectTypes.filter(type => !visibleTypes || visibleTypes.includes(type)), }; if (findOptions.type.length > 1) { findOptions.sortField = 'type'; @@ -201,7 +202,7 @@ class ObjectsTableUI extends Component { toastNotifications.addDanger({ title: intl.formatMessage({ id: 'kbn.management.objects.objectsTable.unableFindSavedObjectsNotificationMessage', - defaultMessage: 'Unable find saved objects' + defaultMessage: 'Unable find saved objects', }), text: `${error}`, }); @@ -253,14 +254,17 @@ class ObjectsTableUI extends Component { onTableChange = async table => { const { index: page, size: perPage } = table.page || {}; - this.setState({ - page, - perPage, - selectedSavedObjects: [], - }, this.fetchSavedObjects); + this.setState( + { + page, + perPage, + selectedSavedObjects: [], + }, + this.fetchSavedObjects + ); }; - onShowRelationships = (object) => { + onShowRelationships = object => { this.setState({ isShowingRelationships: true, relationshipObject: object, @@ -274,7 +278,7 @@ class ObjectsTableUI extends Component { }); }; - onExport = async (includeReferencesDeep) => { + onExport = async includeReferencesDeep => { const { intl } = this.props; const { selectedSavedObjects } = this.state; const objectsToExport = selectedSavedObjects.map(obj => ({ id: obj.id, type: obj.type })); @@ -304,15 +308,12 @@ class ObjectsTableUI extends Component { onExportAll = async () => { const { intl } = this.props; const { exportAllSelectedOptions, isIncludeReferencesDeepChecked } = this.state; - const exportTypes = Object.entries(exportAllSelectedOptions).reduce( - (accum, [id, selected]) => { - if (selected) { - accum.push(id); - } - return accum; - }, - [] - ); + const exportTypes = Object.entries(exportAllSelectedOptions).reduce((accum, [id, selected]) => { + if (selected) { + accum.push(id); + } + return accum; + }, []); let blob; try { @@ -365,9 +366,7 @@ class ObjectsTableUI extends Component { this.setState({ isDeleting: true }); - const indexPatterns = selectedSavedObjects.filter( - object => object.type === 'index-pattern' - ); + const indexPatterns = selectedSavedObjects.filter(object => object.type === 'index-pattern'); if (indexPatterns.length) { await this.props.indexPatterns.clearCache(); } @@ -440,11 +439,7 @@ class ObjectsTableUI extends Component { } renderDeleteConfirmModal() { - const { - isShowingDeleteConfirmModal, - isDeleting, - selectedSavedObjects, - } = this.state; + const { isShowingDeleteConfirmModal, isDeleting, selectedSavedObjects } = this.state; const { intl } = this.props; if (!isShowingDeleteConfirmModal) { @@ -455,9 +450,7 @@ class ObjectsTableUI extends Component { if (isDeleting) { // Block the user from interacting with the table while its contents are being deleted. - modal = ( - - ); + modal = ; } else { const onCancel = () => { this.setState({ isShowingDeleteConfirmModal: false }); @@ -478,22 +471,24 @@ class ObjectsTableUI extends Component { onCancel={onCancel} onConfirm={onConfirm} buttonColor="danger" - cancelButtonText={( + cancelButtonText={ - )} + } confirmButtonText={ - isDeleting - ? () - : ( + ) : ( + ) + /> + ) } defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON} > @@ -509,14 +504,13 @@ class ObjectsTableUI extends Component { { field: 'type', name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.typeColumnName', defaultMessage: 'Type' + id: + 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.typeColumnName', + defaultMessage: 'Type', }), width: '50px', render: (type, object) => ( - + ), @@ -524,13 +518,16 @@ class ObjectsTableUI extends Component { { field: 'id', name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.idColumnName', defaultMessage: 'Id' + id: + 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.idColumnName', + defaultMessage: 'Id', }), }, { field: 'meta.title', name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.titleColumnName', + id: + 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.titleColumnName', defaultMessage: 'Title', }), }, @@ -542,22 +539,18 @@ class ObjectsTableUI extends Component { ); } - return ( - - {modal} - - ); + return {modal}; } changeIncludeReferencesDeep = () => { this.setState(state => ({ isIncludeReferencesDeepChecked: !state.isIncludeReferencesDeepChecked, })); - } + }; closeExportAllModal = () => { this.setState({ isShowingExportAllOptionsModal: false }); - } + }; renderExportAllOptionsModal() { const { @@ -574,26 +567,26 @@ class ObjectsTableUI extends Component { return ( - + } + label={ + + } labelType="legend" > - )} + } checked={isIncludeReferencesDeepChecked} onChange={this.changeIncludeReferencesDeep} /> @@ -677,17 +670,13 @@ class ObjectsTableUI extends Component { })); return ( - + {this.renderFlyout()} {this.renderRelationships()} {this.renderDeleteConfirmModal()} {this.renderExportAllOptionsModal()}
- this.setState({ isShowingExportAllOptionsModal: true }) - } + onExportAll={() => this.setState({ isShowingExportAllOptionsModal: true })} onImport={this.showImportFlyout} onRefresh={this.refreshData} filteredCount={filteredItemCount} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js index c0b1188950126..fe0814b01d3ea 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js @@ -52,13 +52,12 @@ import { isDefaultValue } from '../../lib'; import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; class FieldUI extends PureComponent { - static propTypes = { setting: PropTypes.object.isRequired, save: PropTypes.func.isRequired, clear: PropTypes.func.isRequired, enableSaving: PropTypes.bool.isRequired, - } + }; constructor(props) { super(props); @@ -84,12 +83,12 @@ class FieldUI extends PureComponent { this.setState({ savedValue: editableValue, - unsavedValue: (value === null || value === undefined) ? editableValue : unsavedValue, + unsavedValue: value === null || value === undefined ? editableValue : unsavedValue, }); } getEditableValue(type, value, defVal) { - const val = (value === null || value === undefined) ? defVal : value; + const val = value === null || value === undefined ? defVal : value; switch (type) { case 'array': return val.join(', '); @@ -120,7 +119,7 @@ class FieldUI extends PureComponent { setLoading(loading) { this.setState({ - loading + loading, }); } @@ -131,7 +130,7 @@ class FieldUI extends PureComponent { }); } - onCodeEditorChange = (value) => { + onCodeEditorChange = value => { const { type } = this.props.setting; const { isJsonArray } = this.state; @@ -150,7 +149,8 @@ class FieldUI extends PureComponent { ); + /> + ); } break; default: @@ -162,9 +162,9 @@ class FieldUI extends PureComponent { isInvalid, unsavedValue: newUnsavedValue, }); - } + }; - onFieldChange = (e) => { + onFieldChange = e => { const value = e.target.value; const { type, validation } = this.props.setting; const { unsavedValue } = this.state; @@ -197,7 +197,7 @@ class FieldUI extends PureComponent { isInvalid, error }); - } + }; onFieldKeyDown = ({ keyCode }) => { if (keyCode === keyCodes.ENTER) { @@ -206,15 +206,15 @@ class FieldUI extends PureComponent { if (keyCode === keyCodes.ESCAPE) { this.cancelEdit(); } - } + }; onFieldEscape = ({ keyCode }) => { if (keyCode === keyCodes.ESCAPE) { this.cancelEdit(); } - } + }; - onImageChange = async (files) => { + onImageChange = async files => { if (!files.length) { this.clearError(); this.setState({ @@ -231,12 +231,16 @@ class FieldUI extends PureComponent { this.setState({ isInvalid, error: isInvalid - ? this.props.intl.formattedMessage({ - id: 'kbn.management.settings.field.imageTooLargeErrorMessage', - defaultMessage: 'Image is too large, maximum size is {maxSizeDescription}' - }, { - maxSizeDescription: maxSize.description - }) : null, + ? this.props.intl.formattedMessage( + { + id: 'kbn.management.settings.field.imageTooLargeErrorMessage', + defaultMessage: 'Image is too large, maximum size is {maxSizeDescription}', + }, + { + maxSizeDescription: maxSize.description, + } + ) + : null, changeImage: true, unsavedValue: base64Image, }); @@ -244,12 +248,12 @@ class FieldUI extends PureComponent { toastNotifications.addDanger( this.props.intl.formatMessage({ id: 'kbn.management.settings.field.imageChangeErrorMessage', - defaultMessage: 'Image could not be saved' + defaultMessage: 'Image could not be saved', }) ); this.cancelChangeImage(); } - } + }; getImageAsBase64(file) { if (!file instanceof File) { @@ -263,7 +267,7 @@ class FieldUI extends PureComponent { reader.onload = () => { resolve(reader.result); }; - reader.onerror = (err) => { + reader.onerror = err => { reject(err); }; }); @@ -273,7 +277,7 @@ class FieldUI extends PureComponent { this.setState({ changeImage: true, }); - } + }; cancelChangeImage = () => { const { savedValue } = this.state; @@ -287,7 +291,7 @@ class FieldUI extends PureComponent { changeImage: false, unsavedValue: savedValue, }); - } + }; cancelEdit = () => { const { savedValue } = this.state; @@ -295,17 +299,21 @@ class FieldUI extends PureComponent { this.setState({ unsavedValue: savedValue, }); - } + }; showPageReloadToast = () => { if (this.props.setting.requiresPageReload) { toastNotifications.add({ - title: this.props.intl.formatMessage({ - id: 'kbn.management.settings.field.requiresPageReloadToastDescription', - defaultMessage: 'Please reload the page for the "{settingName}" setting to take effect.', - }, { - settingName: this.props.setting.displayName || this.props.setting.name, - }), + title: this.props.intl.formatMessage( + { + id: 'kbn.management.settings.field.requiresPageReloadToastDescription', + defaultMessage: + 'Please reload the page for the "{settingName}" setting to take effect.', + }, + { + settingName: this.props.setting.displayName || this.props.setting.name, + } + ), text: ( <> @@ -313,7 +321,7 @@ class FieldUI extends PureComponent { window.location.reload()}> {this.props.intl.formatMessage({ id: 'kbn.management.settings.field.requiresPageReloadToastButtonLabel', - defaultMessage: 'Reload page' + defaultMessage: 'Reload page', })} @@ -323,7 +331,7 @@ class FieldUI extends PureComponent { color: 'success', }); } - } + }; saveEdit = async () => { const { name, defVal, type } = this.props.setting; @@ -363,15 +371,17 @@ class FieldUI extends PureComponent { } } catch (e) { toastNotifications.addDanger( - this.props.intl.formatMessage({ - id: 'kbn.management.settings.field.saveFieldErrorMessage', - defaultMessage: 'Unable to save {name}' - }, - { name }) + this.props.intl.formatMessage( + { + id: 'kbn.management.settings.field.saveFieldErrorMessage', + defaultMessage: 'Unable to save {name}', + }, + { name } + ) ); } this.setLoading(false); - } + }; resetField = async () => { const { name } = this.props.setting; @@ -383,15 +393,17 @@ class FieldUI extends PureComponent { this.clearError(); } catch (e) { toastNotifications.addDanger( - this.props.intl.formatMessage({ - id: 'kbn.management.settings.field.resetFieldErrorMessage', - defaultMessage: 'Unable to reset {name}' - }, - { name }) + this.props.intl.formatMessage( + { + id: 'kbn.management.settings.field.resetFieldErrorMessage', + defaultMessage: 'Unable to reset {name}', + }, + { name } + ) ); } this.setLoading(false); - } + }; renderField(setting) { const { enableSaving } = this.props; @@ -402,17 +414,16 @@ class FieldUI extends PureComponent { case 'boolean': return ( - ) : ( - - )} + label={ + !!unsavedValue ? ( + + ) : ( + + ) + } checked={!!unsavedValue} onChange={this.onFieldChange} disabled={loading || isOverridden || !enableSaving} @@ -441,7 +452,7 @@ class FieldUI extends PureComponent { tabSize: 2, }} editorProps={{ - $blockScrolling: Infinity + $blockScrolling: Infinity, }} showGutter={false} /> @@ -449,21 +460,16 @@ class FieldUI extends PureComponent { ); case 'image': if (!isDefaultValue(setting) && !changeImage) { - return ( - - ); + return ; } else { return ( { this.changeImageForm = input; }} + ref={input => { + this.changeImageForm = input; + }} onKeyDown={this.onFieldEscape} data-test-subj={`advancedSetting-editField-${name}`} /> @@ -474,10 +480,10 @@ class FieldUI extends PureComponent { { + options={options.map(option => { return { text: optionLabels.hasOwnProperty(option) ? optionLabels[option] : option, - value: option + value: option, }; })} onChange={this.onFieldChange} @@ -550,7 +556,7 @@ class FieldUI extends PureComponent { return (

{setting.displayName || setting.name} - {setting.isCustom ? + {setting.isCustom ? ( )} + content={ + + } /> - : ''} + ) : ( + '' + )}

); } @@ -616,7 +626,7 @@ class FieldUI extends PureComponent { > {this.getDisplayedDefaultValue(type, defVal)} - ) + ), }} /> @@ -626,7 +636,9 @@ class FieldUI extends PureComponent { id="kbn.management.settings.field.defaultValueText" defaultMessage="Default: {value}" values={{ - value: ({this.getDisplayedDefaultValue(type, defVal, optionLabels)}), + value: ( + {this.getDisplayedDefaultValue(type, defVal, optionLabels)} + ), }} /> @@ -644,13 +656,15 @@ class FieldUI extends PureComponent { return ( @@ -673,13 +687,15 @@ class FieldUI extends PureComponent { return ( @@ -708,13 +724,15 @@ class FieldUI extends PureComponent { changeImage ? this.cancelChangeImage() : this.cancelEdit()} + aria-label={intl.formatMessage( + { + id: 'kbn.management.settings.field.cancelEditingButtonAriaLabel', + defaultMessage: 'Cancel editing {ariaName}', + }, + { + ariaName, + } + )} + onClick={() => (changeImage ? this.cancelChangeImage() : this.cancelEdit())} disabled={isDisabled} data-test-subj={`advancedSetting-cancelEditField-${name}`} > @@ -774,9 +794,7 @@ class FieldUI extends PureComponent { - - {this.renderActions(setting)} - + {this.renderActions(setting)}
); } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js index 21818a7932b0e..88091bb48bea5 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/form/form.js @@ -35,7 +35,6 @@ import { Field } from '../field'; import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; class FormUI extends PureComponent { - static propTypes = { settings: PropTypes.object.isRequired, categories: PropTypes.array.isRequired, @@ -45,7 +44,7 @@ class FormUI extends PureComponent { clear: PropTypes.func.isRequired, showNoResultsMessage: PropTypes.bool.isRequired, enableSaving: PropTypes.bool.isRequired, - } + }; renderClearQueryLink(totalSettings, currentSettings) { const { clearQuery } = this.props; @@ -58,7 +57,7 @@ class FormUI extends PureComponent { id="kbn.management.settings.form.searchResultText" defaultMessage="Search terms are hiding {settingsCount} settings {clearSearch}" values={{ - settingsCount: (totalSettings - currentSettings), + settingsCount: totalSettings - currentSettings, clearSearch: ( @@ -147,13 +146,11 @@ class FormUI extends PureComponent { return ( - { - currentCategories.length ? currentCategories.map((category) => { - return ( - this.renderCategory(category, settings[category], categoryCounts[category]) // fix this - ); - }) : this.maybeRenderNoSettings(clearQuery) - } + {currentCategories.length + ? currentCategories.map(category => { + return this.renderCategory(category, settings[category], categoryCounts[category]); // fix this + }) + : this.maybeRenderNoSettings(clearQuery)} ); } diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js index 2006839877d5b..a85e2299e7502 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js @@ -21,15 +21,11 @@ import React, { Fragment, PureComponent } from 'react'; import PropTypes from 'prop-types'; import { injectI18n } from '@kbn/i18n/react'; -import { - EuiSearchBar, - EuiFormErrorText, -} from '@elastic/eui'; +import { EuiSearchBar, EuiFormErrorText } from '@elastic/eui'; import { getCategoryName } from '../../lib'; class SearchUI extends PureComponent { - static propTypes = { categories: PropTypes.array.isRequired, query: PropTypes.object.isRequired, @@ -50,7 +46,7 @@ class SearchUI extends PureComponent { state = { isSearchTextValid: true, parseErrorMessage: null, - } + }; onChange = ({ query, error }) => { if (error) { @@ -66,7 +62,7 @@ class SearchUI extends PureComponent { parseErrorMessage: null, }); this.props.onQueryChange({ query }); - } + }; render() { const { query, intl } = this.props; @@ -78,7 +74,6 @@ class SearchUI extends PureComponent { id: 'kbn.management.settings.searchBarAriaLabel', defaultMessage: 'Search advanced settings', }), // hack until EuiSearchBar is fixed - }; const filters = [ @@ -91,7 +86,7 @@ class SearchUI extends PureComponent { }), multiSelect: 'or', options: this.categories, - } + }, ]; let queryParseError; @@ -101,20 +96,13 @@ class SearchUI extends PureComponent { defaultMessage: 'Unable to parse query', }); queryParseError = ( - - {`${parseErrorMsg}. ${this.state.parseErrorMessage}`} - + {`${parseErrorMsg}. ${this.state.parseErrorMessage}`} ); } return ( - + {queryParseError} ); From cf39fe7c4951e06bd93e2e2e5eeca31647354d94 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Wed, 18 Sep 2019 11:57:28 +0900 Subject: [PATCH 02/10] Removed injectI18n. Fixes. Fixes. --- .../components/header/__jest__/header.test.js | 20 +- .../components/header/header.js | 11 +- .../step_index_pattern.test.js.snap | 2 +- .../__jest__/step_index_pattern.test.js | 35 ++-- .../components/header/__jest__/header.test.js | 12 +- .../components/header/header.js | 18 +- .../step_index_pattern/step_index_pattern.js | 17 +- .../__jest__/step_time_field.test.js | 66 +++--- .../__jest__/advanced_options.test.js | 12 +- .../advanced_options/advanced_options.js | 18 +- .../time_field/__jest__/time_field.test.js | 20 +- .../components/time_field/time_field.js | 18 +- .../step_time_field/step_time_field.js | 6 +- .../components/table/__jest__/table.test.js | 18 +- .../components/table/table.js | 109 +++++----- .../__jest__/scripted_field_table.test.js | 14 +- .../components/table/__jest__/table.test.js | 29 ++- .../components/table/table.js | 74 +++---- .../source_filters_table.test.js.snap | 14 +- .../add_filter/__jest__/add_filter.test.js | 16 +- .../components/add_filter/add_filter.js | 11 +- .../components/header/header.js | 11 +- .../components/table/__jest__/table.test.js | 82 +++----- .../components/table/table.js | 63 +++--- .../__snapshots__/objects_table.test.js.snap | 6 +- .../__jest__/objects_table.test.js | 140 +++++-------- .../components/flyout/__jest__/flyout.test.js | 81 ++++---- .../objects_table/components/flyout/flyout.js | 194 ++++++++---------- .../__jest__/relationships.test.js | 51 ++--- .../components/relationships/relationships.js | 112 +++++----- .../components/table/__jest__/table.test.js | 80 ++++---- .../objects_table/components/table/table.js | 81 ++++---- .../components/objects_table/objects_table.js | 59 +++--- .../advanced_settings.test.js.snap | 6 +- .../settings/components/field/field.js | 121 +++++------ .../settings/components/field/field.test.js | 12 +- .../sections/settings/components/form/form.js | 6 +- .../settings/components/form/form.test.js | 30 +-- .../page_footer/page_footer.test.js | 4 +- .../page_subtitle/page_subtitle.test.js | 4 +- .../components/page_title/page_title.test.js | 4 +- .../settings/components/search/search.js | 22 +- .../settings/components/search/search.test.js | 31 +-- 43 files changed, 765 insertions(+), 975 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/__jest__/header.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/__jest__/header.test.js index a6766eb865605..c7cb3d4631b94 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/__jest__/header.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/__jest__/header.test.js @@ -19,34 +19,28 @@ import React from 'react'; import { Header } from '../header'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; describe('Header', () => { it('should render normally', () => { - const component = shallowWithIntl( - {}} - /> + const component = shallowWithI18nProvider( +
{}} /> ); expect(component).toMatchSnapshot(); }); it('should render without including system indices', () => { - const component = shallowWithIntl( - {}} - /> + const component = shallowWithI18nProvider( +
{}} /> ); expect(component).toMatchSnapshot(); }); it('should render a different name, prompt, and beta tag if provided', () => { - const component = shallowWithIntl( - {}} prompt={
Test prompt
} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js index 6b0552f736667..3352996368669 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/header/header.js @@ -30,16 +30,16 @@ import { EuiSwitch, } from '@elastic/eui'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; -const HeaderUi = ({ +export const Header = ({ prompt, indexPatternName, showSystemIndices, isIncludingSystemIndices, onChangeIncludingSystemIndices, isBeta, - intl, }) => (
@@ -55,8 +55,7 @@ const HeaderUi = ({ {' '} @@ -102,5 +101,3 @@ const HeaderUi = ({
); - -export const Header = injectI18n(HeaderUi); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/__snapshots__/step_index_pattern.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/__snapshots__/step_index_pattern.test.js.snap index c83d0939dd231..b68ba4720b935 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/__snapshots__/step_index_pattern.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/__snapshots__/step_index_pattern.test.js.snap @@ -2,7 +2,7 @@ exports[`StepIndexPattern renders errors when input is invalid 1`] = ` Object { - "component": , |" data-test-subj="createIndexPatternStep1Header" errors={ diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js index 6c7deefcc0a45..1797fc203ccd8 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js @@ -18,18 +18,19 @@ */ import React from 'react'; -import { StepIndexPatternComponent } from '../step_index_pattern'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { StepIndexPattern } from '../step_index_pattern'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { Header } from '../components/header'; jest.mock('../../../lib/ensure_minimum_time', () => ({ - ensureMinimumTime: async (promises) => Array.isArray(promises) ? await Promise.all(promises) : await promises + ensureMinimumTime: async promises => + Array.isArray(promises) ? await Promise.all(promises) : await promises, })); const mockIndexPatternCreationType = { getIndexPatternType: () => 'default', getIndexPatternName: () => 'name', checkIndicesForErrors: () => false, - getShowSystemIndices: () => false + getShowSystemIndices: () => false, }; // If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype // at Function.defineProperties`. @@ -41,33 +42,29 @@ jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ get: () => '', }), - addBasePath: () => { }, + addBasePath: () => {}, })); jest.mock('../../../lib/get_indices', () => ({ getIndices: (service, indexPatternCreationType, query) => { if (query.startsWith('e')) { - return [ - { name: 'es' }, - ]; + return [{ name: 'es' }]; } - return [ - { name: 'kibana' }, - ]; + return [{ name: 'kibana' }]; }, })); const allIndices = [{ name: 'kibana' }, { name: 'es' }]; const esService = {}; const savedObjectsClient = { - find: () => ({ savedObjects: [] }) + find: () => ({ savedObjects: [] }), }; -const goToNextStep = () => { }; +const goToNextStep = () => {}; const createComponent = props => { - return shallowWithIntl( - { // Ensure the state changes are reflected await component.update(); - expect(component.find('[data-test-subj="createIndexPatternStep1IndicesList"]')).toMatchSnapshot(); + expect( + component.find('[data-test-subj="createIndexPatternStep1IndicesList"]') + ).toMatchSnapshot(); }); it('renders errors when input is invalid', async () => { @@ -121,7 +120,9 @@ describe('StepIndexPattern', () => { // Ensure the state changes are reflected component.update(); - expect(component.find('[data-test-subj="createIndexPatternStep1IndicesList"]')).toMatchSnapshot(); + expect( + component.find('[data-test-subj="createIndexPatternStep1IndicesList"]') + ).toMatchSnapshot(); }); it('appends a wildcard automatically to queries', async () => { diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/__jest__/header.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/__jest__/header.test.js index 975b627c9a7d1..534c46ab73ded 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/__jest__/header.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/components/header/__jest__/header.test.js @@ -18,13 +18,13 @@ */ import React from 'react'; -import { HeaderComponent } from '../header'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { Header } from '../header'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; describe('Header', () => { it('should render normally', () => { - const component = shallowWithIntl( - { }); it('should mark the input as invalid', () => { - const component = shallowWithIntl( - (
@@ -86,10 +86,12 @@ export const HeaderComponent = ({ >
); - -export const Header = injectI18n(HeaderComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index e110e1b7755a8..617262c13b034 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -35,12 +35,13 @@ import { Header } from './components/header'; import { EuiPanel, EuiSpacer, EuiCallOut } from '@elastic/eui'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import chrome from 'ui/chrome'; const uiSettings = chrome.getUiSettingsClient(); -export class StepIndexPatternComponent extends Component { +export class StepIndexPattern extends Component { static propTypes = { allIndices: PropTypes.array.isRequired, isIncludingSystemIndices: PropTypes.bool.isRequired, @@ -224,7 +225,7 @@ export class StepIndexPatternComponent extends Component { } renderHeader({ exactMatchedIndices: indices }) { - const { goToNextStep, indexPatternCreationType, intl } = this.props; + const { goToNextStep, indexPatternCreationType } = this.props; const { query, showingIndexPatternQueryErrors, @@ -243,13 +244,13 @@ export class StepIndexPatternComponent extends Component { // This is an error scenario but do not report an error containsErrors = true; } else if (containsIllegalCharacters(query, ILLEGAL_CHARACTERS)) { - const errorMessage = intl.formatMessage( + const errorMessage = i18n.translate( + 'kbn.management.createIndexPattern.step.invalidCharactersErrorMessage', { - id: 'kbn.management.createIndexPattern.step.invalidCharactersErrorMessage', defaultMessage: 'A {indexPatternName} cannot contain spaces or the characters: {characterList}', - }, - { characterList, indexPatternName } + values: { characterList, indexPatternName }, + } ); errors.push(errorMessage); @@ -301,5 +302,3 @@ export class StepIndexPatternComponent extends Component { ); } } - -export const StepIndexPattern = injectI18n(StepIndexPatternComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/__jest__/step_time_field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/__jest__/step_time_field.test.js index ab6eef146c1b1..5677d2293a725 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/__jest__/step_time_field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/__jest__/step_time_field.test.js @@ -18,9 +18,9 @@ */ import React from 'react'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; -import { StepTimeFieldComponent } from '../step_time_field'; +import { StepTimeField } from '../step_time_field'; jest.mock('../components/header', () => ({ Header: 'Header' })); jest.mock('../components/time_field', () => ({ TimeField: 'TimeField' })); @@ -30,27 +30,27 @@ jest.mock('../../../lib/extract_time_fields', () => ({ extractTimeFields: fields => fields, })); jest.mock('ui/chrome', () => ({ - addBasePath: () => { }, + addBasePath: () => {}, })); const mockIndexPatternCreationType = { getIndexPatternType: () => 'default', getIndexPatternName: () => 'name', - getFetchForWildcardOptions: () => {} + getFetchForWildcardOptions: () => {}, }; const noop = () => {}; const indexPatternsService = { make: async () => ({ fieldsFetcher: { - fetch: noop - } - }) + fetch: noop, + }, + }), }; describe('StepTimeField', () => { it('should render normally', () => { - const component = shallowWithIntl( - { }); it('should render timeFields', () => { - const component = shallowWithIntl( - { timeFields: [ { display: '@timestamp', fieldName: '@timestamp' }, { display: 'name', fieldName: 'name' }, - ] + ], }); expect(component).toMatchSnapshot(); }); it('should render a selected timeField', () => { - const component = shallowWithIntl( - { }); it('should ensure disabled time field options work properly', () => { - const component = shallowWithIntl( - { }); it('should disable the action button if an invalid time field is selected', () => { - const component = shallowWithIntl( - { }); it('should enable the action button if the user decides to not select a time field', () => { - const component = shallowWithIntl( - { }); it('should render advanced options', () => { - const component = shallowWithIntl( - { }); it('should render advanced options with an index pattern id', () => { - const component = shallowWithIntl( - { }); it('should render a loading state when creating the index pattern', () => { - const component = shallowWithIntl( - { }); it('should render any error message', () => { - const component = shallowWithIntl( - { }); it('should render "Custom index pattern ID already exists" when error is "Conflict"', () => { - const component = shallowWithIntl( - { const createIndexPattern = async () => { throw new Error('foobar'); }; - const component = shallowWithIntl( - { component.update(); expect(component.instance().state).toMatchObject({ - error: 'foobar' + error: 'foobar', }); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/__jest__/advanced_options.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/__jest__/advanced_options.test.js index 11c79092f5c25..6dde1a597fc2d 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/__jest__/advanced_options.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/__jest__/advanced_options.test.js @@ -18,13 +18,13 @@ */ import React from 'react'; -import { AdvancedOptionsComponent } from '../advanced_options'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { AdvancedOptions } from '../advanced_options'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; describe('AdvancedOptions', () => { it('should render normally', () => { - const component = shallowWithIntl( - {}} @@ -36,8 +36,8 @@ describe('AdvancedOptions', () => { }); it('should hide if not showing', () => { - const component = shallowWithIntl( - {}} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js index 7e7326f47073e..9082df6affa09 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/advanced_options/advanced_options.js @@ -21,14 +21,14 @@ import React from 'react'; import { EuiForm, EuiFormRow, EuiFieldText, EuiButtonEmpty, EuiSpacer } from '@elastic/eui'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; -export const AdvancedOptionsComponent = ({ +export const AdvancedOptions = ({ isVisible, indexPatternId, toggleAdvancedOptions, onChangeIndexPatternId, - intl, }) => (
) : null}
); - -export const AdvancedOptions = injectI18n(AdvancedOptionsComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/__jest__/time_field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/__jest__/time_field.test.js index bda1198b194fd..8994ffd79b6e4 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/__jest__/time_field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/__jest__/time_field.test.js @@ -18,13 +18,13 @@ */ import React from 'react'; -import { TimeFieldComponent } from '../time_field'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { TimeField } from '../time_field'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; describe('TimeField', () => { it('should render normally', () => { - const component = shallowWithIntl( - {}} timeFieldOptions={[{ text: '@timestamp', value: '@timestamp' }]} @@ -38,8 +38,8 @@ describe('TimeField', () => { }); it('should render something if hiding time field', () => { - const component = shallowWithIntl( - {}} timeFieldOptions={[{ text: '@timestamp', value: '@timestamp' }]} @@ -53,8 +53,8 @@ describe('TimeField', () => { }); it('should render a selected time field', () => { - const component = shallowWithIntl( - {}} timeFieldOptions={[{ text: '@timestamp', value: '@timestamp' }]} @@ -68,8 +68,8 @@ describe('TimeField', () => { }); it('should render a loading state', () => { - const component = shallowWithIntl( - {}} timeFieldOptions={[{ text: '@timestamp', value: '@timestamp' }]} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js index b1304a2462691..595552568b461 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/components/time_field/time_field.js @@ -32,16 +32,16 @@ import { EuiLoadingSpinner, } from '@elastic/eui'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; -export const TimeFieldComponent = ({ +export const TimeField = ({ isVisible, fetchTimeFields, timeFieldOptions, isLoading, selectedTimeField, onTimeFieldChanged, - intl, }) => ( {isVisible ? ( @@ -93,10 +93,12 @@ export const TimeFieldComponent = ({ data-test-subj="createIndexPatternTimeFieldSelect" options={[ { - text: intl.formatMessage({ - id: 'kbn.management.createIndexPattern.stepTime.field.loadingDropDown', - defaultMessage: 'Loading…', - }), + text: i18n.translate( + 'kbn.management.createIndexPattern.stepTime.field.loadingDropDown', + { + defaultMessage: 'Loading…', + } + ), value: '', }, ]} @@ -126,5 +128,3 @@ export const TimeFieldComponent = ({ )} ); - -export const TimeField = injectI18n(TimeFieldComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js index c45d80edfaff1..5cb93a36cdd18 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js @@ -36,9 +36,9 @@ import { EuiLoadingSpinner, } from '@elastic/eui'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; -export class StepTimeFieldComponent extends Component { +export class StepTimeField extends Component { static propTypes = { indexPattern: PropTypes.string.isRequired, indexPatternsService: PropTypes.object.isRequired, @@ -240,5 +240,3 @@ export class StepTimeFieldComponent extends Component { ); } } - -export const StepTimeField = injectI18n(StepTimeFieldComponent); 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/__jest__/table.test.js index c538bb5f24085..01e1030d5e517 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/__jest__/table.test.js @@ -19,7 +19,7 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { TableComponent } from '../table'; @@ -35,7 +35,7 @@ const items = [ describe('Table', () => { it('should render normally', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render normal field name', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render timestamp field name', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render the boolean template (true)', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render the boolean template (false)', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render normal type', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render conflicting type', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { it('should allow edits', () => { const editField = jest.fn(); - const component = shallowWithIntl( + const component = shallowWithI18nProvider( @@ -79,16 +78,16 @@ export class TableComponent extends PureComponent { } renderFieldType(type, isConflict) { - const { intl } = this.props; - const label = intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.multiTypeAria', + const label = i18n.translate('kbn.management.editIndexPattern.fields.table.multiTypeAria', { defaultMessage: 'Multiple type field', }); - const content = intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.multiTypeTooltip', - defaultMessage: - 'The type of this field changes across indices. It is unavailable for many analysis functions.', - }); + 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 ( @@ -106,7 +105,7 @@ export class TableComponent extends PureComponent { } render() { - const { items, editField, intl } = this.props; + const { items, editField } = this.props; const pagination = { initialPageSize: 10, @@ -116,8 +115,7 @@ export class TableComponent extends PureComponent { const columns = [ { field: 'displayName', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.nameHeader', + name: i18n.translate('kbn.management.editIndexPattern.fields.table.nameHeader', { defaultMessage: 'Name', }), dataType: 'string', @@ -130,8 +128,7 @@ export class TableComponent extends PureComponent { }, { field: 'type', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.typeHeader', + name: i18n.translate('kbn.management.editIndexPattern.fields.table.typeHeader', { defaultMessage: 'Type', }), dataType: 'string', @@ -143,8 +140,7 @@ export class TableComponent extends PureComponent { }, { field: 'format', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.formatHeader', + name: i18n.translate('kbn.management.editIndexPattern.fields.table.formatHeader', { defaultMessage: 'Format', }), dataType: 'string', @@ -152,63 +148,57 @@ export class TableComponent extends PureComponent { }, { field: 'searchable', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.searchableHeader', + name: i18n.translate('kbn.management.editIndexPattern.fields.table.searchableHeader', { defaultMessage: 'Searchable', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.searchableDescription', - defaultMessage: 'These fields can be used in the filter bar', - }), + 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, - intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.isSearchableAria', + i18n.translate('kbn.management.editIndexPattern.fields.table.isSearchableAria', { defaultMessage: 'Is searchable', }) ), }, { field: 'aggregatable', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.aggregatableLabel', + name: i18n.translate('kbn.management.editIndexPattern.fields.table.aggregatableLabel', { defaultMessage: 'Aggregatable', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.aggregatableDescription', - defaultMessage: 'These fields can be used in visualization aggregations', - }), + 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, - intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.isAggregatableAria', + i18n.translate('kbn.management.editIndexPattern.fields.table.isAggregatableAria', { defaultMessage: 'Is aggregatable', }) ), }, { field: 'excluded', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.excludedLabel', + name: i18n.translate('kbn.management.editIndexPattern.fields.table.excludedLabel', { defaultMessage: 'Excluded', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.excludedDescription', - defaultMessage: 'Fields that are excluded from _source when it is fetched', - }), + 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, - intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.isExcludedAria', + i18n.translate('kbn.management.editIndexPattern.fields.table.isExcludedAria', { defaultMessage: 'Is excluded', }) ), @@ -217,14 +207,13 @@ export class TableComponent extends PureComponent { name: '', actions: [ { - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.editLabel', - defaultMessage: 'Edit', - }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.fields.table.editDescription', + 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', @@ -239,5 +228,3 @@ export class TableComponent extends PureComponent { ); } } - -export const Table = injectI18n(TableComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/__jest__/scripted_field_table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/__jest__/scripted_field_table.test.js index e0da7e287d082..df9c61b32da94 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/__jest__/scripted_field_table.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/__jest__/scripted_field_table.test.js @@ -18,7 +18,7 @@ */ import React from 'react'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { ScriptedFieldsTable } from '../scripted_fields_table'; @@ -70,7 +70,7 @@ const indexPattern = { describe('ScriptedFieldsTable', () => { it('should render normally', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should filter based on the query bar', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should filter based on the lang filter', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( ([ @@ -130,7 +130,7 @@ describe('ScriptedFieldsTable', () => { }); it('should hide the table if there are no scripted fields', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( ([]) @@ -148,7 +148,7 @@ describe('ScriptedFieldsTable', () => { }); it('should show a delete modal', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { it('should delete a field', async () => { const removeScriptedField = jest.fn(); - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { it('should render normally', async () => { - const component = shallowWithIntl( - {}} @@ -51,8 +51,8 @@ describe('Table', () => { }); it('should render the format', async () => { - const component = shallowWithIntl( - {}} @@ -68,8 +68,8 @@ describe('Table', () => { it('should allow edits', () => { const editField = jest.fn(); - const component = shallowWithIntl( - { it('should allow deletes', () => { const deleteField = jest.fn(); - const component = shallowWithIntl( - {}} @@ -100,5 +100,4 @@ describe('Table', () => { component.prop('columns')[4].actions[1].onClick(); expect(deleteField).toBeCalled(); }); - }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js index be4319b36575c..5e05dd95827c7 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/scripted_fields_table/components/table/table.js @@ -22,9 +22,9 @@ import PropTypes from 'prop-types'; import { EuiInMemoryTable } from '@elastic/eui'; -import { injectI18n } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; -export class TableComponent extends PureComponent { +export class Table extends PureComponent { static propTypes = { indexPattern: PropTypes.object.isRequired, items: PropTypes.array.isRequired, @@ -44,60 +44,56 @@ export class TableComponent extends PureComponent { }; render() { - const { items, editField, deleteField, intl } = this.props; + const { items, editField, deleteField } = this.props; const columns = [ { field: 'displayName', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.nameHeader', + name: i18n.translate('kbn.management.editIndexPattern.scripted.table.nameHeader', { defaultMessage: 'Name', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.nameDescription', - defaultMessage: 'Name of the field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.scripted.table.nameDescription', + { defaultMessage: 'Name of the field' } + ), dataType: 'string', sortable: true, width: '38%', }, { field: 'lang', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.langHeader', + name: i18n.translate('kbn.management.editIndexPattern.scripted.table.langHeader', { defaultMessage: 'Lang', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.langDescription', - defaultMessage: 'Language used for the field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.scripted.table.langDescription', + { defaultMessage: 'Language used for the field' } + ), dataType: 'string', sortable: true, 'data-test-subj': 'scriptedFieldLang', }, { field: 'script', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.scriptHeader', + name: i18n.translate('kbn.management.editIndexPattern.scripted.table.scriptHeader', { defaultMessage: 'Script', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.scriptDescription', - defaultMessage: 'Script for the field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.scripted.table.scriptDescription', + { defaultMessage: 'Script for the field' } + ), dataType: 'string', sortable: true, }, { field: 'name', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.formatHeader', + name: i18n.translate('kbn.management.editIndexPattern.scripted.table.formatHeader', { defaultMessage: 'Format', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.formatDescription', - defaultMessage: 'Format used for the field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.scripted.table.formatDescription', + { defaultMessage: 'Format used for the field' } + ), render: this.renderFormatCell, sortable: false, }, @@ -105,26 +101,24 @@ export class TableComponent extends PureComponent { name: '', actions: [ { - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.editHeader', + name: i18n.translate('kbn.management.editIndexPattern.scripted.table.editHeader', { defaultMessage: 'Edit', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.editDescription', - defaultMessage: 'Edit this field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.scripted.table.editDescription', + { defaultMessage: 'Edit this field' } + ), icon: 'pencil', onClick: editField, }, { - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.deleteHeader', + name: i18n.translate('kbn.management.editIndexPattern.scripted.table.deleteHeader', { defaultMessage: 'Delete', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.scripted.table.deleteDescription', - defaultMessage: 'Delete this field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.scripted.table.deleteDescription', + { defaultMessage: 'Delete this field' } + ), icon: 'trash', color: 'danger', onClick: deleteField, @@ -144,5 +138,3 @@ export class TableComponent extends PureComponent { ); } } - -export const Table = injectI18n(TableComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/__jest__/__snapshots__/source_filters_table.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/__jest__/__snapshots__/source_filters_table.test.js.snap index 03fe9f058013f..52fccb8607a83 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/__jest__/__snapshots__/source_filters_table.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/__jest__/__snapshots__/source_filters_table.test.js.snap @@ -3,7 +3,7 @@ exports[`SourceFiltersTable should add a filter 1`] = `
-
-
-
-
-
-
- { it('should render normally', async () => { - const component = shallowWithIntl( - {}}/> - ); + const component = shallowWithI18nProvider( {}} />); expect(component).toMatchSnapshot(); }); it('should allow adding a filter', async () => { const onAddFilter = jest.fn(); - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Set a value in the input field component.setState({ filter: 'tim*' }); @@ -48,9 +44,7 @@ describe('AddFilter', () => { }); it('should ignore strings with just spaces', async () => { - const component = shallowWithIntl( - {}}/> - ); + const component = shallowWithI18nProvider( {}} />); // Set a value in the input field component.find('EuiFieldText').simulate('keypress', ' '); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js index 311ebb413250f..473526f9d43ad 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js @@ -22,9 +22,10 @@ import PropTypes from 'prop-types'; import { EuiFlexGroup, EuiFlexItem, EuiFieldText, EuiButton } from '@elastic/eui'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; -export class AddFilterComponent extends Component { +export class AddFilter extends Component { static propTypes = { onAddFilter: PropTypes.func.isRequired, }; @@ -43,9 +44,7 @@ export class AddFilterComponent extends Component { render() { const { filter } = this.state; - const { intl } = this.props; - const placeholder = intl.formatMessage({ - id: 'kbn.management.editIndexPattern.sourcePlaceholder', + const placeholder = i18n.translate('kbn.management.editIndexPattern.sourcePlaceholder', { defaultMessage: 'source filter, accepts wildcards (e.g., `user*` to filter fields starting with \'user\')', }); @@ -72,5 +71,3 @@ export class AddFilterComponent extends Component { ); } } - -export const AddFilter = injectI18n(AddFilterComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js index d3572416e8d26..8822ca6236250 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js @@ -19,11 +19,7 @@ import React from 'react'; -import { - EuiTitle, - EuiText, - EuiSpacer, -} from '@elastic/eui'; +import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -31,7 +27,10 @@ export const Header = () => (

- +

diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js index 7ce61668751b9..7fba1fcfe4876 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js @@ -19,9 +19,9 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; -import { TableComponent } from '../table'; +import { Table } from '../table'; import { keyCodes } from '@elastic/eui'; const indexPattern = {}; @@ -29,8 +29,8 @@ const items = [{ value: 'tim*' }]; describe('Table', () => { it('should render normally', async () => { - const component = shallowWithIntl( - {}} @@ -44,8 +44,8 @@ describe('Table', () => { }); it('should render filter matches', async () => { - const component = shallowWithIntl( - [{ name: 'time' }, { name: 'value' }], }} @@ -57,9 +57,7 @@ describe('Table', () => { /> ); - const matchesTableCell = shallow( - component.prop('columns')[1].render('tim', { clientId: 1 }) - ); + const matchesTableCell = shallow(component.prop('columns')[1].render('tim', { clientId: 1 })); expect(matchesTableCell).toMatchSnapshot(); }); @@ -69,8 +67,8 @@ describe('Table', () => { let component; beforeEach(() => { - component = shallowWithIntl( - {}} @@ -85,9 +83,7 @@ describe('Table', () => { // Start the editing process const editingComponent = shallow( // Wrap in a div because: https://github.com/airbnb/enzyme/issues/1213 -
- {component.prop('columns')[2].render({ clientId, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId, value: 'tim*' })}
); editingComponent .find('EuiButtonIcon') @@ -107,9 +103,7 @@ describe('Table', () => { // Start the editing process const editingComponent = shallow( // Fixes: Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {component.prop('columns')[2].render({ clientId, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId, value: 'tim*' })}
); editingComponent .find('EuiButtonIcon') @@ -122,16 +116,14 @@ describe('Table', () => { // Verify save button const saveTableCell = shallow( // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {component.prop('columns')[2].render({ clientId, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId, value: 'tim*' })}
); expect(saveTableCell).toMatchSnapshot(); }); it('should update the matches dynamically as input value is changed', () => { - const localComponent = shallowWithIntl( - [{ name: 'time' }, { name: 'value' }], }} @@ -148,11 +140,7 @@ describe('Table', () => { // Start the editing process const editingComponent = shallow( // Fixes: Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {localComponent - .prop('columns')[2] - .render({ clientId, value: 'tim*' })} -
+
{localComponent.prop('columns')[2].render({ clientId, value: 'tim*' })}
); editingComponent .find('EuiButtonIcon') @@ -168,9 +156,7 @@ describe('Table', () => { // Verify updated matches const matchesTableCell = shallow( // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {localComponent.prop('columns')[1].render('tim*', { clientId })} -
+
{localComponent.prop('columns')[1].render('tim*', { clientId })}
); expect(matchesTableCell).toMatchSnapshot(); }); @@ -185,9 +171,7 @@ describe('Table', () => { // Click the save button const editingComponent = shallow( // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {component.prop('columns')[2].render({ clientId, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId, value: 'tim*' })}
); editingComponent .find('EuiButtonIcon') @@ -208,8 +192,8 @@ describe('Table', () => { it('should allow deletes', () => { const deleteFilter = jest.fn(); - const component = shallowWithIntl( - { // Click the delete button const deleteCellComponent = shallow( // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {component.prop('columns')[2].render({ clientId: 1, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId: 1, value: 'tim*' })}
); deleteCellComponent .find('EuiButtonIcon') @@ -237,8 +219,8 @@ describe('Table', () => { const saveFilter = jest.fn(); const clientId = 1; - const component = shallowWithIntl( - {}} @@ -251,9 +233,7 @@ describe('Table', () => { // Start the editing process const editingComponent = shallow( // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {component.prop('columns')[2].render({ clientId, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId, value: 'tim*' })}
); editingComponent .find('EuiButtonIcon') @@ -269,9 +249,7 @@ describe('Table', () => { ); // Press the enter key - filterNameTableCell - .find('EuiFieldText') - .simulate('keydown', { keyCode: keyCodes.ENTER }); + filterNameTableCell.find('EuiFieldText').simulate('keydown', { keyCode: keyCodes.ENTER }); expect(saveFilter).toBeCalled(); // It should reset @@ -282,8 +260,8 @@ describe('Table', () => { const saveFilter = jest.fn(); const clientId = 1; - const component = shallowWithIntl( - {}} @@ -296,9 +274,7 @@ describe('Table', () => { // Start the editing process const editingComponent = shallow( // Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`. -
- {component.prop('columns')[2].render({ clientId, value: 'tim*' })} -
+
{component.prop('columns')[2].render({ clientId, value: 'tim*' })}
); editingComponent .find('EuiButtonIcon') @@ -314,9 +290,7 @@ describe('Table', () => { ); // Press the enter key - filterNameTableCell - .find('EuiFieldText') - .simulate('keydown', { keyCode: keyCodes.ESCAPE }); + filterNameTableCell.find('EuiFieldText').simulate('keydown', { keyCode: keyCodes.ESCAPE }); expect(saveFilter).not.toBeCalled(); // It should reset diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js index c08c787248a79..f16663e1cd41a 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.js @@ -28,9 +28,10 @@ import { RIGHT_ALIGNMENT, } from '@elastic/eui'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; -export class TableComponent extends Component { +export class Table extends Component { static propTypes = { indexPattern: PropTypes.object.isRequired, items: PropTypes.array.isRequired, @@ -67,19 +68,18 @@ export class TableComponent extends Component { }; getColumns() { - const { deleteFilter, fieldWildcardMatcher, indexPattern, saveFilter, intl } = this.props; + const { deleteFilter, fieldWildcardMatcher, indexPattern, saveFilter } = this.props; return [ { field: 'value', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.filterHeader', + name: i18n.translate('kbn.management.editIndexPattern.source.table.filterHeader', { defaultMessage: 'Filter', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.filterDescription', - defaultMessage: 'Filter name', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.source.table.filterDescription', + { defaultMessage: 'Filter name' } + ), dataType: 'string', sortable: true, render: (value, filter) => { @@ -99,14 +99,13 @@ export class TableComponent extends Component { }, { field: 'value', - name: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.matchesHeader', + name: i18n.translate('kbn.management.editIndexPattern.source.table.matchesHeader', { defaultMessage: 'Matches', }), - description: intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.matchesDescription', - defaultMessage: 'Language used for the field', - }), + description: i18n.translate( + 'kbn.management.editIndexPattern.source.table.matchesDescription', + { defaultMessage: 'Language used for the field' } + ), dataType: 'string', sortable: true, render: (value, filter) => { @@ -150,10 +149,10 @@ export class TableComponent extends Component { this.stopEditingFilter(); }} iconType="checkInCircleFilled" - aria-label={intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.saveAria', - defaultMessage: 'Save', - })} + aria-label={i18n.translate( + 'kbn.management.editIndexPattern.source.table.saveAria', + { defaultMessage: 'Save' } + )} /> ); @@ -177,19 +176,19 @@ export class TableComponent extends Component { color="danger" onClick={() => deleteFilter(filter)} iconType="trash" - aria-label={intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.deleteAria', - defaultMessage: 'Delete', - })} + aria-label={i18n.translate( + 'kbn.management.editIndexPattern.source.table.deleteAria', + { defaultMessage: 'Delete' } + )} /> this.startEditingFilter(filter.clientId, filter.value)} iconType="pencil" - aria-label={intl.formatMessage({ - id: 'kbn.management.editIndexPattern.source.table.editAria', - defaultMessage: 'Edit', - })} + aria-label={i18n.translate( + 'kbn.management.editIndexPattern.source.table.editAria', + { defaultMessage: 'Edit' } + )} /> ); @@ -217,5 +216,3 @@ export class TableComponent extends Component { ); } } - -export const Table = injectI18n(TableComponent); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/__snapshots__/objects_table.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/__snapshots__/objects_table.test.js.snap index 4f54203a2c661..fc58ea51688ed 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/__snapshots__/objects_table.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/__snapshots__/objects_table.test.js.snap @@ -200,7 +200,7 @@ exports[`ObjectsTable export should allow the user to choose when exporting all `; exports[`ObjectsTable import should show the flyout 1`] = ` - - ({ getSavedObjectCounts: jest.fn().mockImplementation(() => { return { 'index-pattern': 0, - 'visualization': 0, - 'dashboard': 0, - 'search': 0, + visualization: 0, + dashboard: 0, + search: 0, }; - }) + }), })); jest.mock('@elastic/filesaver', () => ({ @@ -74,34 +74,34 @@ const allSavedObjects = [ id: '1', type: 'index-pattern', attributes: { - title: `MyIndexPattern*` - } + title: `MyIndexPattern*`, + }, }, { id: '2', type: 'search', attributes: { - title: `MySearch` - } + title: `MySearch`, + }, }, { id: '3', type: 'dashboard', attributes: { - title: `MyDashboard` - } + title: `MyDashboard`, + }, }, { id: '4', type: 'visualization', attributes: { - title: `MyViz` - } + title: `MyViz`, + }, }, ]; const $http = () => {}; -$http.post = jest.fn().mockImplementation(() => ([])); +$http.post = jest.fn().mockImplementation(() => []); const defaultProps = { goInspectObject: () => {}, confirmModalPromise: jest.fn(), @@ -122,7 +122,7 @@ const defaultProps = { read: true, edit: false, delete: false, - } + }, }, canDelete: true, }; @@ -209,11 +209,8 @@ describe('ObjectsTable', () => { }); it('should render normally', async () => { - const component = shallowWithIntl( - + const component = shallowWithI18nProvider( + ); // Ensure all promises resolve @@ -228,11 +225,8 @@ describe('ObjectsTable', () => { findObjects.mockImplementation(() => { throw new Error('Simulated find error'); }); - const component = shallowWithIntl( - + const component = shallowWithI18nProvider( + ); // Ensure all promises resolve @@ -247,7 +241,7 @@ describe('ObjectsTable', () => { it('should export selected objects', async () => { const mockSelectedSavedObjects = [ { id: '1', type: 'index-pattern' }, - { id: '3', type: 'dashboard' } + { id: '3', type: 'dashboard' }, ]; const mockSavedObjects = mockSelectedSavedObjects.map(obj => ({ @@ -260,16 +254,13 @@ describe('ObjectsTable', () => { ...defaultProps.savedObjectsClient, bulkGet: jest.fn().mockImplementation(() => ({ savedObjects: mockSavedObjects, - })) + })), }; const { fetchExportObjects } = require('../../../lib/fetch_export_objects'); - const component = shallowWithIntl( - + const component = shallowWithI18nProvider( + ); // Ensure all promises resolve @@ -283,15 +274,13 @@ describe('ObjectsTable', () => { await component.instance().onExport(true); expect(fetchExportObjects).toHaveBeenCalledWith(mockSelectedSavedObjects, true); - expect(addSuccessMock).toHaveBeenCalledWith({ title: 'Your file is downloading in the background' }); + expect(addSuccessMock).toHaveBeenCalledWith({ + title: 'Your file is downloading in the background', + }); }); it('should allow the user to choose when exporting all', async () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -307,11 +296,7 @@ describe('ObjectsTable', () => { it('should export all', async () => { const { fetchExportByType } = require('../../../lib/fetch_export_by_type'); const { saveAs } = require('@elastic/filesaver'); - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -326,17 +311,15 @@ describe('ObjectsTable', () => { expect(fetchExportByType).toHaveBeenCalledWith(POSSIBLE_TYPES, true); expect(saveAs).toHaveBeenCalledWith(blob, 'export.ndjson'); - expect(addSuccessMock).toHaveBeenCalledWith({ title: 'Your file is downloading in the background' }); + expect(addSuccessMock).toHaveBeenCalledWith({ + title: 'Your file is downloading in the background', + }); }); }); describe('import', () => { it('should show the flyout', async () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -350,11 +333,7 @@ describe('ObjectsTable', () => { }); it('should hide the flyout', async () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -372,11 +351,7 @@ describe('ObjectsTable', () => { it('should fetch relationships', async () => { const { getRelationships } = require('../../../lib/get_relationships'); - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -385,15 +360,17 @@ describe('ObjectsTable', () => { await component.instance().getRelationships('search', '1'); const savedObjectTypes = ['index-pattern', 'visualization', 'dashboard', 'search']; - expect(getRelationships).toHaveBeenCalledWith('search', '1', savedObjectTypes, defaultProps.$http, defaultProps.basePath); + expect(getRelationships).toHaveBeenCalledWith( + 'search', + '1', + savedObjectTypes, + defaultProps.$http, + defaultProps.basePath + ); }); it('should show the flyout', async () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -432,11 +409,7 @@ describe('ObjectsTable', () => { }); it('should hide the flyout', async () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -455,15 +428,11 @@ describe('ObjectsTable', () => { describe('delete', () => { it('should show a confirm modal', async () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); const mockSelectedSavedObjects = [ { id: '1', type: 'index-pattern', title: 'Title 1' }, - { id: '3', type: 'dashboard', title: 'Title 2' } + { id: '3', type: 'dashboard', title: 'Title 2' }, ]; // Ensure all promises resolve @@ -482,7 +451,7 @@ describe('ObjectsTable', () => { it('should delete selected objects', async () => { const mockSelectedSavedObjects = [ { id: '1', type: 'index-pattern' }, - { id: '3', type: 'dashboard' } + { id: '3', type: 'dashboard' }, ]; const mockSavedObjects = mockSelectedSavedObjects.map(obj => ({ @@ -499,11 +468,8 @@ describe('ObjectsTable', () => { delete: jest.fn(), }; - const component = shallowWithIntl( - + const component = shallowWithI18nProvider( + ); // Ensure all promises resolve @@ -518,8 +484,14 @@ describe('ObjectsTable', () => { expect(defaultProps.indexPatterns.clearCache).toHaveBeenCalled(); expect(mockSavedObjectsClient.bulkGet).toHaveBeenCalledWith(mockSelectedSavedObjects); - expect(mockSavedObjectsClient.delete).toHaveBeenCalledWith(mockSavedObjects[0].type, mockSavedObjects[0].id); - expect(mockSavedObjectsClient.delete).toHaveBeenCalledWith(mockSavedObjects[1].type, mockSavedObjects[1].id); + expect(mockSavedObjectsClient.delete).toHaveBeenCalledWith( + mockSavedObjects[0].type, + mockSavedObjects[0].id + ); + expect(mockSavedObjectsClient.delete).toHaveBeenCalledWith( + mockSavedObjects[1].type, + mockSavedObjects[1].id + ); expect(component.state('selectedSavedObjects').length).toBe(0); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/__jest__/flyout.test.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/__jest__/flyout.test.js index 2e80dcd753bc2..e465149b301dc 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/__jest__/flyout.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/__jest__/flyout.test.js @@ -18,7 +18,7 @@ */ import React from 'react'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { Flyout } from '../flyout'; @@ -73,7 +73,7 @@ const legacyMockFile = { describe('Flyout', () => { it('should render import step', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -84,7 +84,7 @@ describe('Flyout', () => { }); it('should toggle the overwrite all control', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -97,7 +97,7 @@ describe('Flyout', () => { }); it('should allow picking a file', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -110,7 +110,7 @@ describe('Flyout', () => { }); it('should allow removing a file', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await Promise.resolve(); @@ -126,7 +126,7 @@ describe('Flyout', () => { it('should handle invalid files', async () => { const { importLegacyFile } = require('../../../../../lib/import_legacy_file'); - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -171,7 +171,7 @@ describe('Flyout', () => { type: 'index-pattern', }, ], - } + }, }, ], })); @@ -183,7 +183,7 @@ describe('Flyout', () => { }); it('should figure out unmatchedReferences', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -218,7 +218,7 @@ describe('Flyout', () => { }); it('should allow conflict resolution', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -233,9 +233,7 @@ describe('Flyout', () => { expect(component).toMatchSnapshot(); // Ensure we can change the resolution - component - .instance() - .onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); + component.instance().onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); expect(component.state('unmatchedReferences')[0].newIndexPatternId).toBe('2'); // Let's resolve now @@ -248,7 +246,7 @@ describe('Flyout', () => { }); it('should handle errors', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -277,9 +275,7 @@ describe('Flyout', () => { await component.instance().import(); component.update(); // Set a resolution - component - .instance() - .onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); + component.instance().onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); await component .find('EuiButton[data-test-subj="importSavedObjectsConfirmBtn"]') .simulate('click'); @@ -306,7 +302,7 @@ describe('Flyout', () => { const { resolveImportErrors } = require('../../../../../lib/resolve_import_errors'); it('should display unsupported type errors properly', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await Promise.resolve(); @@ -323,7 +319,7 @@ describe('Flyout', () => { title: 'My Title', error: { type: 'unsupported_type', - } + }, }, ], })); @@ -405,12 +401,18 @@ describe('Flyout', () => { }, obj: { searchSource: { - getOwnField: (field) => { - if(field === 'index') { return 'MyIndexPattern*';} - if(field === 'filter') { return [{ meta: { index: 'filterIndex' } }];} + getOwnField: field => { + if (field === 'index') { + return 'MyIndexPattern*'; + } + if (field === 'filter') { + return [{ meta: { index: 'filterIndex' } }]; + } }, }, - _serialize: () => { return { references: [{ id: 'MyIndexPattern*' }, { id: 'filterIndex' }] };}, + _serialize: () => { + return { references: [{ id: 'MyIndexPattern*' }, { id: 'filterIndex' }] }; + }, }, }, ]; @@ -430,7 +432,7 @@ describe('Flyout', () => { }); it('should figure out unmatchedReferences', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -443,11 +445,11 @@ describe('Flyout', () => { expect(importLegacyFile).toHaveBeenCalledWith(legacyMockFile); // Remove the last element from data since it should be filtered out expect(resolveSavedObjects).toHaveBeenCalledWith( - mockData.slice(0, 2).map((doc) => ({ ...doc, _migrationVersion: {} })), + mockData.slice(0, 2).map(doc => ({ ...doc, _migrationVersion: {} })), true, defaultProps.services, defaultProps.indexPatterns, - defaultProps.confirmModalPromise, + defaultProps.confirmModalPromise ); expect(component.state()).toMatchObject({ @@ -468,23 +470,24 @@ describe('Flyout', () => { type: 'index-pattern', }, ], - }, { - 'existingIndexPatternId': 'filterIndex', - 'list': [ + }, + { + existingIndexPatternId: 'filterIndex', + list: [ { - 'id': 'filterIndex', - 'title': 'MyIndexPattern*', - 'type': 'index-pattern', + id: 'filterIndex', + title: 'MyIndexPattern*', + type: 'index-pattern', }, ], - 'newIndexPatternId': undefined, - } + newIndexPatternId: undefined, + }, ], }); }); it('should allow conflict resolution', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -499,9 +502,7 @@ describe('Flyout', () => { expect(component).toMatchSnapshot(); // Ensure we can change the resolution - component - .instance() - .onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); + component.instance().onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); expect(component.state('unmatchedReferences')[0].newIndexPatternId).toBe('2'); // Let's resolve now @@ -528,7 +529,7 @@ describe('Flyout', () => { }); it('should handle errors', async () => { - const component = shallowWithIntl(); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); @@ -545,9 +546,7 @@ describe('Flyout', () => { await component.instance().legacyImport(); component.update(); // Set a resolution - component - .instance() - .onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); + component.instance().onIndexChanged('MyIndexPattern*', { target: { value: '2' } }); await component .find('EuiButton[data-test-subj="importSavedObjectsConfirmBtn"]') .simulate('click'); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js index 8a25e40ba58b9..8394c84d2da9c 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/flyout/flyout.js @@ -45,6 +45,9 @@ import { EuiOverlayMask, EUI_MODAL_CONFIRM_BUTTON, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; + import { importFile, importLegacyFile, @@ -60,9 +63,8 @@ import { saveObjects, } from '../../../../lib/resolve_saved_objects'; import { POSSIBLE_TYPES } from '../../objects_table'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; -class FlyoutUI extends Component { +export class Flyout extends Component { static propTypes = { close: PropTypes.func.isRequired, done: PropTypes.func.isRequired, @@ -124,7 +126,6 @@ class FlyoutUI extends Component { * Does the initial import of a file, resolveImportErrors then handles errors and retries */ import = async () => { - const { intl } = this.props; const { file, isOverwriteAllChecked } = this.state; this.setState({ status: 'loading', error: undefined }); @@ -135,8 +136,7 @@ class FlyoutUI extends Component { } catch (e) { this.setState({ status: 'error', - error: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.importFileErrorMessage', + error: i18n.translate('kbn.management.objects.objectsTable.flyout.importFileErrorMessage', { defaultMessage: 'The file could not be processed.', }), }); @@ -185,8 +185,6 @@ class FlyoutUI extends Component { * Function goes through the failedImports and tries to resolve the issues. */ resolveImportErrors = async () => { - const { intl } = this.props; - this.setState({ error: undefined, status: 'loading', @@ -202,16 +200,16 @@ class FlyoutUI extends Component { } catch (e) { this.setState({ status: 'error', - error: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.resolveImportErrorsFileErrorMessage', - defaultMessage: 'The file could not be processed.', - }), + error: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.resolveImportErrorsFileErrorMessage', + { defaultMessage: 'The file could not be processed.' } + ), }); } }; legacyImport = async () => { - const { services, indexPatterns, intl, confirmModalPromise } = this.props; + const { services, indexPatterns, confirmModalPromise } = this.props; const { file, isOverwriteAllChecked } = this.state; this.setState({ status: 'loading', error: undefined }); @@ -225,10 +223,10 @@ class FlyoutUI extends Component { } catch (e) { this.setState({ status: 'error', - error: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.importLegacyFileErrorMessage', - defaultMessage: 'The file could not be processed.', - }), + error: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.importLegacyFileErrorMessage', + { defaultMessage: 'The file could not be processed.' } + ), }); return; } @@ -236,10 +234,10 @@ class FlyoutUI extends Component { if (!Array.isArray(contents)) { this.setState({ status: 'error', - error: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.invalidFormatOfImportedFileErrorMessage', - defaultMessage: 'Saved objects file format is invalid and cannot be imported.', - }), + error: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.invalidFormatOfImportedFileErrorMessage', + { defaultMessage: 'Saved objects file format is invalid and cannot be imported.' } + ), }); return; } @@ -335,7 +333,7 @@ class FlyoutUI extends Component { failedImports, } = this.state; - const { services, indexPatterns, intl } = this.props; + const { services, indexPatterns } = this.props; this.setState({ error: undefined, @@ -351,11 +349,10 @@ class FlyoutUI extends Component { // Do not Promise.all these calls as the order matters this.setState({ - loadingMessage: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.resolvingConflictsLoadingMessage', - defaultMessage: 'Resolving conflicts…', - }), + loadingMessage: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.resolvingConflictsLoadingMessage', + { defaultMessage: 'Resolving conflicts…' } + ), }); if (resolutions.length) { importCount += await resolveIndexPatternConflicts( @@ -365,22 +362,20 @@ class FlyoutUI extends Component { ); } this.setState({ - loadingMessage: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savingConflictsLoadingMessage', - defaultMessage: 'Saving conflicts…', - }), + loadingMessage: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savingConflictsLoadingMessage', + { defaultMessage: 'Saving conflicts…' } + ), }); importCount += await saveObjects( conflictedSavedObjectsLinkedToSavedSearches, isOverwriteAllChecked ); this.setState({ - loadingMessage: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savedSearchAreLinkedProperlyLoadingMessage', - defaultMessage: 'Ensure saved searches are linked properly…', - }), + loadingMessage: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.savedSearchAreLinkedProperlyLoadingMessage', + { defaultMessage: 'Ensure saved searches are linked properly…' } + ), }); importCount += await resolveSavedSearches( conflictedSearchDocs, @@ -389,11 +384,10 @@ class FlyoutUI extends Component { isOverwriteAllChecked ); this.setState({ - loadingMessage: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.retryingFailedObjectsLoadingMessage', - defaultMessage: 'Retrying failed objects…', - }), + loadingMessage: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.confirmLegacyImport.retryingFailedObjectsLoadingMessage', + { defaultMessage: 'Retrying failed objects…' } + ), }); importCount += await saveObjects( failedImports.map(({ obj }) => obj), @@ -437,7 +431,6 @@ class FlyoutUI extends Component { renderUnmatchedReferences() { const { unmatchedReferences } = this.state; - const { intl } = this.props; if (!unmatchedReferences) { return null; @@ -446,42 +439,40 @@ class FlyoutUI extends Component { const columns = [ { field: 'existingIndexPatternId', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnIdName', - defaultMessage: 'ID', - }), - description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnIdDescription', - defaultMessage: 'ID of the index pattern', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnIdName', + { defaultMessage: 'ID' } + ), + description: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnIdDescription', + { defaultMessage: 'ID of the index pattern' } + ), sortable: true, }, { field: 'list', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnCountName', - defaultMessage: 'Count', - }), - description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnCountDescription', - defaultMessage: 'How many affected objects', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnCountName', + { defaultMessage: 'Count' } + ), + description: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnCountDescription', + { defaultMessage: 'How many affected objects' } + ), render: list => { return {list.length}; }, }, { field: 'list', - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsName', - defaultMessage: 'Sample of affected objects', - }), - description: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsDescription', - defaultMessage: 'Sample of affected objects', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsName', + { defaultMessage: 'Sample of affected objects' } + ), + description: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnSampleOfAffectedObjectsDescription', + { defaultMessage: 'Sample of affected objects' } + ), render: list => { return (
    @@ -494,11 +485,10 @@ class FlyoutUI extends Component { }, { field: 'existingIndexPatternId', - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnNewIndexPatternName', - defaultMessage: 'New index pattern', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.flyout.renderConflicts.columnNewIndexPatternName', + { defaultMessage: 'New index pattern' } + ), render: id => { const options = this.state.indexPatterns.map(indexPattern => ({ text: indexPattern.title, @@ -557,7 +547,6 @@ class FlyoutUI extends Component { } renderBody() { - const { intl } = this.props; const { status, loadingMessage, @@ -612,29 +601,28 @@ class FlyoutUI extends Component { .map(({ error, obj }) => { if (error.type === 'missing_references') { return error.references.map(reference => { - return intl.formatMessage( + return i18n.translate( + 'kbn.management.objects.objectsTable.flyout.importFailedMissingReference', { - id: - 'kbn.management.objects.objectsTable.flyout.importFailedMissingReference', defaultMessage: '{type} [id={id}] could not locate {refType} [id={refId}]', - }, - { - id: obj.id, - type: obj.type, - refId: reference.id, - refType: reference.type, + values: { + id: obj.id, + type: obj.type, + refId: reference.id, + refType: reference.type, + }, } ); }); } else if (error.type === 'unsupported_type') { - return intl.formatMessage( + return i18n.translate( + 'kbn.management.objects.objectsTable.flyout.importFailedUnsupportedType', { - id: 'kbn.management.objects.objectsTable.flyout.importFailedUnsupportedType', defaultMessage: '{type} [id={id}] unsupported type', - }, - { - id: obj.id, - type: obj.type, + values: { + id: obj.id, + type: obj.type, + }, } ); } @@ -883,28 +871,28 @@ class FlyoutUI extends Component { } render() { - const { close, intl } = this.props; + const { close } = this.props; let confirmOverwriteModal; if (this.state.conflictingRecord) { confirmOverwriteModal = ( ({ kfetch: jest.fn() })); jest.mock('ui/chrome', () => ({ - addBasePath: () => '' + addBasePath: () => '', })); jest.mock('../../../../../lib/fetch_export_by_type', () => ({ @@ -37,11 +37,10 @@ jest.mock('../../../../../lib/fetch_export_objects', () => ({ import { Relationships } from '../relationships'; describe('Relationships', () => { - it('should render index patterns normally', async () => { const props = { goInspectObject: () => {}, - getRelationships: jest.fn().mockImplementation(() => ([ + getRelationships: jest.fn().mockImplementation(() => [ { type: 'search', id: '1', @@ -70,7 +69,7 @@ describe('Relationships', () => { title: 'My Visualization Title', }, }, - ])), + ]), savedObject: { id: '1', type: 'index-pattern', @@ -87,11 +86,7 @@ describe('Relationships', () => { close: jest.fn(), }; - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Make sure we are showing loading expect(component.find('EuiLoadingKibana').length).toBe(1); @@ -108,7 +103,7 @@ describe('Relationships', () => { it('should render searches normally', async () => { const props = { goInspectObject: () => {}, - getRelationships: jest.fn().mockImplementation(() => ([ + getRelationships: jest.fn().mockImplementation(() => [ { type: 'index-pattern', id: '1', @@ -137,7 +132,7 @@ describe('Relationships', () => { title: 'My Visualization Title', }, }, - ])), + ]), savedObject: { id: '1', type: 'search', @@ -154,11 +149,7 @@ describe('Relationships', () => { close: jest.fn(), }; - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Make sure we are showing loading expect(component.find('EuiLoadingKibana').length).toBe(1); @@ -175,7 +166,7 @@ describe('Relationships', () => { it('should render visualizations normally', async () => { const props = { goInspectObject: () => {}, - getRelationships: jest.fn().mockImplementation(() => ([ + getRelationships: jest.fn().mockImplementation(() => [ { type: 'dashboard', id: '1', @@ -204,7 +195,7 @@ describe('Relationships', () => { title: 'My Dashboard 2', }, }, - ])), + ]), savedObject: { id: '1', type: 'visualization', @@ -221,11 +212,7 @@ describe('Relationships', () => { close: jest.fn(), }; - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Make sure we are showing loading expect(component.find('EuiLoadingKibana').length).toBe(1); @@ -242,7 +229,7 @@ describe('Relationships', () => { it('should render dashboards normally', async () => { const props = { goInspectObject: () => {}, - getRelationships: jest.fn().mockImplementation(() => ([ + getRelationships: jest.fn().mockImplementation(() => [ { type: 'visualization', id: '1', @@ -271,7 +258,7 @@ describe('Relationships', () => { title: 'My Visualization Title 2', }, }, - ])), + ]), savedObject: { id: '1', type: 'dashboard', @@ -288,11 +275,7 @@ describe('Relationships', () => { close: jest.fn(), }; - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Make sure we are showing loading expect(component.find('EuiLoadingKibana').length).toBe(1); @@ -328,11 +311,7 @@ describe('Relationships', () => { close: jest.fn(), }; - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); // Ensure all promises resolve await new Promise(resolve => process.nextTick(resolve)); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js index c5ed65606489b..278f7de38b19d 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/relationships/relationships.js @@ -35,10 +35,11 @@ import { EuiSpacer, } from '@elastic/eui'; import chrome from 'ui/chrome'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import { getDefaultTitle, getSavedObjectLabel } from '../../../../lib'; -class RelationshipsUI extends Component { +export class Relationships extends Component { static propTypes = { getRelationships: PropTypes.func.isRequired, savedObject: PropTypes.object.isRequired, @@ -103,7 +104,7 @@ class RelationshipsUI extends Component { } renderRelationships() { - const { intl, goInspectObject, savedObject } = this.props; + const { goInspectObject, savedObject } = this.props; const { relationships, isLoading, error } = this.state; if (error) { @@ -117,16 +118,15 @@ class RelationshipsUI extends Component { const columns = [ { field: 'type', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnTypeName', + name: i18n.translate('kbn.management.objects.objectsTable.relationships.columnTypeName', { defaultMessage: 'Type', }), width: '50px', align: 'center', - description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnTypeDescription', - defaultMessage: 'Type of the saved object', - }), + description: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.columnTypeDescription', + { defaultMessage: 'Type of the saved object' } + ), sortable: false, render: (type, object) => { return ( @@ -142,10 +142,10 @@ class RelationshipsUI extends Component { }, { field: 'relationship', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnRelationshipName', - defaultMessage: 'Direct relationship', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.columnRelationshipName', + { defaultMessage: 'Direct relationship' } + ), dataType: 'string', sortable: false, width: '125px', @@ -174,14 +174,13 @@ class RelationshipsUI extends Component { }, { field: 'meta.title', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnTitleName', + name: i18n.translate('kbn.management.objects.objectsTable.relationships.columnTitleName', { defaultMessage: 'Title', }), - description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnTitleDescription', - defaultMessage: 'Title of the saved object', - }), + description: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.columnTitleDescription', + { defaultMessage: 'Title of the saved object' } + ), dataType: 'string', sortable: false, render: (title, object) => { @@ -196,22 +195,20 @@ class RelationshipsUI extends Component { }, }, { - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.columnActionsName', - defaultMessage: 'Actions', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.columnActionsName', + { defaultMessage: 'Actions' } + ), actions: [ { - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionName', - defaultMessage: 'Inspect', - }), - description: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionDescription', - defaultMessage: 'Inspect this saved object', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionName', + { defaultMessage: 'Inspect' } + ), + description: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.columnActions.inspectActionDescription', + { defaultMessage: 'Inspect this saved object' } + ), type: 'icon', icon: 'inspect', onClick: object => goInspectObject(object), @@ -237,40 +234,37 @@ class RelationshipsUI extends Component { { type: 'field_value_selection', field: 'relationship', - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.name', - defaultMessage: 'Direct relationship', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.name', + { defaultMessage: 'Direct relationship' } + ), multiSelect: 'or', options: [ { value: 'parent', name: 'parent', - view: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.parentAsValue.view', - defaultMessage: 'Parent', - }), + view: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.parentAsValue.view', + { defaultMessage: 'Parent' } + ), }, { value: 'child', name: 'child', - view: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.childAsValue.view', - defaultMessage: 'Child', - }), + view: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.search.filters.relationship.childAsValue.view', + { defaultMessage: 'Child' } + ), }, ], }, { type: 'field_value_selection', field: 'type', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.relationships.search.filters.type.name', - defaultMessage: 'Type', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.relationships.search.filters.type.name', + { defaultMessage: 'Type' } + ), multiSelect: 'or', options: [...filterTypesMap.values()], }, @@ -281,16 +275,16 @@ class RelationshipsUI extends Component {

    - {intl.formatMessage( + {i18n.translate( + 'kbn.management.objects.objectsTable.relationships.relationshipsTitle', { - id: 'kbn.management.objects.objectsTable.relationships.relationshipsTitle', defaultMessage: 'Here are the saved objects related to {title}. ' + 'Deleting this {type} affects its parent objects, but not its children.', - }, - { - type: savedObject.type, - title: savedObject.meta.title || getDefaultTitle(savedObject), + values: { + type: savedObject.type, + title: savedObject.meta.title || getDefaultTitle(savedObject), + }, } )}

    @@ -332,5 +326,3 @@ class RelationshipsUI extends Component { ); } } - -export const Relationships = injectI18n(RelationshipsUI); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/__jest__/table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/__jest__/table.test.js index e36c340751dc6..d3f5fb1945254 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/__jest__/table.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/__jest__/table.test.js @@ -18,32 +18,34 @@ */ import React from 'react'; -import { shallowWithIntl, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers'; import { findTestSubject } from '@elastic/eui/lib/test'; import { keyCodes } from '@elastic/eui/lib/services'; jest.mock('ui/kfetch', () => ({ kfetch: jest.fn() })); jest.mock('ui/chrome', () => ({ - addBasePath: () => '' + addBasePath: () => '', })); import { Table } from '../table'; const defaultProps = { - selectedSavedObjects: [{ - id: '1', - type: 'index-pattern', - meta: { - title: `MyIndexPattern*`, - icon: 'indexPatternApp', - editUrl: '#/management/kibana/index_patterns/1', - inAppUrl: { - path: '/management/kibana/index_patterns/1', - uiCapabilitiesPath: 'management.kibana.index_patterns', + selectedSavedObjects: [ + { + id: '1', + type: 'index-pattern', + meta: { + title: `MyIndexPattern*`, + icon: 'indexPatternApp', + editUrl: '#/management/kibana/index_patterns/1', + inAppUrl: { + path: '/management/kibana/index_patterns/1', + uiCapabilitiesPath: 'management.kibana.index_patterns', + }, }, }, - }], + ], selectionConfig: { onSelectionChange: () => {}, }, @@ -54,35 +56,33 @@ const defaultProps = { canGoInApp: () => {}, pageIndex: 1, pageSize: 2, - items: [{ - id: '1', - type: 'index-pattern', - meta: { - title: `MyIndexPattern*`, - icon: 'indexPatternApp', - editUrl: '#/management/kibana/index_patterns/1', - inAppUrl: { - path: '/management/kibana/index_patterns/1', - uiCapabilitiesPath: 'management.kibana.index_patterns', + items: [ + { + id: '1', + type: 'index-pattern', + meta: { + title: `MyIndexPattern*`, + icon: 'indexPatternApp', + editUrl: '#/management/kibana/index_patterns/1', + inAppUrl: { + path: '/management/kibana/index_patterns/1', + uiCapabilitiesPath: 'management.kibana.index_patterns', + }, }, }, - }], + ], itemId: 'id', totalItemCount: 3, onQueryChange: () => {}, onTableChange: () => {}, isSearching: false, onShowRelationships: () => {}, - canDelete: true + canDelete: true, }; describe('Table', () => { it('should render normally', () => { - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(); expect(component).toMatchSnapshot(); }); @@ -91,14 +91,10 @@ describe('Table', () => { const onQueryChangeMock = jest.fn(); const customizedProps = { ...defaultProps, - onQueryChange: onQueryChangeMock + onQueryChange: onQueryChangeMock, }; - const component = mountWithIntl( - - ); + const component = mountWithI18nProvider(
    ); const searchBar = findTestSubject(component, 'savedObjectSearchBar'); // Send invalid query @@ -115,13 +111,13 @@ describe('Table', () => { }); it(`prevents saved objects from being deleted`, () => { - const selectedSavedObjects = [{ type: 'visualization' }, { type: 'search' }, { type: 'index-pattern' }]; + const selectedSavedObjects = [ + { type: 'visualization' }, + { type: 'search' }, + { type: 'index-pattern' }, + ]; const customizedProps = { ...defaultProps, selectedSavedObjects, canDelete: false }; - const component = shallowWithIntl( - - ); + const component = shallowWithI18nProvider(
    ); expect(component).toMatchSnapshot(); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js index b1887c32a9a1d..43cf8c2a23286 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/components/table/table.js @@ -38,9 +38,9 @@ import { } from '@elastic/eui'; import { getDefaultTitle, getSavedObjectLabel } from '../../../../lib'; import { i18n } from '@kbn/i18n'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; -class TableUI extends PureComponent { +export class Table extends PureComponent { static propTypes = { selectedSavedObjects: PropTypes.array.isRequired, selectionConfig: PropTypes.shape({ @@ -136,7 +136,6 @@ class TableUI extends PureComponent { onTableChange, goInspectObject, onShowRelationships, - intl, } = this.props; const pagination = { @@ -150,8 +149,7 @@ class TableUI extends PureComponent { { type: 'field_value_selection', field: 'type', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.typeFilterName', + name: i18n.translate('kbn.management.objects.objectsTable.table.typeFilterName', { defaultMessage: 'Type', }), multiSelect: 'or', @@ -170,16 +168,15 @@ class TableUI extends PureComponent { const columns = [ { field: 'type', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnTypeName', + name: i18n.translate('kbn.management.objects.objectsTable.table.columnTypeName', { defaultMessage: 'Type', }), width: '50px', align: 'center', - description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnTypeDescription', - defaultMessage: 'Type of the saved object', - }), + description: i18n.translate( + 'kbn.management.objects.objectsTable.table.columnTypeDescription', + { defaultMessage: 'Type of the saved object' } + ), sortable: false, render: (type, object) => { return ( @@ -195,14 +192,13 @@ class TableUI extends PureComponent { }, { field: 'meta.title', - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnTitleName', + name: i18n.translate('kbn.management.objects.objectsTable.table.columnTitleName', { defaultMessage: 'Title', }), - description: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnTitleDescription', - defaultMessage: 'Title of the saved object', - }), + description: i18n.translate( + 'kbn.management.objects.objectsTable.table.columnTitleDescription', + { defaultMessage: 'Title of the saved object' } + ), dataType: 'string', sortable: false, render: (title, object) => { @@ -217,37 +213,36 @@ class TableUI extends PureComponent { }, }, { - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnActionsName', + name: i18n.translate('kbn.management.objects.objectsTable.table.columnActionsName', { defaultMessage: 'Actions', }), actions: [ { - name: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.table.columnActions.inspectActionName', - defaultMessage: 'Inspect', - }), - description: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.table.columnActions.inspectActionDescription', - defaultMessage: 'Inspect this saved object', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.table.columnActions.inspectActionName', + { defaultMessage: 'Inspect' } + ), + description: i18n.translate( + 'kbn.management.objects.objectsTable.table.columnActions.inspectActionDescription', + { defaultMessage: 'Inspect this saved object' } + ), type: 'icon', icon: 'inspect', onClick: object => goInspectObject(object), available: object => !!object.meta.editUrl, }, { - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionName', - defaultMessage: 'Relationships', - }), - description: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionDescription', - defaultMessage: 'View the relationships this saved object has to other saved objects', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionName', + { defaultMessage: 'Relationships' } + ), + description: i18n.translate( + 'kbn.management.objects.objectsTable.table.columnActions.viewRelationshipsActionDescription', + { + defaultMessage: + 'View the relationships this saved object has to other saved objects', + } + ), type: 'icon', icon: 'kqlSelector', onClick: object => onShowRelationships(object), @@ -276,10 +271,10 @@ class TableUI extends PureComponent { let queryParseError; if (!this.state.isSearchTextValid) { - const parseErrorMsg = intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.searchBar.unableToParseQueryErrorMessage', - defaultMessage: 'Unable to parse query', - }); + const parseErrorMsg = i18n.translate( + 'kbn.management.objects.objectsTable.searchBar.unableToParseQueryErrorMessage', + { defaultMessage: 'Unable to parse query' } + ); queryParseError = ( {`${parseErrorMsg}. ${this.state.parseErrorMessage}`} ); @@ -383,5 +378,3 @@ class TableUI extends PureComponent { ); } } - -export const Table = injectI18n(TableUI); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/objects_table.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/objects_table.js index 42f787b988230..0b084d546bcb9 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/objects_table.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/objects_table.js @@ -52,6 +52,9 @@ import { EuiFlexGroup, EuiFlexItem, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; + import { parseQuery, getSavedObjectCounts, @@ -61,11 +64,10 @@ import { fetchExportByType, findObjects, } from '../../lib'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; export const POSSIBLE_TYPES = chrome.getInjected('importAndExportableTypes'); -class ObjectsTableUI extends Component { +export class ObjectsTable extends Component { static propTypes = { savedObjectsClient: PropTypes.object.isRequired, indexPatterns: PropTypes.object.isRequired, @@ -174,7 +176,6 @@ class ObjectsTableUI extends Component { }; debouncedFetch = debounce(async () => { - const { intl } = this.props; const { activeQuery: query, page, perPage } = this.state; const { queryText, visibleTypes } = parseQuery(query); // "searchFields" is missing from the "findOptions" but gets injected via the API. @@ -200,10 +201,10 @@ class ObjectsTableUI extends Component { }); } toastNotifications.addDanger({ - title: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.unableFindSavedObjectsNotificationMessage', - defaultMessage: 'Unable find saved objects', - }), + title: i18n.translate( + 'kbn.management.objects.objectsTable.unableFindSavedObjectsNotificationMessage', + { defaultMessage: 'Unable find saved objects' } + ), text: `${error}`, }); return; @@ -279,7 +280,6 @@ class ObjectsTableUI extends Component { }; onExport = async includeReferencesDeep => { - const { intl } = this.props; const { selectedSavedObjects } = this.state; const objectsToExport = selectedSavedObjects.map(obj => ({ id: obj.id, type: obj.type })); @@ -288,8 +288,7 @@ class ObjectsTableUI extends Component { blob = await fetchExportObjects(objectsToExport, includeReferencesDeep); } catch (e) { toastNotifications.addDanger({ - title: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.export.dangerNotification', + title: i18n.translate('kbn.management.objects.objectsTable.export.dangerNotification', { defaultMessage: 'Unable to generate export', }), }); @@ -298,15 +297,13 @@ class ObjectsTableUI extends Component { saveAs(blob, 'export.ndjson'); toastNotifications.addSuccess({ - title: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.export.successNotification', + title: i18n.translate('kbn.management.objects.objectsTable.export.successNotification', { defaultMessage: 'Your file is downloading in the background', }), }); }; onExportAll = async () => { - const { intl } = this.props; const { exportAllSelectedOptions, isIncludeReferencesDeepChecked } = this.state; const exportTypes = Object.entries(exportAllSelectedOptions).reduce((accum, [id, selected]) => { if (selected) { @@ -320,8 +317,7 @@ class ObjectsTableUI extends Component { blob = await fetchExportByType(exportTypes, isIncludeReferencesDeepChecked); } catch (e) { toastNotifications.addDanger({ - title: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.exportAll.dangerNotification', + title: i18n.translate('kbn.management.objects.objectsTable.exportAll.dangerNotification', { defaultMessage: 'Unable to generate export', }), }); @@ -330,8 +326,7 @@ class ObjectsTableUI extends Component { saveAs(blob, 'export.ndjson'); toastNotifications.addSuccess({ - title: intl.formatMessage({ - id: 'kbn.management.objects.objectsTable.exportAll.successNotification', + title: i18n.translate('kbn.management.objects.objectsTable.exportAll.successNotification', { defaultMessage: 'Your file is downloading in the background', }), }); @@ -440,7 +435,6 @@ class ObjectsTableUI extends Component { renderDeleteConfirmModal() { const { isShowingDeleteConfirmModal, isDeleting, selectedSavedObjects } = this.state; - const { intl } = this.props; if (!isShowingDeleteConfirmModal) { return null; @@ -503,11 +497,10 @@ class ObjectsTableUI extends Component { columns={[ { field: 'type', - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.typeColumnName', - defaultMessage: 'Type', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.typeColumnName', + { defaultMessage: 'Type' } + ), width: '50px', render: (type, object) => ( @@ -517,19 +510,17 @@ class ObjectsTableUI extends Component { }, { field: 'id', - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.idColumnName', - defaultMessage: 'Id', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.idColumnName', + { defaultMessage: 'Id' } + ), }, { field: 'meta.title', - name: intl.formatMessage({ - id: - 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.titleColumnName', - defaultMessage: 'Title', - }), + name: i18n.translate( + 'kbn.management.objects.objectsTable.deleteSavedObjectsConfirmModal.titleColumnName', + { defaultMessage: 'Title' } + ), }, ]} pagination={true} @@ -705,5 +696,3 @@ class ObjectsTableUI extends Component { ); } } - -export const ObjectsTable = injectI18n(ObjectsTableUI); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap index 8c1db0c33e0b0..10d165d0d69c4 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/__snapshots__/advanced_settings.test.js.snap @@ -317,7 +317,7 @@ exports[`AdvancedSettings should render normally 1`] = ` } } /> - - - { if (this.props.setting.requiresPageReload) { toastNotifications.add({ - title: this.props.intl.formatMessage( - { - id: 'kbn.management.settings.field.requiresPageReloadToastDescription', - defaultMessage: - 'Please reload the page for the "{settingName}" setting to take effect.', - }, - { + title: i18n.translate('kbn.management.settings.field.requiresPageReloadToastDescription', { + defaultMessage: 'Please reload the page for the "{settingName}" setting to take effect.', + values: { settingName: this.props.setting.displayName || this.props.setting.name, - } - ), + }, + }), text: ( <> window.location.reload()}> - {this.props.intl.formatMessage({ - id: 'kbn.management.settings.field.requiresPageReloadToastButtonLabel', - defaultMessage: 'Reload page', - })} + {i18n.translate( + 'kbn.management.settings.field.requiresPageReloadToastButtonLabel', + { defaultMessage: 'Reload page' } + )} @@ -371,13 +363,10 @@ class FieldUI extends PureComponent { } } catch (e) { toastNotifications.addDanger( - this.props.intl.formatMessage( - { - id: 'kbn.management.settings.field.saveFieldErrorMessage', - defaultMessage: 'Unable to save {name}', - }, - { name } - ) + i18n.translate('kbn.management.settings.field.saveFieldErrorMessage', { + defaultMessage: 'Unable to save {name}', + values: { name }, + }) ); } this.setLoading(false); @@ -393,13 +382,10 @@ class FieldUI extends PureComponent { this.clearError(); } catch (e) { toastNotifications.addDanger( - this.props.intl.formatMessage( - { - id: 'kbn.management.settings.field.resetFieldErrorMessage', - defaultMessage: 'Unable to reset {name}', - }, - { name } - ) + i18n.translate('kbn.management.settings.field.resetFieldErrorMessage', { + defaultMessage: 'Unable to reset {name}', + values: { name }, + }) ); } this.setLoading(false); @@ -560,8 +546,7 @@ class FieldUI extends PureComponent { @@ -687,15 +669,12 @@ class FieldUI extends PureComponent { return ( @@ -712,7 +691,6 @@ class FieldUI extends PureComponent { const { ariaName, name } = setting; const { loading, isInvalid, changeImage, savedValue, unsavedValue } = this.state; const isDisabled = loading || setting.isOverridden; - const { intl } = this.props; if (savedValue === unsavedValue && !changeImage) { return; @@ -724,15 +702,12 @@ class FieldUI extends PureComponent { (changeImage ? this.cancelChangeImage() : this.cancelEdit())} @@ -799,5 +774,3 @@ class FieldUI extends PureComponent { ); } } - -export const Field = injectI18n(FieldUI); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js index 0a2886d0d0287..ddd2e3984caed 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js @@ -18,7 +18,7 @@ */ import React from 'react'; -import { shallowWithIntl, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider, mountWithIntl } from 'test_utils/enzyme_helpers'; import { findTestSubject } from '@elastic/eui/lib/test'; import { Field } from './field'; @@ -183,7 +183,7 @@ describe('Field', () => { describe(`for ${type} setting`, () => { it('should render default value if there is no user value set', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render as read only with help text if overridden', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render as read only if saving is disabled', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render user value if there is user value is set', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( { }); it('should render custom setting icon if it is custom', async () => { - const component = shallowWithIntl( + const component = shallowWithI18nProvider( ({ Field: () => { return 'field'; - } + }, })); const settings = { - 'dashboard': [ + dashboard: [ { name: 'dashboard:test:setting', ariaName: 'dashboard test setting', @@ -37,7 +37,7 @@ const settings = { category: ['dashboard'], }, ], - 'general': [ + general: [ { name: 'general:test:date', ariaName: 'general test date', @@ -69,14 +69,14 @@ const categoryCounts = { dashboard: 1, 'x-pack': 10, }; -const save = () => { }; -const clear = () => { }; -const clearQuery = () => { }; +const save = () => {}; +const clear = () => {}; +const clearQuery = () => {}; describe('Form', () => { it('should render normally', async () => { - const component = shallowWithIntl( - { }); it('should render read-only when saving is disabled', async () => { - const component = shallowWithIntl( - { }); it('should render no settings message when there are no settings', async () => { - const component = shallowWithIntl( - { }); it('should not render no settings message when instructed not to', async () => { - const component = shallowWithIntl( - { it('should render normally', () => { - expect(shallowWithIntl()).toMatchSnapshot(); + expect(shallowWithI18nProvider()).toMatchSnapshot(); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.js index 999d6a2143f4c..0703706a50101 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_subtitle/page_subtitle.test.js @@ -17,12 +17,12 @@ * under the License. */ import React from 'react'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { PageSubtitle } from './page_subtitle'; describe('PageSubtitle', () => { it('should render normally', () => { - expect(shallowWithIntl()).toMatchSnapshot(); + expect(shallowWithI18nProvider()).toMatchSnapshot(); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.js index 261f892c22f45..54244909a668a 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/page_title/page_title.test.js @@ -17,12 +17,12 @@ * under the License. */ import React from 'react'; -import { shallowWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; import { PageTitle } from './page_title'; describe('PageTitle', () => { it('should render normally', () => { - expect(shallowWithIntl()).toMatchSnapshot(); + expect(shallowWithI18nProvider()).toMatchSnapshot(); }); }); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js index a85e2299e7502..02315e73cc11b 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.js @@ -19,13 +19,13 @@ import React, { Fragment, PureComponent } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import { EuiSearchBar, EuiFormErrorText } from '@elastic/eui'; import { getCategoryName } from '../../lib'; -class SearchUI extends PureComponent { +export class Search extends PureComponent { static propTypes = { categories: PropTypes.array.isRequired, query: PropTypes.object.isRequired, @@ -65,13 +65,12 @@ class SearchUI extends PureComponent { }; render() { - const { query, intl } = this.props; + const { query } = this.props; const box = { incremental: true, 'data-test-subj': 'settingsSearchBar', - 'aria-label': intl.formatMessage({ - id: 'kbn.management.settings.searchBarAriaLabel', + 'aria-label': i18n.translate('kbn.management.settings.searchBarAriaLabel', { defaultMessage: 'Search advanced settings', }), // hack until EuiSearchBar is fixed }; @@ -80,8 +79,7 @@ class SearchUI extends PureComponent { { type: 'field_value_selection', field: 'category', - name: intl.formatMessage({ - id: 'kbn.management.settings.categorySearchLabel', + name: i18n.translate('kbn.management.settings.categorySearchLabel', { defaultMessage: 'Category', }), multiSelect: 'or', @@ -91,10 +89,10 @@ class SearchUI extends PureComponent { let queryParseError; if (!this.state.isSearchTextValid) { - const parseErrorMsg = intl.formatMessage({ - id: 'kbn.management.settings.searchBar.unableToParseQueryErrorMessage', - defaultMessage: 'Unable to parse query', - }); + const parseErrorMsg = i18n.translate( + 'kbn.management.settings.searchBar.unableToParseQueryErrorMessage', + { defaultMessage: 'Unable to parse query' } + ); queryParseError = ( {`${parseErrorMsg}. ${this.state.parseErrorMessage}`} ); @@ -108,5 +106,3 @@ class SearchUI extends PureComponent { ); } } - -export const Search = injectI18n(SearchUI); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js index 40532605d807a..3cd2de6ddccaa 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/search/search.test.js @@ -18,10 +18,9 @@ */ import React from 'react'; -import { shallowWithIntl, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers'; import { findTestSubject } from '@elastic/eui/lib/test'; - import { Query } from '@elastic/eui'; import { Search } from './search'; @@ -31,12 +30,8 @@ const categories = ['general', 'dashboard', 'hiddenCategory', 'x-pack']; describe('Search', () => { it('should render normally', async () => { const onQueryChange = () => {}; - const component = shallowWithIntl( - + const component = shallowWithI18nProvider( + ); expect(component).toMatchSnapshot(); @@ -46,25 +41,19 @@ describe('Search', () => { //This test is brittle as it knows about implementation details // (EuiFieldSearch uses onKeyup instead of onChange to handle input) const onQueryChange = jest.fn(); - const component = mountWithIntl( - + const component = mountWithI18nProvider( + ); - findTestSubject(component, 'settingsSearchBar').simulate('keyup', { target: { value: 'new filter' } }); + findTestSubject(component, 'settingsSearchBar').simulate('keyup', { + target: { value: 'new filter' }, + }); expect(onQueryChange).toHaveBeenCalledTimes(1); }); it('should handle query parse error', async () => { const onQueryChangeMock = jest.fn(); - const component = mountWithIntl( - + const component = mountWithI18nProvider( + ); const searchBar = findTestSubject(component, 'settingsSearchBar'); From 1f947bc0805c869b11aee22b9b6629b59b94bad9 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Wed, 18 Sep 2019 11:58:11 +0900 Subject: [PATCH 03/10] Fixed Field.js and its tests. --- .../field/__snapshots__/field.test.js.snap | 444 ++---------------- .../settings/components/field/field.js | 90 ++-- .../settings/components/field/field.test.js | 213 +++++---- 3 files changed, 195 insertions(+), 552 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap index eb8454f64e7ba..eb345fa8b4a04 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap @@ -93,17 +93,7 @@ exports[`Field for array setting should render as read only with help text if ov size="xs" > - - default_value - , - } - } - /> + Default: [object Object] @@ -135,11 +125,7 @@ exports[`Field for array setting should render as read only with help text if ov - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -195,13 +181,7 @@ exports[`Field for array setting should render custom setting icon if it is cust - } + content="Custom setting" type="asterisk" /> @@ -337,17 +317,7 @@ exports[`Field for array setting should render user value if there is user value size="xs" > - - default_value - , - } - } - /> + Default: [object Object] @@ -385,11 +355,7 @@ exports[`Field for array setting should render user value if there is user value onClick={[Function]} type="button" > - + Reset to default     @@ -471,13 +437,7 @@ exports[`Field for boolean setting should render as read only if saving is disab checked={true} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={true} - label={ - - } + label="On" onChange={[Function]} onKeyDown={[Function]} /> @@ -516,17 +476,7 @@ exports[`Field for boolean setting should render as read only with help text if size="xs" > - - true - , - } - } - /> + Default: [object Object] @@ -558,11 +508,7 @@ exports[`Field for boolean setting should render as read only with help text if - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -574,13 +520,7 @@ exports[`Field for boolean setting should render as read only with help text if checked={false} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={true} - label={ - - } + label="Off" onChange={[Function]} onKeyDown={[Function]} /> @@ -622,13 +562,7 @@ exports[`Field for boolean setting should render custom setting icon if it is cu - } + content="Custom setting" type="asterisk" /> @@ -656,13 +590,7 @@ exports[`Field for boolean setting should render custom setting icon if it is cu checked={true} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={false} - label={ - - } + label="On" onChange={[Function]} onKeyDown={[Function]} /> @@ -727,13 +655,7 @@ exports[`Field for boolean setting should render default value if there is no us checked={true} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={false} - label={ - - } + label="On" onChange={[Function]} onKeyDown={[Function]} /> @@ -772,17 +694,7 @@ exports[`Field for boolean setting should render user value if there is user val size="xs" > - - true - , - } - } - /> + Default: [object Object] @@ -820,11 +732,7 @@ exports[`Field for boolean setting should render user value if there is user val onClick={[Function]} type="button" > - + Reset to default     @@ -839,13 +747,7 @@ exports[`Field for boolean setting should render user value if there is user val checked={false} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={false} - label={ - - } + label="Off" onChange={[Function]} onKeyDown={[Function]} /> @@ -950,17 +852,7 @@ exports[`Field for image setting should render as read only with help text if ov size="xs" > - - null - , - } - } - /> + Default: [object Object] @@ -992,11 +884,7 @@ exports[`Field for image setting should render as read only with help text if ov - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -1047,13 +935,7 @@ exports[`Field for image setting should render custom setting icon if it is cust - } + content="Custom setting" type="asterisk" /> @@ -1187,17 +1069,7 @@ exports[`Field for image setting should render user value if there is user value size="xs" > - - null - , - } - } - /> + Default: [object Object] @@ -1235,11 +1107,7 @@ exports[`Field for image setting should render user value if there is user value onClick={[Function]} type="button" > - + Reset to default     @@ -1251,11 +1119,7 @@ exports[`Field for image setting should render user value if there is user value onClick={[Function]} type="button" > - + Change image @@ -1305,21 +1169,7 @@ exports[`Field for json setting should render as read only if saving is disabled size="xs" > - - {} - , - } - } - /> + Default: [object Object] @@ -1415,21 +1265,7 @@ exports[`Field for json setting should render as read only with help text if ove size="xs" > - - {} - , - } - } - /> + Default: [object Object] @@ -1461,11 +1297,7 @@ exports[`Field for json setting should render as read only with help text if ove - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -1538,13 +1370,7 @@ exports[`Field for json setting should render custom setting icon if it is custo - } + content="Custom setting" type="asterisk" /> @@ -1630,21 +1456,7 @@ exports[`Field for json setting should render default value if there is no user size="xs" > - - {} - , - } - } - /> + Default: [object Object] @@ -1682,11 +1494,7 @@ exports[`Field for json setting should render default value if there is no user onClick={[Function]} type="button" > - + Reset to default     @@ -1759,21 +1567,7 @@ exports[`Field for json setting should render user value if there is user value size="xs" > - - {} - , - } - } - /> + Default: [object Object] @@ -1811,11 +1605,7 @@ exports[`Field for json setting should render user value if there is user value onClick={[Function]} type="button" > - + Reset to default     @@ -1972,17 +1762,7 @@ exports[`Field for markdown setting should render as read only with help text if size="xs" > - - null - , - } - } - /> + Default: [object Object] @@ -2014,11 +1794,7 @@ exports[`Field for markdown setting should render as read only with help text if - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -2091,13 +1867,7 @@ exports[`Field for markdown setting should render custom setting icon if it is c - } + content="Custom setting" type="asterisk" /> @@ -2267,17 +2037,7 @@ exports[`Field for markdown setting should render user value if there is user va size="xs" > - - null - , - } - } - /> + Default: [object Object] @@ -2315,11 +2075,7 @@ exports[`Field for markdown setting should render user value if there is user va onClick={[Function]} type="button" > - + Reset to default     @@ -2459,17 +2215,7 @@ exports[`Field for number setting should render as read only with help text if o size="xs" > - - 5 - , - } - } - /> + Default: [object Object] @@ -2501,11 +2247,7 @@ exports[`Field for number setting should render as read only with help text if o - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -2561,13 +2303,7 @@ exports[`Field for number setting should render custom setting icon if it is cus - } + content="Custom setting" type="asterisk" /> @@ -2703,17 +2439,7 @@ exports[`Field for number setting should render user value if there is user valu size="xs" > - - 5 - , - } - } - /> + Default: [object Object] @@ -2751,11 +2477,7 @@ exports[`Field for number setting should render user value if there is user valu onClick={[Function]} type="button" > - + Reset to default     @@ -2895,17 +2617,7 @@ exports[`Field for select setting should render as read only with help text if o size="xs" > - - Orange - , - } - } - /> + Default: [object Object] @@ -2937,11 +2649,7 @@ exports[`Field for select setting should render as read only with help text if o - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -3014,13 +2722,7 @@ exports[`Field for select setting should render custom setting icon if it is cus - } + content="Custom setting" type="asterisk" /> @@ -3190,17 +2892,7 @@ exports[`Field for select setting should render user value if there is user valu size="xs" > - - Orange - , - } - } - /> + Default: [object Object] @@ -3238,11 +2930,7 @@ exports[`Field for select setting should render user value if there is user valu onClick={[Function]} type="button" > - + Reset to default     @@ -3382,17 +3070,7 @@ exports[`Field for string setting should render as read only with help text if o size="xs" > - - null - , - } - } - /> + Default: [object Object] @@ -3424,11 +3102,7 @@ exports[`Field for string setting should render as read only with help text if o - + This setting is overridden by the Kibana server and can not be changed. } isInvalid={false} @@ -3484,13 +3158,7 @@ exports[`Field for string setting should render custom setting icon if it is cus - } + content="Custom setting" type="asterisk" /> @@ -3626,17 +3294,7 @@ exports[`Field for string setting should render user value if there is user valu size="xs" > - - null - , - } - } - /> + Default: [object Object] @@ -3674,11 +3332,7 @@ exports[`Field for string setting should render user value if there is user valu onClick={[Function]} type="button" > - + Reset to default     diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js index e52f789eb8af7..79e4e1056200b 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js @@ -47,7 +47,6 @@ import { keyCodes, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n/react'; import { isDefaultValue } from '../../lib'; @@ -145,12 +144,9 @@ export class Field extends PureComponent { JSON.parse(newUnsavedValue); } catch (e) { isInvalid = true; - error = ( - - ); + error = i18n.translate('kbn.management.settings.field.codeEditorSyntaxErrorMessage', { + defaultMessage: 'Invalid JSON syntax', + }); } break; default: @@ -401,14 +397,11 @@ export class Field extends PureComponent { return ( - ) : ( - - ) + !!unsavedValue + ? i18n.translate('kbn.management.settings.field.onLabel', { defaultMessage: 'On' }) + : i18n.translate('kbn.management.settings.field.offLabel', { + defaultMessage: 'Off', + }) } checked={!!unsavedValue} onChange={this.onFieldChange} @@ -514,10 +507,10 @@ export class Field extends PureComponent { if (setting.isOverridden) { return ( - + {i18n.translate('kbn.management.settings.field.helpText', { + defaultMessage: + 'This setting is overridden by the Kibana server and can not be changed.', + })} ); } @@ -549,12 +542,9 @@ export class Field extends PureComponent { aria-label={i18n.translate('kbn.management.settings.field.customSettingAriaLabel', { defaultMessage: 'Custom setting', })} - content={ - - } + content={i18n.translate('kbn.management.settings.field.customSettingTooltip', { + defaultMessage: 'Custom setting', + })} /> ) : ( '' @@ -599,10 +589,9 @@ export class Field extends PureComponent { {type === 'json' ? ( - ), - }} - /> + }, + })} ) : ( - {this.getDisplayedDefaultValue(type, defVal, optionLabels)} ), - }} - /> + }, + })} )} @@ -650,10 +638,9 @@ export class Field extends PureComponent { onClick={this.resetField} data-test-subj={`advancedSetting-resetField-${name}`} > - + {i18n.translate('kbn.management.settings.field.resetToDefaultLinkText', { + defaultMessage: 'Reset to default', + })}     @@ -678,10 +665,9 @@ export class Field extends PureComponent { onClick={this.changeImage} data-test-subj={`advancedSetting-changeImage-${name}`} > - + {i18n.translate('kbn.management.settings.field.changeImageLinkText', { + defaultMessage: 'Change image', + })} ); @@ -712,10 +698,9 @@ export class Field extends PureComponent { disabled={isDisabled || isInvalid} data-test-subj={`advancedSetting-saveEditField-${name}`} > - + {i18n.translate('kbn.management.settings.field.saveButtonLabel', { + defaultMessage: 'Save', + })} @@ -733,10 +718,9 @@ export class Field extends PureComponent { disabled={isDisabled} data-test-subj={`advancedSetting-cancelEditField-${name}`} > - + {i18n.translate('kbn.management.settings.field.cancelEditingButtonLabel', { + defaultMessage: 'Cancel', + })} diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js index ddd2e3984caed..647a546d7b2f1 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js @@ -18,7 +18,7 @@ */ import React from 'react'; -import { shallowWithI18nProvider, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { mount, shallow } from 'enzyme'; import { findTestSubject } from '@elastic/eui/lib/test'; import { Field } from './field'; @@ -27,7 +27,7 @@ jest.mock('ui/notify', () => ({ toastNotifications: { addDanger: () => {}, add: jest.fn(), - } + }, })); import { toastNotifications } from 'ui/notify'; @@ -75,7 +75,7 @@ const settings = { length: 1000, displayName: '1 kB', description: 'Description for 1 kB', - } + }, }, }, json: { @@ -129,7 +129,7 @@ const settings = { apple: 'Apple', orange: 'Orange', // Deliberately left out `banana` to test if it also works with missing labels - } + }, }, string: { name: 'string:test:setting', @@ -183,21 +183,16 @@ describe('Field', () => { describe(`for ${type} setting`, () => { it('should render default value if there is no user value set', async () => { - const component = shallowWithI18nProvider( - + const component = shallow( + ); expect(component).toMatchSnapshot(); }); it('should render as read only with help text if overridden', async () => { - const component = shallowWithI18nProvider( - { }); it('should render as read only if saving is disabled', async () => { - const component = shallowWithI18nProvider( - + const component = shallow( + ); expect(component).toMatchSnapshot(); }); it('should render user value if there is user value is set', async () => { - const component = shallowWithI18nProvider( - { }); it('should render custom setting icon if it is custom', async () => { - const component = shallowWithI18nProvider( - { }); }); - if(type === 'select') { + if (type === 'select') { it('should use options for rendering values', () => { - const component = mountWithIntl( - { }); it('should use optionLabels for rendering labels', () => { - const component = mountWithIntl( - { }); } - if(type === 'image') { + if (type === 'image') { describe(`for changing ${type} setting`, () => { - const component = mountWithIntl( - + const component = mount( + ); const userValue = userValues[type]; - component.instance().getImageAsBase64 = (file) => Promise.resolve(file); + component.instance().getImageAsBase64 = file => Promise.resolve(file); it('should be able to change value from no value and cancel', async () => { await component.instance().onImageChange([userValue]); - component.update(); - findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); - expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( + 'click' + ); + expect( + component.instance().state.unsavedValue === component.instance().state.savedValue + ).toBe(true); }); it('should be able to change value and save', async () => { await component.instance().onImageChange([userValue]); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( + 'click' + ); expect(save).toBeCalled(); component.setState({ savedValue: userValue }); - await component.setProps({ setting: { - ...component.instance().props.setting, - value: userValue, - } }); + await component.setProps({ + setting: { + ...component.instance().props.setting, + value: userValue, + }, + }); await component.instance().cancelChangeImage(); component.update(); }); it('should be able to change value from existing value and save', async () => { - findTestSubject(component, `advancedSetting-changeImage-${setting.name}`).simulate('click'); + findTestSubject(component, `advancedSetting-changeImage-${setting.name}`).simulate( + 'click' + ); const newUserValue = `${userValue}=`; await component.instance().onImageChange([newUserValue]); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( + 'click' + ); expect(save).toBeCalled(); component.setState({ savedValue: newUserValue }); - await component.setProps({ setting: { - ...component.instance().props.setting, - value: newUserValue, - } }); + await component.setProps({ + setting: { + ...component.instance().props.setting, + value: newUserValue, + }, + }); component.update(); }); it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); + findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate( + 'click' + ); expect(clear).toBeCalled(); }); }); - } else if(type === 'markdown' || type === 'json') { + } else if (type === 'markdown' || type === 'json') { describe(`for changing ${type} setting`, () => { - const component = mountWithIntl( - + const component = mount( + ); const userValue = userValues[type]; @@ -367,46 +363,51 @@ describe('Field', () => { it('should be able to change value and cancel', async () => { component.instance().onCodeEditorChange(fieldUserValue); - component.update(); - findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); - expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( + 'click' + ); + expect( + component.instance().state.unsavedValue === component.instance().state.savedValue + ).toBe(true); }); it('should be able to change value and save', async () => { component.instance().onCodeEditorChange(fieldUserValue); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( + 'click' + ); expect(save).toBeCalled(); component.setState({ savedValue: fieldUserValue }); - await component.setProps({ setting: { - ...component.instance().props.setting, - value: userValue, - } }); + await component.setProps({ + setting: { + ...component.instance().props.setting, + value: userValue, + }, + }); component.update(); }); - if(type === 'json') { + if (type === 'json') { it('should be able to clear value and have empty object populate', async () => { component.instance().onCodeEditorChange(''); - component.update(); - expect(component.instance().state.unsavedValue).toEqual('{}'); + const updated = component.update(); + expect(updated.instance().state.unsavedValue).toEqual('{}'); }); } it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); + findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate( + 'click' + ); expect(clear).toBeCalled(); }); }); } else { describe(`for changing ${type} setting`, () => { - const component = mountWithIntl( - + const component = mount( + ); const userValue = userValues[type]; @@ -424,26 +425,36 @@ describe('Field', () => { it('should be able to change value and cancel', async () => { component.instance().onFieldChange({ target: { value: fieldUserValue } }); - component.update(); - findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); - expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( + 'click' + ); + expect( + component.instance().state.unsavedValue === component.instance().state.savedValue + ).toBe(true); }); it('should be able to change value and save', async () => { component.instance().onFieldChange({ target: { value: fieldUserValue } }); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( + 'click' + ); expect(save).toBeCalled(); component.setState({ savedValue: fieldUserValue }); - await component.setProps({ setting: { - ...component.instance().props.setting, - value: userValue, - } }); + await component.setProps({ + setting: { + ...component.instance().props.setting, + value: userValue, + }, + }); component.update(); }); it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); + findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate( + 'click' + ); expect(clear).toBeCalled(); }); }); @@ -455,22 +466,16 @@ describe('Field', () => { ...settings.string, requiresPageReload: true, }; - const wrapper = mountWithIntl( - - ); - wrapper.instance().onFieldChange({ target: { value: 'a new value' } }); - wrapper.update(); - findTestSubject(wrapper, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const component = mount(); + component.instance().onFieldChange({ target: { value: 'a new value' } }); + const updated = component.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toHaveBeenCalled(); await save(); expect(toastNotifications.add).toHaveBeenCalledWith( expect.objectContaining({ title: expect.stringContaining('Please reload the page'), - }), + }) ); }); }); From a453be8e288c26a078c22be261a7fc6e66e4bc75 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Fri, 4 Oct 2019 06:52:44 +0900 Subject: [PATCH 04/10] Fixed eslint error. --- .../indexed_fields_table/components/table/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index b0e38dcd4de38..4b59a096c4440 100644 --- 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 @@ -24,7 +24,7 @@ import { EuiIcon, EuiInMemoryTable, EuiIconTip } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -export class TableComponent extends PureComponent { +export class Table extends PureComponent { static propTypes = { indexPattern: PropTypes.object.isRequired, items: PropTypes.array.isRequired, From a61f529e56f78b0677edb7bcea82d538c05e431b Mon Sep 17 00:00:00 2001 From: sainthkh Date: Wed, 18 Sep 2019 11:58:11 +0900 Subject: [PATCH 05/10] Revert "Fixed Field.js and its tests." This reverts commit bc909ac791160c32581097107dad13c184fc77cb. --- .../field/__snapshots__/field.test.js.snap | 444 ++++++++++++++++-- .../settings/components/field/field.js | 90 ++-- .../settings/components/field/field.test.js | 213 ++++----- 3 files changed, 552 insertions(+), 195 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap index eb345fa8b4a04..eb8454f64e7ba 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/__snapshots__/field.test.js.snap @@ -93,7 +93,17 @@ exports[`Field for array setting should render as read only with help text if ov size="xs" > - Default: [object Object] + + default_value + , + } + } + /> @@ -125,7 +135,11 @@ exports[`Field for array setting should render as read only with help text if ov - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -181,7 +195,13 @@ exports[`Field for array setting should render custom setting icon if it is cust + } type="asterisk" /> @@ -317,7 +337,17 @@ exports[`Field for array setting should render user value if there is user value size="xs" > - Default: [object Object] + + default_value + , + } + } + /> @@ -355,7 +385,11 @@ exports[`Field for array setting should render user value if there is user value onClick={[Function]} type="button" > - Reset to default +     @@ -437,7 +471,13 @@ exports[`Field for boolean setting should render as read only if saving is disab checked={true} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={true} - label="On" + label={ + + } onChange={[Function]} onKeyDown={[Function]} /> @@ -476,7 +516,17 @@ exports[`Field for boolean setting should render as read only with help text if size="xs" > - Default: [object Object] + + true + , + } + } + /> @@ -508,7 +558,11 @@ exports[`Field for boolean setting should render as read only with help text if - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -520,7 +574,13 @@ exports[`Field for boolean setting should render as read only with help text if checked={false} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={true} - label="Off" + label={ + + } onChange={[Function]} onKeyDown={[Function]} /> @@ -562,7 +622,13 @@ exports[`Field for boolean setting should render custom setting icon if it is cu + } type="asterisk" /> @@ -590,7 +656,13 @@ exports[`Field for boolean setting should render custom setting icon if it is cu checked={true} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={false} - label="On" + label={ + + } onChange={[Function]} onKeyDown={[Function]} /> @@ -655,7 +727,13 @@ exports[`Field for boolean setting should render default value if there is no us checked={true} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={false} - label="On" + label={ + + } onChange={[Function]} onKeyDown={[Function]} /> @@ -694,7 +772,17 @@ exports[`Field for boolean setting should render user value if there is user val size="xs" > - Default: [object Object] + + true + , + } + } + /> @@ -732,7 +820,11 @@ exports[`Field for boolean setting should render user value if there is user val onClick={[Function]} type="button" > - Reset to default +     @@ -747,7 +839,13 @@ exports[`Field for boolean setting should render user value if there is user val checked={false} data-test-subj="advancedSetting-editField-boolean:test:setting" disabled={false} - label="Off" + label={ + + } onChange={[Function]} onKeyDown={[Function]} /> @@ -852,7 +950,17 @@ exports[`Field for image setting should render as read only with help text if ov size="xs" > - Default: [object Object] + + null + , + } + } + /> @@ -884,7 +992,11 @@ exports[`Field for image setting should render as read only with help text if ov - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -935,7 +1047,13 @@ exports[`Field for image setting should render custom setting icon if it is cust + } type="asterisk" /> @@ -1069,7 +1187,17 @@ exports[`Field for image setting should render user value if there is user value size="xs" > - Default: [object Object] + + null + , + } + } + /> @@ -1107,7 +1235,11 @@ exports[`Field for image setting should render user value if there is user value onClick={[Function]} type="button" > - Reset to default +     @@ -1119,7 +1251,11 @@ exports[`Field for image setting should render user value if there is user value onClick={[Function]} type="button" > - Change image + @@ -1169,7 +1305,21 @@ exports[`Field for json setting should render as read only if saving is disabled size="xs" > - Default: [object Object] + + {} + , + } + } + /> @@ -1265,7 +1415,21 @@ exports[`Field for json setting should render as read only with help text if ove size="xs" > - Default: [object Object] + + {} + , + } + } + /> @@ -1297,7 +1461,11 @@ exports[`Field for json setting should render as read only with help text if ove - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -1370,7 +1538,13 @@ exports[`Field for json setting should render custom setting icon if it is custo + } type="asterisk" /> @@ -1456,7 +1630,21 @@ exports[`Field for json setting should render default value if there is no user size="xs" > - Default: [object Object] + + {} + , + } + } + /> @@ -1494,7 +1682,11 @@ exports[`Field for json setting should render default value if there is no user onClick={[Function]} type="button" > - Reset to default +     @@ -1567,7 +1759,21 @@ exports[`Field for json setting should render user value if there is user value size="xs" > - Default: [object Object] + + {} + , + } + } + /> @@ -1605,7 +1811,11 @@ exports[`Field for json setting should render user value if there is user value onClick={[Function]} type="button" > - Reset to default +     @@ -1762,7 +1972,17 @@ exports[`Field for markdown setting should render as read only with help text if size="xs" > - Default: [object Object] + + null + , + } + } + /> @@ -1794,7 +2014,11 @@ exports[`Field for markdown setting should render as read only with help text if - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -1867,7 +2091,13 @@ exports[`Field for markdown setting should render custom setting icon if it is c + } type="asterisk" /> @@ -2037,7 +2267,17 @@ exports[`Field for markdown setting should render user value if there is user va size="xs" > - Default: [object Object] + + null + , + } + } + /> @@ -2075,7 +2315,11 @@ exports[`Field for markdown setting should render user value if there is user va onClick={[Function]} type="button" > - Reset to default +     @@ -2215,7 +2459,17 @@ exports[`Field for number setting should render as read only with help text if o size="xs" > - Default: [object Object] + + 5 + , + } + } + /> @@ -2247,7 +2501,11 @@ exports[`Field for number setting should render as read only with help text if o - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -2303,7 +2561,13 @@ exports[`Field for number setting should render custom setting icon if it is cus + } type="asterisk" /> @@ -2439,7 +2703,17 @@ exports[`Field for number setting should render user value if there is user valu size="xs" > - Default: [object Object] + + 5 + , + } + } + /> @@ -2477,7 +2751,11 @@ exports[`Field for number setting should render user value if there is user valu onClick={[Function]} type="button" > - Reset to default +     @@ -2617,7 +2895,17 @@ exports[`Field for select setting should render as read only with help text if o size="xs" > - Default: [object Object] + + Orange + , + } + } + /> @@ -2649,7 +2937,11 @@ exports[`Field for select setting should render as read only with help text if o - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -2722,7 +3014,13 @@ exports[`Field for select setting should render custom setting icon if it is cus + } type="asterisk" /> @@ -2892,7 +3190,17 @@ exports[`Field for select setting should render user value if there is user valu size="xs" > - Default: [object Object] + + Orange + , + } + } + /> @@ -2930,7 +3238,11 @@ exports[`Field for select setting should render user value if there is user valu onClick={[Function]} type="button" > - Reset to default +     @@ -3070,7 +3382,17 @@ exports[`Field for string setting should render as read only with help text if o size="xs" > - Default: [object Object] + + null + , + } + } + /> @@ -3102,7 +3424,11 @@ exports[`Field for string setting should render as read only with help text if o - This setting is overridden by the Kibana server and can not be changed. + } isInvalid={false} @@ -3158,7 +3484,13 @@ exports[`Field for string setting should render custom setting icon if it is cus + } type="asterisk" /> @@ -3294,7 +3626,17 @@ exports[`Field for string setting should render user value if there is user valu size="xs" > - Default: [object Object] + + null + , + } + } + /> @@ -3332,7 +3674,11 @@ exports[`Field for string setting should render user value if there is user valu onClick={[Function]} type="button" > - Reset to default +     diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js index 79e4e1056200b..e52f789eb8af7 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.js @@ -47,6 +47,7 @@ import { keyCodes, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import { isDefaultValue } from '../../lib'; @@ -144,9 +145,12 @@ export class Field extends PureComponent { JSON.parse(newUnsavedValue); } catch (e) { isInvalid = true; - error = i18n.translate('kbn.management.settings.field.codeEditorSyntaxErrorMessage', { - defaultMessage: 'Invalid JSON syntax', - }); + error = ( + + ); } break; default: @@ -397,11 +401,14 @@ export class Field extends PureComponent { return ( + ) : ( + + ) } checked={!!unsavedValue} onChange={this.onFieldChange} @@ -507,10 +514,10 @@ export class Field extends PureComponent { if (setting.isOverridden) { return ( - {i18n.translate('kbn.management.settings.field.helpText', { - defaultMessage: - 'This setting is overridden by the Kibana server and can not be changed.', - })} + ); } @@ -542,9 +549,12 @@ export class Field extends PureComponent { aria-label={i18n.translate('kbn.management.settings.field.customSettingAriaLabel', { defaultMessage: 'Custom setting', })} - content={i18n.translate('kbn.management.settings.field.customSettingTooltip', { - defaultMessage: 'Custom setting', - })} + content={ + + } /> ) : ( '' @@ -589,9 +599,10 @@ export class Field extends PureComponent { {type === 'json' ? ( - {i18n.translate('kbn.management.settings.field.defaultValueTypeJsonText', { - defaultMessage: 'Default: {value}', - values: { + ), - }, - })} + }} + /> ) : ( - {i18n.translate('kbn.management.settings.field.defaultValueText', { - defaultMessage: 'Default: {value}', - values: { + {this.getDisplayedDefaultValue(type, defVal, optionLabels)} ), - }, - })} + }} + /> )} @@ -638,9 +650,10 @@ export class Field extends PureComponent { onClick={this.resetField} data-test-subj={`advancedSetting-resetField-${name}`} > - {i18n.translate('kbn.management.settings.field.resetToDefaultLinkText', { - defaultMessage: 'Reset to default', - })} +     @@ -665,9 +678,10 @@ export class Field extends PureComponent { onClick={this.changeImage} data-test-subj={`advancedSetting-changeImage-${name}`} > - {i18n.translate('kbn.management.settings.field.changeImageLinkText', { - defaultMessage: 'Change image', - })} + ); @@ -698,9 +712,10 @@ export class Field extends PureComponent { disabled={isDisabled || isInvalid} data-test-subj={`advancedSetting-saveEditField-${name}`} > - {i18n.translate('kbn.management.settings.field.saveButtonLabel', { - defaultMessage: 'Save', - })} + @@ -718,9 +733,10 @@ export class Field extends PureComponent { disabled={isDisabled} data-test-subj={`advancedSetting-cancelEditField-${name}`} > - {i18n.translate('kbn.management.settings.field.cancelEditingButtonLabel', { - defaultMessage: 'Cancel', - })} + diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js index 647a546d7b2f1..ddd2e3984caed 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js @@ -18,7 +18,7 @@ */ import React from 'react'; -import { mount, shallow } from 'enzyme'; +import { shallowWithI18nProvider, mountWithIntl } from 'test_utils/enzyme_helpers'; import { findTestSubject } from '@elastic/eui/lib/test'; import { Field } from './field'; @@ -27,7 +27,7 @@ jest.mock('ui/notify', () => ({ toastNotifications: { addDanger: () => {}, add: jest.fn(), - }, + } })); import { toastNotifications } from 'ui/notify'; @@ -75,7 +75,7 @@ const settings = { length: 1000, displayName: '1 kB', description: 'Description for 1 kB', - }, + } }, }, json: { @@ -129,7 +129,7 @@ const settings = { apple: 'Apple', orange: 'Orange', // Deliberately left out `banana` to test if it also works with missing labels - }, + } }, string: { name: 'string:test:setting', @@ -183,16 +183,21 @@ describe('Field', () => { describe(`for ${type} setting`, () => { it('should render default value if there is no user value set', async () => { - const component = shallow( - + const component = shallowWithI18nProvider( + ); expect(component).toMatchSnapshot(); }); it('should render as read only with help text if overridden', async () => { - const component = shallow( - { }); it('should render as read only if saving is disabled', async () => { - const component = shallow( - + const component = shallowWithI18nProvider( + ); expect(component).toMatchSnapshot(); }); it('should render user value if there is user value is set', async () => { - const component = shallow( - { }); it('should render custom setting icon if it is custom', async () => { - const component = shallow( - { }); }); - if (type === 'select') { + if(type === 'select') { it('should use options for rendering values', () => { - const component = mount( - { }); it('should use optionLabels for rendering labels', () => { - const component = mount( - { }); } - if (type === 'image') { + if(type === 'image') { describe(`for changing ${type} setting`, () => { - const component = mount( - + const component = mountWithIntl( + ); const userValue = userValues[type]; - component.instance().getImageAsBase64 = file => Promise.resolve(file); + component.instance().getImageAsBase64 = (file) => Promise.resolve(file); it('should be able to change value from no value and cancel', async () => { await component.instance().onImageChange([userValue]); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( - 'click' - ); - expect( - component.instance().state.unsavedValue === component.instance().state.savedValue - ).toBe(true); + component.update(); + findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); + expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); }); it('should be able to change value and save', async () => { await component.instance().onImageChange([userValue]); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( - 'click' - ); + component.update(); + findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: userValue }); - await component.setProps({ - setting: { - ...component.instance().props.setting, - value: userValue, - }, - }); + await component.setProps({ setting: { + ...component.instance().props.setting, + value: userValue, + } }); await component.instance().cancelChangeImage(); component.update(); }); it('should be able to change value from existing value and save', async () => { - findTestSubject(component, `advancedSetting-changeImage-${setting.name}`).simulate( - 'click' - ); + findTestSubject(component, `advancedSetting-changeImage-${setting.name}`).simulate('click'); const newUserValue = `${userValue}=`; await component.instance().onImageChange([newUserValue]); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( - 'click' - ); + component.update(); + findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: newUserValue }); - await component.setProps({ - setting: { - ...component.instance().props.setting, - value: newUserValue, - }, - }); + await component.setProps({ setting: { + ...component.instance().props.setting, + value: newUserValue, + } }); component.update(); }); it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate( - 'click' - ); + findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); expect(clear).toBeCalled(); }); }); - } else if (type === 'markdown' || type === 'json') { + } else if(type === 'markdown' || type === 'json') { describe(`for changing ${type} setting`, () => { - const component = mount( - + const component = mountWithIntl( + ); const userValue = userValues[type]; @@ -363,51 +367,46 @@ describe('Field', () => { it('should be able to change value and cancel', async () => { component.instance().onCodeEditorChange(fieldUserValue); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( - 'click' - ); - expect( - component.instance().state.unsavedValue === component.instance().state.savedValue - ).toBe(true); + component.update(); + findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); + expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); }); it('should be able to change value and save', async () => { component.instance().onCodeEditorChange(fieldUserValue); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( - 'click' - ); + component.update(); + findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: fieldUserValue }); - await component.setProps({ - setting: { - ...component.instance().props.setting, - value: userValue, - }, - }); + await component.setProps({ setting: { + ...component.instance().props.setting, + value: userValue, + } }); component.update(); }); - if (type === 'json') { + if(type === 'json') { it('should be able to clear value and have empty object populate', async () => { component.instance().onCodeEditorChange(''); - const updated = component.update(); - expect(updated.instance().state.unsavedValue).toEqual('{}'); + component.update(); + expect(component.instance().state.unsavedValue).toEqual('{}'); }); } it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate( - 'click' - ); + findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); expect(clear).toBeCalled(); }); }); } else { describe(`for changing ${type} setting`, () => { - const component = mount( - + const component = mountWithIntl( + ); const userValue = userValues[type]; @@ -425,36 +424,26 @@ describe('Field', () => { it('should be able to change value and cancel', async () => { component.instance().onFieldChange({ target: { value: fieldUserValue } }); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate( - 'click' - ); - expect( - component.instance().state.unsavedValue === component.instance().state.savedValue - ).toBe(true); + component.update(); + findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); + expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); }); it('should be able to change value and save', async () => { component.instance().onFieldChange({ target: { value: fieldUserValue } }); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate( - 'click' - ); + component.update(); + findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: fieldUserValue }); - await component.setProps({ - setting: { - ...component.instance().props.setting, - value: userValue, - }, - }); + await component.setProps({ setting: { + ...component.instance().props.setting, + value: userValue, + } }); component.update(); }); it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate( - 'click' - ); + findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); expect(clear).toBeCalled(); }); }); @@ -466,16 +455,22 @@ describe('Field', () => { ...settings.string, requiresPageReload: true, }; - const component = mount(); - component.instance().onFieldChange({ target: { value: 'a new value' } }); - const updated = component.update(); - findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const wrapper = mountWithIntl( + + ); + wrapper.instance().onFieldChange({ target: { value: 'a new value' } }); + wrapper.update(); + findTestSubject(wrapper, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toHaveBeenCalled(); await save(); expect(toastNotifications.add).toHaveBeenCalledWith( expect.objectContaining({ title: expect.stringContaining('Please reload the page'), - }) + }), ); }); }); From 9be6d6948c92fda0fb7fdec551fa9d66064eefd1 Mon Sep 17 00:00:00 2001 From: sainthkh Date: Fri, 4 Oct 2019 08:11:18 +0900 Subject: [PATCH 06/10] Fixed simple tests. --- .../settings/components/field/field.test.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js index ddd2e3984caed..83e6a821753c9 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js @@ -18,7 +18,9 @@ */ import React from 'react'; -import { shallowWithI18nProvider, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { I18nProvider } from '@kbn/i18n/react'; +import { shallowWithI18nProvider, mountWithI18nProvider, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { mount } from 'enzyme'; import { findTestSubject } from '@elastic/eui/lib/test'; import { Field } from './field'; @@ -184,7 +186,7 @@ describe('Field', () => { describe(`for ${type} setting`, () => { it('should render default value if there is no user value set', async () => { const component = shallowWithI18nProvider( - { it('should render as read only with help text if overridden', async () => { const component = shallowWithI18nProvider( - { it('should render as read only if saving is disabled', async () => { const component = shallowWithI18nProvider( - { it('should render user value if there is user value is set', async () => { const component = shallowWithI18nProvider( - { it('should render custom setting icon if it is custom', async () => { const component = shallowWithI18nProvider( - { if(type === 'select') { it('should use options for rendering values', () => { - const component = mountWithIntl( - { }); it('should use optionLabels for rendering labels', () => { - const component = mountWithIntl( - { ...settings.string, requiresPageReload: true, }; - const wrapper = mountWithIntl( - ); wrapper.instance().onFieldChange({ target: { value: 'a new value' } }); - wrapper.update(); - findTestSubject(wrapper, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toHaveBeenCalled(); await save(); expect(toastNotifications.add).toHaveBeenCalledWith( From b6f0f77218109582481501280ab8011cd2120a8f Mon Sep 17 00:00:00 2001 From: sainthkh Date: Fri, 4 Oct 2019 08:28:07 +0900 Subject: [PATCH 07/10] Fixed other tests. --- .../settings/components/field/field.test.js | 108 +++++++++--------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js index 83e6a821753c9..f95332680437b 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/settings/components/field/field.test.js @@ -19,7 +19,7 @@ import React from 'react'; import { I18nProvider } from '@kbn/i18n/react'; -import { shallowWithI18nProvider, mountWithI18nProvider, mountWithIntl } from 'test_utils/enzyme_helpers'; +import { shallowWithI18nProvider, mountWithI18nProvider } from 'test_utils/enzyme_helpers'; import { mount } from 'enzyme'; import { findTestSubject } from '@elastic/eui/lib/test'; @@ -296,121 +296,121 @@ describe('Field', () => { }); } - if(type === 'image') { - describe(`for changing ${type} setting`, () => { - const component = mountWithIntl( - { + const Wrapper = (props) => ( + + - ); + + ); + const wrapper = mount(); + const component = wrapper.find(I18nProvider).find(Field); + + return { + wrapper, + component, + }; + }; + if(type === 'image') { + describe(`for changing ${type} setting`, () => { + const { wrapper, component } = setup(); const userValue = userValues[type]; component.instance().getImageAsBase64 = (file) => Promise.resolve(file); it('should be able to change value from no value and cancel', async () => { await component.instance().onImageChange([userValue]); - component.update(); - findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); }); it('should be able to change value and save', async () => { await component.instance().onImageChange([userValue]); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: userValue }); - await component.setProps({ setting: { + await wrapper.setProps({ setting: { ...component.instance().props.setting, value: userValue, } }); await component.instance().cancelChangeImage(); - component.update(); + wrapper.update(); }); it('should be able to change value from existing value and save', async () => { - findTestSubject(component, `advancedSetting-changeImage-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-changeImage-${setting.name}`).simulate('click'); const newUserValue = `${userValue}=`; await component.instance().onImageChange([newUserValue]); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated2 = wrapper.update(); + findTestSubject(updated2, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: newUserValue }); - await component.setProps({ setting: { + await wrapper.setProps({ setting: { ...component.instance().props.setting, value: newUserValue, } }); - component.update(); + wrapper.update(); }); it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-resetField-${setting.name}`).simulate('click'); expect(clear).toBeCalled(); }); }); } else if(type === 'markdown' || type === 'json') { describe(`for changing ${type} setting`, () => { - const component = mountWithIntl( - - ); - + const { wrapper, component } = setup(); const userValue = userValues[type]; const fieldUserValue = userValue; it('should be able to change value and cancel', async () => { component.instance().onCodeEditorChange(fieldUserValue); - component.update(); - findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); }); it('should be able to change value and save', async () => { component.instance().onCodeEditorChange(fieldUserValue); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: fieldUserValue }); - await component.setProps({ setting: { + await wrapper.setProps({ setting: { ...component.instance().props.setting, value: userValue, } }); - component.update(); + wrapper.update(); }); if(type === 'json') { it('should be able to clear value and have empty object populate', async () => { component.instance().onCodeEditorChange(''); - component.update(); + wrapper.update(); expect(component.instance().state.unsavedValue).toEqual('{}'); }); } it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-resetField-${setting.name}`).simulate('click'); expect(clear).toBeCalled(); }); }); } else { describe(`for changing ${type} setting`, () => { - const component = mountWithIntl( - - ); - + const { wrapper, component } = setup(); const userValue = userValues[type]; const fieldUserValue = type === 'array' ? userValue.join(', ') : userValue; @@ -418,34 +418,35 @@ describe('Field', () => { const invalidUserValue = invalidUserValues[type]; it('should display an error when validation fails', async () => { component.instance().onFieldChange({ target: { value: invalidUserValue } }); - component.update(); - const errorMessage = component.find('.euiFormErrorText').text(); + const updated = wrapper.update(); + const errorMessage = updated.find('.euiFormErrorText').text(); expect(errorMessage).toEqual(setting.validation.message); }); } it('should be able to change value and cancel', async () => { component.instance().onFieldChange({ target: { value: fieldUserValue } }); - component.update(); - findTestSubject(component, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-cancelEditField-${setting.name}`).simulate('click'); expect(component.instance().state.unsavedValue === component.instance().state.savedValue).toBe(true); }); it('should be able to change value and save', async () => { component.instance().onFieldChange({ target: { value: fieldUserValue } }); - component.update(); - findTestSubject(component, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-saveEditField-${setting.name}`).simulate('click'); expect(save).toBeCalled(); component.setState({ savedValue: fieldUserValue }); - await component.setProps({ setting: { + await wrapper.setProps({ setting: { ...component.instance().props.setting, value: userValue, } }); - component.update(); + wrapper.update(); }); it('should be able to reset to default value', async () => { - findTestSubject(component, `advancedSetting-resetField-${setting.name}`).simulate('click'); + const updated = wrapper.update(); + findTestSubject(updated, `advancedSetting-resetField-${setting.name}`).simulate('click'); expect(clear).toBeCalled(); }); }); @@ -462,6 +463,7 @@ describe('Field', () => { setting={setting} save={save} clear={clear} + enableSaving={true} /> ); wrapper.instance().onFieldChange({ target: { value: 'a new value' } }); From 26eadbe4bb791fad009173aff0a89b54cf52e4ca Mon Sep 17 00:00:00 2001 From: sainthkh Date: Fri, 4 Oct 2019 08:31:43 +0900 Subject: [PATCH 08/10] Fixed x-pack snapshot error. --- .../public/components/__snapshots__/telemetry_form.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/legacy/plugins/telemetry/public/components/__snapshots__/telemetry_form.test.js.snap b/x-pack/legacy/plugins/telemetry/public/components/__snapshots__/telemetry_form.test.js.snap index 06becfdda57d0..5bc88f425118b 100644 --- a/x-pack/legacy/plugins/telemetry/public/components/__snapshots__/telemetry_form.test.js.snap +++ b/x-pack/legacy/plugins/telemetry/public/components/__snapshots__/telemetry_form.test.js.snap @@ -26,7 +26,7 @@ exports[`TelemetryForm renders as expected 1`] = ` - Date: Thu, 3 Oct 2019 21:41:48 -0500 Subject: [PATCH 09/10] TableComponent to Table --- .../components/table/__jest__/table.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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/__jest__/table.test.js index 01e1030d5e517..84acc2c085b13 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/__jest__/table.test.js @@ -21,7 +21,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers'; -import { TableComponent } from '../table'; +import { Table } from '../table'; const indexPattern = { timeFieldName: 'timestamp' @@ -36,7 +36,7 @@ const items = [ describe('Table', () => { it('should render normally', async () => { const component = shallowWithI18nProvider( - {}} @@ -48,7 +48,7 @@ describe('Table', () => { it('should render normal field name', async () => { const component = shallowWithI18nProvider( - {}} @@ -61,7 +61,7 @@ describe('Table', () => { it('should render timestamp field name', async () => { const component = shallowWithI18nProvider( - {}} @@ -74,7 +74,7 @@ describe('Table', () => { it('should render the boolean template (true)', async () => { const component = shallowWithI18nProvider( - {}} @@ -87,7 +87,7 @@ describe('Table', () => { it('should render the boolean template (false)', async () => { const component = shallowWithI18nProvider( - {}} @@ -100,7 +100,7 @@ describe('Table', () => { it('should render normal type', async () => { const component = shallowWithI18nProvider( - {}} @@ -113,7 +113,7 @@ describe('Table', () => { it('should render conflicting type', async () => { const component = shallowWithI18nProvider( - {}} @@ -128,7 +128,7 @@ describe('Table', () => { const editField = jest.fn(); const component = shallowWithI18nProvider( - Date: Tue, 8 Oct 2019 10:34:12 +0900 Subject: [PATCH 10/10] Fixed eslint error. --- .../components/objects_table/__jest__/objects_table.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/objects_table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/objects_table.test.js index e5ed9089d66eb..7cf3f935ec4b5 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/objects_table.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/objects/components/objects_table/__jest__/objects_table.test.js @@ -318,8 +318,8 @@ describe('ObjectsTable', () => { it('should export all, accounting for the current search criteria', async () => { const { fetchExportByTypeAndSearch } = require('../../../lib/fetch_export_by_type_and_search'); const { saveAs } = require('@elastic/filesaver'); - const component = shallowWithIntl( - );