Skip to content

Commit

Permalink
Fix dynamic uses of i18n and correct unprefixed and duplicate i18n id…
Browse files Browse the repository at this point in the history
…entifiers in data plugin (opensearch-project#8395)

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki authored Oct 3, 2024
1 parent 2f541ff commit 4129d4d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/plugins/data/public/data_sources/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,3 @@ export const s3DataSourceMetadata = {
},
},
};

export const DATA_SELECTOR_REFRESHER_POPOVER_TEXT = 'Refresh data selector';
export const DATA_SELECTOR_DEFAULT_PLACEHOLDER = 'Select a data source';
export const DATA_SELECTOR_S3_DATA_SOURCE_GROUP_HINT_LABEL = ' - Opens in Log Explorer';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import { EuiButtonIconProps, EuiSmallButtonIcon, EuiToolTip, EuiToolTipProps } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React from 'react';

interface IDataSelectorRefresherProps {
Expand All @@ -19,9 +18,7 @@ export const DataSelectorRefresher: React.FC<IDataSelectorRefresherProps> = Reac
return (
<EuiToolTip
position="right"
content={i18n.translate('data.datasource.selector.refreshDataSources', {
defaultMessage: tooltipText,
})}
content={tooltipText}
display="block"
data-test-subj="sourceRefreshButtonToolTip"
{...toolTipProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import { EuiCompressedComboBox } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React, { useCallback, useEffect, useMemo } from 'react';
import {
DATA_SELECTOR_DEFAULT_PLACEHOLDER,
DATA_SELECTOR_REFRESHER_POPOVER_TEXT,
DATA_SELECTOR_S3_DATA_SOURCE_GROUP_HINT_LABEL,
} from '../constants';
import { DataSetWithDataSource, DataSource, IndexPatternOption } from '../datasource';
import { DataSelectorRefresher } from './data_selector_refresher';
import { DataSourceGroup, DataSourceOption, DataSourceSelectableProps } from './types';
Expand Down Expand Up @@ -70,13 +65,13 @@ const addOrUpdateGroup = (
const groupType = metadata.ui.groupType;
let groupName =
metadata.ui.typeLabel ||
i18n.translate('dataExplorer.dataSourceSelector.defaultGroupTitle', {
i18n.translate('data.dataSourceSelector.defaultGroupTitle', {
defaultMessage: 'Default Group',
});

if (dataSource.getType() !== 'DEFAULT_INDEX_PATTERNS') {
groupName += i18n.translate('dataExplorer.dataSourceSelector.redirectionHint', {
defaultMessage: DATA_SELECTOR_S3_DATA_SOURCE_GROUP_HINT_LABEL,
groupName += i18n.translate('data.dataSourceSelector.redirectionHint', {
defaultMessage: ' - Opens in Log Explorer',
});
}

Expand Down Expand Up @@ -165,7 +160,7 @@ export const DataSourceSelectable = ({
className="dataExplorerDSSelect"
data-test-subj="dataExplorerDSSelect"
placeholder={i18n.translate('data.datasource.selectADatasource', {
defaultMessage: DATA_SELECTOR_DEFAULT_PLACEHOLDER,
defaultMessage: 'Select a data source',
})}
options={memorizedDataSourceOptionList as any}
selectedOptions={selectedSources as any}
Expand All @@ -174,7 +169,9 @@ export const DataSourceSelectable = ({
isClearable={false}
append={
<DataSelectorRefresher
tooltipText={DATA_SELECTOR_REFRESHER_POPOVER_TEXT}
tooltipText={i18n.translate('data.datasource.selector.refreshDataSources', {
defaultMessage: 'Refresh data selector',
})}
onRefresh={onRefresh}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DefaultLanguageReference = () => {
<div>
<EuiButtonIcon
iconType={'iInCircle'}
aria-label={i18n.translate('discover.queryControls.languageReference', {
aria-label={i18n.translate('data.queryControls.languageReference', {
defaultMessage: `Language Reference`,
})}
onClick={() => setIsLanguageReferenceOpen(!isLanguageReferenceOpen)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
isLoading
data-test-subj="queryResultLoading"
>
{i18n.translate('data.query.languageService.queryResults.completeTime', {
defaultMessage: `Loading ${time} s`,
{i18n.translate('data.query.languageService.queryResults.loadTime', {
defaultMessage: 'Loading {time} s',
values: { time },
})}
</EuiButtonEmpty>
);
Expand All @@ -79,19 +80,21 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
if (props.queryStatus.status === ResultStatus.READY) {
let message;
if (!props.queryStatus.elapsedMs) {
message = i18n.translate('data.query.languageService.queryResults.completeTime', {
defaultMessage: `Completed`,
message = i18n.translate('data.query.languageService.queryResults.completeNoTime', {
defaultMessage: 'Completed',
});
} else if (props.queryStatus.elapsedMs < 1000) {
message = i18n.translate(
'data.query.languageService.queryResults.completeTimeInMiliseconds',
{
defaultMessage: `Completed in ${props.queryStatus.elapsedMs} ms`,
defaultMessage: 'Completed in {timeMS} ms',
values: { timeMS: props.queryStatus.elapsedMs },
}
);
} else {
message = i18n.translate('data.query.languageService.queryResults.completeTimeInSeconds', {
defaultMessage: `Completed in ${(props.queryStatus.elapsedMs / 1000).toFixed(1)} s`,
defaultMessage: 'Completed in {time} s',
values: { time: (props.queryStatus.elapsedMs / 1000).toFixed(1) },
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/data/public/search/errors/timeout_error.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

import { SearchTimeoutError, TIMEOUT_MESSAGE } from './timeout_error';
import { SearchTimeoutError } from './timeout_error';

import { coreMock } from '../../../../../core/public/mocks';
const startMock = coreMock.createStart();
Expand All @@ -45,6 +45,8 @@ describe('SearchTimeoutError', () => {
it('Should create timeout message', () => {
const e = new SearchTimeoutError(new AbortError());
const component = mount(e.getErrorMessage(startMock.application));
expect(component.html()).toEqual(TIMEOUT_MESSAGE);
expect(component.html()).toEqual(
'Your query has timed out. Contact your system administrator to review your index strategy or increase the run time.'
);
});
});
9 changes: 6 additions & 3 deletions src/plugins/data/public/search/errors/timeout_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import { i18n } from '@osd/i18n';
import { ApplicationStart } from 'opensearch-dashboards/public';
import { OsdError } from '../../../../opensearch_dashboards_utils/common';

export const TIMEOUT_MESSAGE: string =
'Your query has timed out. Contact your system administrator to review your index strategy or increase the run time.';
/**
* Request Failure - When an entire multi request fails
* @param {Error} err - the Error that came back
Expand All @@ -46,7 +44,12 @@ export class SearchTimeoutError extends OsdError {

public getErrorMessage(application: ApplicationStart) {
return (
<>{i18n.translate('data.search.timeoutContactAdmin', { defaultMessage: TIMEOUT_MESSAGE })}</>
<>
{i18n.translate('data.search.timeoutContactAdmin', {
defaultMessage:
'Your query has timed out. Contact your system administrator to review your index strategy or increase the run time.',
})}
</>
);
}
}
2 changes: 1 addition & 1 deletion src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export default class QueryEditorUI extends Component<Props, State> {
<EuiFlexItem grow={false}>
<EuiButtonIcon
iconType={this.state.isCollapsed ? 'expand' : 'minimize'}
aria-label={i18n.translate('discover.queryControls.languageToggle', {
aria-label={i18n.translate('data.queryControls.languageToggle', {
defaultMessage: `Language Toggle`,
})}
onClick={() => this.setIsCollapsed(!this.state.isCollapsed)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function QueryLanguageSwitcher(props: Props) {
<EuiText size="s">
<p>
<FormattedMessage
id="data.query.queryBar.syntaxOptionsDescription"
id="data.query.queryBar.syntaxOptionsLongDescription"
defaultMessage="The {docsLink} (DQL) offers a simplified query
syntax and support for scripted fields. If you turn off DQL,
OpenSearch Dashboards uses Lucene."
Expand Down

0 comments on commit 4129d4d

Please sign in to comment.