[Upgrade Assistant] Clean up i18n (#89661)

This commit is contained in:
Alison Goryachev 2021-01-29 13:18:06 -05:00 committed by GitHub
parent 8780a2de6e
commit d6227fbb30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 70 deletions

View file

@ -5,9 +5,9 @@
*/ */
import React from 'react'; import React from 'react';
import { shallowWithIntl } from '@kbn/test/jest'; import { shallow } from 'enzyme';
import { IndexDeprecationTableProps, IndexDeprecationTableUI } from './index_table'; import { IndexDeprecationTableProps, IndexDeprecationTable } from './index_table';
describe('IndexDeprecationTable', () => { describe('IndexDeprecationTable', () => {
const defaultProps = { const defaultProps = {
@ -22,7 +22,7 @@ describe('IndexDeprecationTable', () => {
// This test simply verifies that the props passed to EuiBaseTable are the ones // This test simply verifies that the props passed to EuiBaseTable are the ones
// expected. // expected.
test('render', () => { test('render', () => {
expect(shallowWithIntl(<IndexDeprecationTableUI {...defaultProps} />)).toMatchInlineSnapshot(` expect(shallow(<IndexDeprecationTable {...defaultProps} />)).toMatchInlineSnapshot(`
<EuiBasicTable <EuiBasicTable
columns={ columns={
Array [ Array [

View file

@ -8,7 +8,7 @@ import { sortBy } from 'lodash';
import React from 'react'; import React from 'react';
import { EuiBasicTable } from '@elastic/eui'; import { EuiBasicTable } from '@elastic/eui';
import { injectI18n } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n';
import { ReindexButton } from './reindex'; import { ReindexButton } from './reindex';
import { AppContext } from '../../../../app_context'; import { AppContext } from '../../../../app_context';
import { EnrichedDeprecationInfo } from '../../../../../../common/types'; import { EnrichedDeprecationInfo } from '../../../../../../common/types';
@ -22,7 +22,7 @@ export interface IndexDeprecationDetails {
details?: string; details?: string;
} }
export interface IndexDeprecationTableProps extends ReactIntl.InjectedIntlProps { export interface IndexDeprecationTableProps {
indices: IndexDeprecationDetails[]; indices: IndexDeprecationDetails[];
} }
@ -33,7 +33,7 @@ interface IndexDeprecationTableState {
pageSize: number; pageSize: number;
} }
export class IndexDeprecationTableUI extends React.Component< export class IndexDeprecationTable extends React.Component<
IndexDeprecationTableProps, IndexDeprecationTableProps,
IndexDeprecationTableState IndexDeprecationTableState
> { > {
@ -49,24 +49,27 @@ export class IndexDeprecationTableUI extends React.Component<
} }
public render() { public render() {
const { intl } = this.props;
const { pageIndex, pageSize, sortField, sortDirection } = this.state; const { pageIndex, pageSize, sortField, sortDirection } = this.state;
const columns = [ const columns = [
{ {
field: 'index', field: 'index',
name: intl.formatMessage({ name: i18n.translate(
id: 'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.indexColumnLabel', 'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.indexColumnLabel',
defaultMessage: 'Index', {
}), defaultMessage: 'Index',
}
),
sortable: true, sortable: true,
}, },
{ {
field: 'details', field: 'details',
name: intl.formatMessage({ name: i18n.translate(
id: 'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.detailsColumnLabel', 'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.detailsColumnLabel',
defaultMessage: 'Details', {
}), defaultMessage: 'Details',
}
),
}, },
]; ];
@ -169,5 +172,3 @@ export class IndexDeprecationTableUI extends React.Component<
}; };
} }
} }
export const IndexDeprecationTable = injectI18n(IndexDeprecationTableUI);

View file

@ -7,13 +7,13 @@
import React from 'react'; import React from 'react';
import { EuiLoadingSpinner, EuiSwitch } from '@elastic/eui'; import { EuiLoadingSpinner, EuiSwitch } from '@elastic/eui';
import { injectI18n } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n';
import { HttpSetup } from 'src/core/public'; import { HttpSetup } from 'src/core/public';
import { LoadingState } from '../../types'; import { LoadingState } from '../../types';
interface DeprecationLoggingTabProps extends ReactIntl.InjectedIntlProps { interface DeprecationLoggingTabProps {
http: HttpSetup; http: HttpSetup;
} }
@ -22,7 +22,7 @@ interface DeprecationLoggingTabState {
loggingEnabled?: boolean; loggingEnabled?: boolean;
} }
export class DeprecationLoggingToggleUI extends React.Component< export class DeprecationLoggingToggle extends React.Component<
DeprecationLoggingTabProps, DeprecationLoggingTabProps,
DeprecationLoggingTabState DeprecationLoggingTabState
> { > {
@ -59,27 +59,29 @@ export class DeprecationLoggingToggleUI extends React.Component<
} }
private renderLoggingState() { private renderLoggingState() {
const { intl } = this.props;
const { loggingEnabled, loadingState } = this.state; const { loggingEnabled, loadingState } = this.state;
if (loadingState === LoadingState.Error) { if (loadingState === LoadingState.Error) {
return intl.formatMessage({ return i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.errorLabel',
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.errorLabel', {
defaultMessage: 'Could not load logging state', defaultMessage: 'Could not load logging state',
}); }
);
} else if (loggingEnabled) { } else if (loggingEnabled) {
return intl.formatMessage({ return i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.enabledLabel',
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.enabledLabel', {
defaultMessage: 'On', defaultMessage: 'On',
}); }
);
} else { } else {
return intl.formatMessage({ return i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.disabledLabel',
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.disabledLabel', {
defaultMessage: 'Off', defaultMessage: 'Off',
}); }
);
} }
} }
@ -117,5 +119,3 @@ export class DeprecationLoggingToggleUI extends React.Component<
} }
}; };
} }
export const DeprecationLoggingToggle = injectI18n(DeprecationLoggingToggleUI);

