Skip to content

Commit

Permalink
[Upgrade Assistant] Clean up i18n (#89661) (#89767)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Jan 29, 2021
1 parent c3f68f5 commit 92b7d97
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

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', () => {
const defaultProps = {
Expand All @@ -22,7 +22,7 @@ describe('IndexDeprecationTable', () => {
// This test simply verifies that the props passed to EuiBaseTable are the ones
// expected.
test('render', () => {
expect(shallowWithIntl(<IndexDeprecationTableUI {...defaultProps} />)).toMatchInlineSnapshot(`
expect(shallow(<IndexDeprecationTable {...defaultProps} />)).toMatchInlineSnapshot(`
<EuiBasicTable
columns={
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { sortBy } from 'lodash';
import React from 'react';

import { EuiBasicTable } from '@elastic/eui';
import { injectI18n } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { FixDefaultFieldsButton } from './default_fields/button';
import { ReindexButton } from './reindex';
import { AppContext } from '../../../../app_context';
Expand All @@ -24,7 +24,7 @@ export interface IndexDeprecationDetails {
details?: string;
}

export interface IndexDeprecationTableProps extends ReactIntl.InjectedIntlProps {
export interface IndexDeprecationTableProps {
indices: IndexDeprecationDetails[];
}

Expand All @@ -35,7 +35,7 @@ interface IndexDeprecationTableState {
pageSize: number;
}

export class IndexDeprecationTableUI extends React.Component<
export class IndexDeprecationTable extends React.Component<
IndexDeprecationTableProps,
IndexDeprecationTableState
> {
Expand All @@ -51,24 +51,27 @@ export class IndexDeprecationTableUI extends React.Component<
}

public render() {
const { intl } = this.props;
const { pageIndex, pageSize, sortField, sortDirection } = this.state;

const columns = [
{
field: 'index',
name: intl.formatMessage({
id: 'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.indexColumnLabel',
defaultMessage: 'Index',
}),
name: i18n.translate(
'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.indexColumnLabel',
{
defaultMessage: 'Index',
}
),
sortable: true,
},
{
field: 'details',
name: intl.formatMessage({
id: 'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.detailsColumnLabel',
defaultMessage: 'Details',
}),
name: i18n.translate(
'xpack.upgradeAssistant.checkupTab.deprecations.indexTable.detailsColumnLabel',
{
defaultMessage: 'Details',
}
),
},
];

Expand Down Expand Up @@ -181,5 +184,3 @@ export class IndexDeprecationTableUI extends React.Component<
};
}
}

export const IndexDeprecationTable = injectI18n(IndexDeprecationTableUI);
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import React from 'react';

import { EuiLoadingSpinner, EuiSwitch } from '@elastic/eui';
import { injectI18n } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

import { HttpSetup } from 'src/core/public';

import { LoadingState } from '../../types';

interface DeprecationLoggingTabProps extends ReactIntl.InjectedIntlProps {
interface DeprecationLoggingTabProps {
http: HttpSetup;
}

Expand All @@ -22,7 +22,7 @@ interface DeprecationLoggingTabState {
loggingEnabled?: boolean;
}

export class DeprecationLoggingToggleUI extends React.Component<
export class DeprecationLoggingToggle extends React.Component<
DeprecationLoggingTabProps,
DeprecationLoggingTabState
> {
Expand Down Expand Up @@ -59,27 +59,29 @@ export class DeprecationLoggingToggleUI extends React.Component<
}

private renderLoggingState() {
const { intl } = this.props;
const { loggingEnabled, loadingState } = this.state;

if (loadingState === LoadingState.Error) {
return intl.formatMessage({
id:
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.errorLabel',
defaultMessage: 'Could not load logging state',
});
return i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.errorLabel',
{
defaultMessage: 'Could not load logging state',
}
);
} else if (loggingEnabled) {
return intl.formatMessage({
id:
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.enabledLabel',
defaultMessage: 'On',
});
return i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.enabledLabel',
{
defaultMessage: 'On',
}
);
} else {
return intl.formatMessage({
id:
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.disabledLabel',
defaultMessage: 'Off',
});
return i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingToggleSwitch.disabledLabel',
{
defaultMessage: 'Off',
}
);
}
}

Expand Down Expand Up @@ -117,5 +119,3 @@ export class DeprecationLoggingToggleUI extends React.Component<
}
};
}

export const DeprecationLoggingToggle = injectI18n(DeprecationLoggingToggleUI);
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
EuiText,
} from '@elastic/eui';
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 { UpgradeAssistantTabProps } from '../../types';
Expand Down Expand Up @@ -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,
setSelectedTabIndex,
intl,
}) => {
const checkupDataTyped = (checkupData! as unknown) as { [checkupType: string]: any[] };
const countByType = Object.keys(checkupDataTyped).reduce((counts, checkupType) => {
Expand All @@ -113,15 +112,18 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
steps={[
{
title: countByType.cluster
? intl.formatMessage({
id: 'xpack.upgradeAssistant.overviewTab.steps.clusterStep.issuesRemainingStepTitle',
defaultMessage: 'Check for issues with your cluster',
})
: intl.formatMessage({
id:
'xpack.upgradeAssistant.overviewTab.steps.clusterStep.noIssuesRemainingStepTitle',
defaultMessage: 'Your cluster settings are ready',
}),
? i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.clusterStep.issuesRemainingStepTitle',
{
defaultMessage: 'Check for issues with your cluster',
}
)
: i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.clusterStep.noIssuesRemainingStepTitle',
{
defaultMessage: 'Your cluster settings are ready',
}
),
status: countByType.cluster ? 'warning' : 'complete',
children: (
<EuiText>
Expand Down Expand Up @@ -168,15 +170,18 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
},
{
title: countByType.indices
? intl.formatMessage({
id: 'xpack.upgradeAssistant.overviewTab.steps.indicesStep.issuesRemainingStepTitle',
defaultMessage: 'Check for issues with your indices',
})
: intl.formatMessage({
id:
'xpack.upgradeAssistant.overviewTab.steps.indicesStep.noIssuesRemainingStepTitle',
defaultMessage: 'Your index settings are ready',
}),
? i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.indicesStep.issuesRemainingStepTitle',
{
defaultMessage: 'Check for issues with your indices',
}
)
: i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.indicesStep.noIssuesRemainingStepTitle',
{
defaultMessage: 'Your index settings are ready',
}
),
status: countByType.indices ? 'warning' : 'complete',
children: (
<EuiText>
Expand Down Expand Up @@ -222,10 +227,12 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
),
},
{
title: intl.formatMessage({
id: 'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.stepTitle',
defaultMessage: 'Review the Elasticsearch deprecation logs',
}),
title: i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.stepTitle',
{
defaultMessage: 'Review the Elasticsearch deprecation logs',
}
),
children: (
<Fragment>
<EuiText grow={false}>
Expand Down Expand Up @@ -256,11 +263,12 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
<EuiSpacer />

<EuiFormRow
label={intl.formatMessage({
id:
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingLabel',
defaultMessage: 'Enable deprecation logging?',
})}
label={i18n.translate(
'xpack.upgradeAssistant.overviewTab.steps.deprecationLogsStep.enableDeprecationLoggingLabel',
{
defaultMessage: 'Enable deprecation logging?',
}
)}
describedByIds={['deprecation-logging']}
>
<DeprecationLoggingToggle http={http} />
Expand All @@ -276,5 +284,3 @@ export const StepsUI: FunctionComponent<UpgradeAssistantTabProps & ReactIntl.Inj
/>
);
};

export const Steps = injectI18n(StepsUI);

0 comments on commit 92b7d97

Please sign in to comment.