From 7b8f6ba837ae76735c5eecd817f9e61afaea4391 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 12 Jun 2019 05:41:30 -0700 Subject: [PATCH] Convert ILM from using intl.formatMessage to i18n.translate. (#38747) --- .../sections/components/learn_more_link.js | 8 +-- .../components/cold_phase/cold_phase.js | 20 +++--- .../components/hot_phase/hot_phase.js | 45 +++++------- .../edit_policy/components/min_age_input.js | 69 ++++++++----------- .../node_allocation/node_allocation.js | 19 ++--- .../node_attrs_details/node_attrs_details.js | 25 +++---- .../components/policy_json_flyout.js | 19 +++-- .../components/warm_phase/warm_phase.js | 37 +++++----- .../sections/edit_policy/edit_policy.js | 34 ++++----- .../add_policy_to_template_confirm_modal.js | 66 +++++++++++------- .../components/policy_table/confirm_delete.js | 29 ++++---- .../components/policy_table/policy_table.js | 64 ++++++++--------- 12 files changed, 204 insertions(+), 231 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/public/sections/components/learn_more_link.js b/x-pack/plugins/index_lifecycle_management/public/sections/components/learn_more_link.js index 420ca972c222..c7ca71a78d5d 100644 --- a/x-pack/plugins/index_lifecycle_management/public/sections/components/learn_more_link.js +++ b/x-pack/plugins/index_lifecycle_management/public/sections/components/learn_more_link.js @@ -7,11 +7,11 @@ import React from 'react'; import { EuiLink } from '@elastic/eui'; import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; + const esBase = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/${DOC_LINK_VERSION}/`; - -export class LearnMoreLinkUi extends React.PureComponent { +export class LearnMoreLink extends React.PureComponent { render() { const { href, docPath, text } = this.props; let url; @@ -31,7 +31,5 @@ export class LearnMoreLinkUi extends React.PureComponent { {content} ); - } } -export const LearnMoreLink = injectI18n(LearnMoreLinkUi); diff --git a/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/cold_phase/cold_phase.js b/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/cold_phase/cold_phase.js index c95ef1ee75d4..493da3e19b9f 100644 --- a/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/cold_phase/cold_phase.js +++ b/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/cold_phase/cold_phase.js @@ -6,7 +6,8 @@ import React, { PureComponent, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import { EuiFlexGroup, @@ -17,19 +18,20 @@ import { EuiSwitch, EuiTextColor, } from '@elastic/eui'; + import { PHASE_COLD, PHASE_ENABLED, PHASE_REPLICA_COUNT, PHASE_FREEZE_ENABLED } from '../../../../constants'; +import { LearnMoreLink, ActiveBadge, PhaseErrorMessage, OptionalLabel } from '../../../components'; import { ErrableFormRow } from '../../form_errors'; import { MinAgeInput } from '../min_age_input'; -import { LearnMoreLink, ActiveBadge, PhaseErrorMessage, OptionalLabel } from '../../../components'; import { NodeAllocation } from '../node_allocation'; import { SetPriorityInput } from '../set_priority_input'; -class ColdPhaseUi extends PureComponent { +export class ColdPhase extends PureComponent { static propTypes = { setPhaseData: PropTypes.func.isRequired, showNodeDetailsFlyout: PropTypes.func.isRequired, @@ -44,13 +46,13 @@ class ColdPhaseUi extends PureComponent { phaseData, errors, isShowingErrors, - intl, hotPhaseRolloverEnabled } = this.props; - const freezeLabel = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.coldPhase.freezeIndexLabel', - defaultMessage: 'Freeze index', + + const freezeLabel = i18n.translate('xpack.indexLifecycleMgmt.coldPhase.freezeIndexLabel', { + defaultMessage: 'Freeze index' }); + return (
@@ -124,8 +123,7 @@ class HotPhaseUi extends PureComponent { { - const { rolloverEnabled, errors, phaseData, phase, setPhaseData, isShowingErrors, intl } = props; + +export const MinAgeInput = props => { + const { rolloverEnabled, errors, phaseData, phase, setPhaseData, isShowingErrors } = props; + const fromMessage = rolloverEnabled - ? intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.editPolicy.fromRolloverMessage', - defaultMessage: 'from rollover', + ? i18n.translate('xpack.indexLifecycleMgmt.editPolicy.fromRolloverMessage', { + defaultMessage: 'from rollover' }) - : intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.editPolicy.fromIndexCreationMessage', - defaultMessage: 'from index creation', + : i18n.translate('xpack.indexLifecycleMgmt.editPolicy.fromIndexCreationMessage', { + defaultMessage: 'from index creation' }); + return ( { setPhaseData(PHASE_ROLLOVER_MINIMUM_AGE_UNITS, e.target.value)} options={[ { value: 'd', - text: intl.formatMessage( - { - id: 'xpack.indexLifecycleMgmt.editPolicy.daysLabel', - defaultMessage: 'days {fromMessage}', - }, - { + text: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.daysLabel', { + defaultMessage: 'days {fromMessage}', + values: { fromMessage, } - ), + }), }, { value: 'h', - text: intl.formatMessage( - { - id: 'xpack.indexLifecycleMgmt.editPolicy.hoursLabel', - defaultMessage: 'hours {fromMessage}', - }, - { + text: i18n.translate('xpack.indexLifecycleMgmt.editPolicy.hoursLabel', { + defaultMessage: 'hours {fromMessage}', + values: { fromMessage, } - ), + }), }, ]} /> @@ -112,4 +104,3 @@ const MinAgeInputUi = props => { ); }; -export const MinAgeInput = injectI18n(MinAgeInputUi); diff --git a/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/node_allocation/node_allocation.js b/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/node_allocation/node_allocation.js index 0a0f3bf9d35a..778386e26a56 100644 --- a/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/node_allocation/node_allocation.js +++ b/x-pack/plugins/index_lifecycle_management/public/sections/edit_policy/components/node_allocation/node_allocation.js @@ -5,11 +5,14 @@ */ import React, { Component, Fragment } from 'react'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import { EuiSelect, EuiButtonEmpty, EuiCallOut, EuiSpacer, EuiLoadingSpinner } from '@elastic/eui'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; + import { PHASE_NODE_ATTRS } from '../../../../constants'; -import { ErrableFormRow } from '../../form_errors'; import { LearnMoreLink } from '../../../components/learn_more_link'; +import { ErrableFormRow } from '../../form_errors'; + const learnMoreLinks = ( @@ -25,15 +28,16 @@ const learnMoreLinks = ( /> ); -class NodeAllocationUi extends Component { + +export class NodeAllocation extends Component { componentDidMount() { this.props.fetchNodes(); } + render() { const { phase, setPhaseData, - intl, isShowingErrors, phaseData, showNodeDetailsFlyout, @@ -72,13 +76,13 @@ class NodeAllocationUi extends Component { ); } + return ( @@ -51,17 +51,14 @@ export class NodeAttrsDetailsUi extends PureComponent { { - const { intl } = this.props; this.setState({ isShowingErrors: true }); const { saveLifecyclePolicy, lifecycle, saveAsNewPolicy, firstError } = this.props; if (firstError) { toastNotifications.addDanger( - intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.editPolicy.formErrorsMessage', - defaultMessage: 'Please fix the errors on this page.', + i18n.translate('xpack.indexLifecycleMgmt.editPolicy.formErrorsMessage', { + defaultMessage: 'Please fix the errors on this page.' }) ); const errorRowId = `${firstError.replace('.', '-')}-row`; @@ -136,7 +135,6 @@ class EditPolicyUi extends Component { }; render() { const { - intl, selectedPolicy, errors, setSaveAsNewPolicy, @@ -160,17 +158,13 @@ class EditPolicyUi extends Component {

{isNewPolicy - ? intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.editPolicy.createPolicyMessage', - defaultMessage: 'Create an index lifecycle policy', + ? i18n.translate('xpack.indexLifecycleMgmt.editPolicy.createPolicyMessage', { + defaultMessage: 'Create an index lifecycle policy' }) - : intl.formatMessage( - { - id: 'xpack.indexLifecycleMgmt.editPolicy.editPolicyMessage', - defaultMessage: 'Edit index lifecycle policy {originalPolicyName}', - }, - { originalPolicyName } - )} + : i18n.translate('xpack.indexLifecycleMgmt.editPolicy.editPolicyMessage', { + defaultMessage: 'Edit index lifecycle policy {originalPolicyName}', + values: { originalPolicyName } + })}

@@ -255,9 +249,8 @@ class EditPolicyUi extends Component { > { - const { intl, policy, callback, onCancel } = this.props; + const { policy, callback, onCancel } = this.props; const { templateName, aliasName } = this.state; const policyName = policy.name; if (!templateName) { @@ -47,17 +49,23 @@ export class AddPolicyToTemplateConfirmModalUi extends Component { templateName, aliasName }); - const message = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.successMessage', - defaultMessage: 'Added policy {policyName} to index template {templateName}', - }, { policyName, templateName }); + const message = i18n.translate( + 'xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.successMessage', + { + defaultMessage: 'Added policy {policyName} to index template {templateName}', + values: { policyName, templateName } + } + ); toastNotifications.addSuccess(message); onCancel(); } catch (e) { - const title = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.errorMessage', - defaultMessage: 'Error adding policy "{policyName}" to index template {templateName}', - }, { policyName, templateName }); + const title = i18n.translate( + 'xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.errorMessage', + { + defaultMessage: 'Error adding policy "{policyName}" to index template {templateName}', + values: { policyName, templateName } + } + ); showApiError(e, title); } if (callback) { @@ -168,25 +176,32 @@ export class AddPolicyToTemplateConfirmModalUi extends Component { ); }; render() { - const { intl, policy, onCancel } = this.props; - const title = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.title', - defaultMessage: 'Add policy "{name}" to index template', - }, { name: policy.name }); + const { policy, onCancel } = this.props; + const title = i18n.translate( + 'xpack.indexLifecycleMgmt.policyTable.addLifecyclePolicyToTemplateConfirmModal.title', + { + defaultMessage: 'Add policy "{name}" to index template', + values: { name: policy.name } + } + ); return ( @@ -213,4 +228,3 @@ export class AddPolicyToTemplateConfirmModalUi extends Component { ); } } -export const AddPolicyToTemplateConfirmModal = injectI18n(AddPolicyToTemplateConfirmModalUi); diff --git a/x-pack/plugins/index_lifecycle_management/public/sections/policy_table/components/policy_table/confirm_delete.js b/x-pack/plugins/index_lifecycle_management/public/sections/policy_table/components/policy_table/confirm_delete.js index cdaf60d1f829..595ef13e7e69 100644 --- a/x-pack/plugins/index_lifecycle_management/public/sections/policy_table/components/policy_table/confirm_delete.js +++ b/x-pack/plugins/index_lifecycle_management/public/sections/policy_table/components/policy_table/confirm_delete.js @@ -5,28 +5,30 @@ */ import React, { Component } from 'react'; -import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiOverlayMask, EuiConfirmModal } from '@elastic/eui'; import { toastNotifications } from 'ui/notify'; import { deletePolicy } from '../../../../services/api'; import { showApiError } from '../../../../services/api_errors'; -export class ConfirmDeleteUi extends Component { + +export class ConfirmDelete extends Component { deletePolicy = async () => { - const { intl, policyToDelete, callback } = this.props; + const { policyToDelete, callback } = this.props; const policyName = policyToDelete.name; try { await deletePolicy(policyName); - const message = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.confirmDelete.successMessage', + const message = i18n.translate('xpack.indexLifecycleMgmt.confirmDelete.successMessage', { defaultMessage: 'Deleted policy {policyName}', - }, { policyName }); + values: { policyName } + }); toastNotifications.addSuccess(message); } catch (e) { - const title = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.confirmDelete.errorMessage', + const title = i18n.translate('xpack.indexLifecycleMgmt.confirmDelete.errorMessage', { defaultMessage: 'Error deleting policy {policyName}', - }, { policyName }); + values: { policyName } + }); showApiError(e, title); } if (callback) { @@ -34,11 +36,11 @@ export class ConfirmDeleteUi extends Component { } }; render() { - const { intl, policyToDelete, onCancel } = this.props; - const title = intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.confirmDelete.title', + const { policyToDelete, onCancel } = this.props; + const title = i18n.translate('xpack.indexLifecycleMgmt.confirmDelete.title', { defaultMessage: 'Delete policy "{name}"', - }, { name: policyToDelete.name }); + values: { name: policyToDelete.name } + }); return ( { const value = policy[fieldName]; @@ -320,9 +316,8 @@ export class PolicyTableUi extends Component { onClick={() => this.togglePolicyPopover(policy)} color="primary" > - {intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.policyTable.actionsButtonText', - defaultMessage: 'Actions', + {i18n.translate('xpack.indexLifecycleMgmt.policyTable.actionsButtonText', { + defaultMessage: 'Actions' })} ); @@ -382,7 +377,6 @@ export class PolicyTableUi extends Component { totalNumberOfPolicies, policyFilterChanged, filter, - intl, policyListLoaded, } = this.props; const { selectedPoliciesMap } = this.state; @@ -428,14 +422,18 @@ export class PolicyTableUi extends Component { policyFilterChanged(event.target.value); }} data-test-subj="policyTableFilterInput" - placeholder={intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.policyTable.systempoliciesSearchInputPlaceholder', - defaultMessage: 'Search', - })} - aria-label={intl.formatMessage({ - id: 'xpack.indexLifecycleMgmt.policyTable.systempoliciesSearchInputAriaLabel', - defaultMessage: 'Search policies', - })} + placeholder={i18n.translate( + 'xpack.indexLifecycleMgmt.policyTable.systempoliciesSearchInputPlaceholder', + { + defaultMessage: 'Search' + } + )} + aria-label={i18n.translate( + 'xpack.indexLifecycleMgmt.policyTable.systempoliciesSearchInputAriaLabel', + { + defaultMessage: 'Search policies' + } + )} /> @@ -491,5 +489,3 @@ export class PolicyTableUi extends Component { ); } } - -export const PolicyTable = injectI18n(PolicyTableUi);