View file

@ -17,7 +17,7 @@ import {
EuiText, EuiText,
} from '@elastic/eui'; } from '@elastic/eui';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react'; import { FormattedMessage } from '@kbn/i18n/react';
import { CURRENT_MAJOR_VERSION, NEXT_MAJOR_VERSION } from '../../../../../common/version'; import { CURRENT_MAJOR_VERSION, NEXT_MAJOR_VERSION } from '../../../../../common/version';
import { UpgradeAssistantTabProps } from '../../types'; import { UpgradeAssistantTabProps } from '../../types';
@ -89,10 +89,9 @@ const START_UPGRADE_STEP = (isCloudEnabled: boolean, esDocBasePath: string) => (
), ),
}); });
export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.InjectedIntlProps> = ({ export const Steps: FunctionComponent<UpgradeAssistantTabProps> = ({
checkupData, checkupData,
setSelectedTabIndex, setSelectedTabIndex,
intl,
}) => { }) => {
const checkupDataTyped = (checkupData! as unknown) as { [checkupType: string]: any[] }; const checkupDataTyped = (checkupData! as unknown) as { [checkupType: string]: any[] };
const countByType = Object.keys(checkupDataTyped).reduce((counts, checkupType) => { const countByType = Object.keys(checkupDataTyped).reduce((counts, checkupType) => {
@ -113,15 +112,18 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
steps={[ steps={[
{ {
title: countByType.cluster title: countByType.cluster
? intl.formatMessage({ ? i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.clusterStep.issuesRemainingStepTitle', 'xpack.upgradeAssistant.overviewTab.steps.clusterStep.issuesRemainingStepTitle',
defaultMessage: 'Check for issues with your cluster', {
}) defaultMessage: 'Check for issues with your cluster',
: intl.formatMessage({ }
id: )
'xpack.upgradeAssistant.overviewTab.steps.clusterStep.noIssuesRemainingStepTitle', : i18n.translate(
defaultMessage: 'Your cluster settings are ready', 'xpack.upgradeAssistant.overviewTab.steps.clusterStep.noIssuesRemainingStepTitle',
}), {
defaultMessage: 'Your cluster settings are ready',
}
),
status: countByType.cluster ? 'warning' : 'complete', status: countByType.cluster ? 'warning' : 'complete',
children: ( children: (
<EuiText> <EuiText>
@ -168,15 +170,18 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
}, },
{ {
title: countByType.indices title: countByType.indices
? intl.formatMessage({ ? i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.indicesStep.issuesRemainingStepTitle', 'xpack.upgradeAssistant.overviewTab.steps.indicesStep.issuesRemainingStepTitle',
defaultMessage: 'Check for issues with your indices', {
}) defaultMessage: 'Check for issues with your indices',
: intl.formatMessage({ }
id: )
'xpack.upgradeAssistant.overviewTab.steps.indicesStep.noIssuesRemainingStepTitle', : i18n.translate(
defaultMessage: 'Your index settings are ready', 'xpack.upgradeAssistant.overviewTab.steps.indicesStep.noIssuesRemainingStepTitle',
}), {
defaultMessage: 'Your index settings are ready',
}
),
status: countByType.indices ? 'warning' : 'complete', status: countByType.indices ? 'warning' : 'complete',
children: ( children: (
<EuiText> <EuiText>
@ -222,10 +227,12 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
), ),
}, },
{ {
title: intl.formatMessage({ title: i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.stepTitle', 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.stepTitle',
defaultMessage: 'Review the Elasticsearch deprecation logs', {
}), defaultMessage: 'Review the Elasticsearch deprecation logs',
}
),
children: ( children: (
<Fragment> <Fragment>
<EuiText grow={false}> <EuiText grow={false}>
@ -256,11 +263,12 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
<EuiSpacer /> <EuiSpacer />
<EuiFormRow <EuiFormRow
label={intl.formatMessage({ label={i18n.translate(
id: 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingLabel',
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingLabel', {
defaultMessage: 'Enable deprecation logging?', defaultMessage: 'Enable deprecation logging?',
})} }
)}
describedByIds={['deprecation-logging']} describedByIds={['deprecation-logging']}
> >
<DeprecationLoggingToggle http={http} /> <DeprecationLoggingToggle http={http} />
@ -276,5 +284,3 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
/> />
); );
}; };
export const Steps = injectI18n(StepsUI);