Skip to content

Commit

Permalink
Translate Input Control component (elastic#22400)
Browse files Browse the repository at this point in the history
* Translate Input Control component

* Remove export from variables that get wrapped by a helper

* Refactoring

* Update message ids

* Fix unit tests
  • Loading branch information
maryia-lapata authored and MaryiaLapata committed Sep 10, 2018
1 parent 850cfcf commit a633812
Show file tree
Hide file tree
Showing 29 changed files with 388 additions and 142 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"paths": {
"common.ui": "src/ui",
"inputControl":"src/core_plugins/input_control_vis",
"kbn": "src/core_plugins/kibana",
"statusPage": "src/core_plugins/status_page",
"xpack.idxMgmt": "x-pack/plugins/index_management"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`renders ControlsTab 1`] = `
<div>
<ControlEditor
<InjectIntl(ControlEditorUi)
controlIndex={0}
controlParams={
Object {
Expand Down Expand Up @@ -39,7 +39,7 @@ exports[`renders ControlsTab 1`] = `
]
}
/>
<ControlEditor
<InjectIntl(ControlEditorUi)
controlIndex={1}
controlParams={
Object {
Expand Down Expand Up @@ -140,7 +140,11 @@ exports[`renders ControlsTab 1`] = `
onClick={[Function]}
type="button"
>
Add
<FormattedMessage
defaultMessage="Add"
id="inputControl.editor.controlsTab.addButtonLabel"
values={Object {}}
/>
</EuiButton>
</EuiFormRow>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

exports[`renders dynamic options should display disabled dynamic options with tooltip for non-string fields 1`] = `
<div>
<IndexPatternSelect
<InjectIntl(IndexPatternSelectUi)
controlIndex={0}
getIndexPattern={[Function]}
getIndexPatterns={[Function]}
indexPatternId="mockIndexPattern"
onChange={[Function]}
/>
<FieldSelect
<InjectIntl(FieldSelectUi)
controlIndex={0}
fieldName="numberField"
filterField={[Function]}
Expand Down Expand Up @@ -72,14 +72,14 @@ exports[`renders dynamic options should display disabled dynamic options with to

exports[`renders dynamic options should display dynamic options for string fields 1`] = `
<div>
<IndexPatternSelect
<InjectIntl(IndexPatternSelectUi)
controlIndex={0}
getIndexPattern={[Function]}
getIndexPatterns={[Function]}
indexPatternId="mockIndexPattern"
onChange={[Function]}
/>
<FieldSelect
<InjectIntl(FieldSelectUi)
controlIndex={0}
fieldName="keywordField"
filterField={[Function]}
Expand Down Expand Up @@ -123,14 +123,14 @@ exports[`renders dynamic options should display dynamic options for string field

exports[`renders dynamic options should display size field when dynamic options is disabled 1`] = `
<div>
<IndexPatternSelect
<InjectIntl(IndexPatternSelectUi)
controlIndex={0}
getIndexPattern={[Function]}
getIndexPatterns={[Function]}
indexPatternId="mockIndexPattern"
onChange={[Function]}
/>
<FieldSelect
<InjectIntl(FieldSelectUi)
controlIndex={0}
fieldName="keywordField"
filterField={[Function]}
Expand Down Expand Up @@ -193,14 +193,14 @@ exports[`renders dynamic options should display size field when dynamic options

exports[`renders should display chaining input when parents are provided 1`] = `
<div>
<IndexPatternSelect
<InjectIntl(IndexPatternSelectUi)
controlIndex={0}
getIndexPattern={[Function]}
getIndexPatterns={[Function]}
indexPatternId="indexPattern1"
onChange={[Function]}
/>
<FieldSelect
<InjectIntl(FieldSelectUi)
controlIndex={0}
fieldName="keywordField"
filterField={[Function]}
Expand Down Expand Up @@ -296,14 +296,14 @@ exports[`renders should display chaining input when parents are provided 1`] = `

exports[`renders should not display any options until field is selected 1`] = `
<div>
<IndexPatternSelect
<InjectIntl(IndexPatternSelectUi)
controlIndex={0}
getIndexPattern={[Function]}
getIndexPatterns={[Function]}
indexPatternId="mockIndexPattern"
onChange={[Function]}
/>
<FieldSelect
<InjectIntl(FieldSelectUi)
controlIndex={0}
fieldName=""
filterField={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ exports[`renders OptionsTab 1`] = `
<EuiSwitch
checked={false}
data-test-subj="inputControlEditorUpdateFiltersOnChangeCheckbox"
label="Update Kibana filters on each change"
label={
<FormattedMessage
defaultMessage="Update Kibana filters on each change"
id="inputControl.editor.optionsTab.updateFilterLabel"
values={Object {}}
/>
}
onChange={[Function]}
/>
</EuiFormRow>
Expand All @@ -24,7 +30,13 @@ exports[`renders OptionsTab 1`] = `
<EuiSwitch
checked={false}
data-test-subj="inputControlEditorUseTimeFilterCheckbox"
label="Use time filter"
label={
<FormattedMessage
defaultMessage="Use time filter"
id="inputControl.editor.optionsTab.useTimeFielterLabel"
values={Object {}}
/>
}
onChange={[Function]}
/>
</EuiFormRow>
Expand All @@ -36,7 +48,13 @@ exports[`renders OptionsTab 1`] = `
>
<EuiSwitch
data-test-subj="inputControlEditorPinFiltersCheckbox"
label="Pin filters to global state"
label={
<FormattedMessage
defaultMessage="Pin filters to global state"
id="inputControl.editor.optionsTab.pinFieltersLabel"
values={Object {}}
/>
}
onChange={[Function]}
/>
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

exports[`renders RangeControlEditor 1`] = `
<div>
<IndexPatternSelect
<InjectIntl(IndexPatternSelectUi)
controlIndex={0}
getIndexPattern={[Function]}
getIndexPatterns={[Function]}
indexPatternId="indexPattern1"
onChange={[Function]}
/>
<FieldSelect
<InjectIntl(FieldSelectUi)
controlIndex={0}
fieldName="numberField"
filterField={[Function]}
Expand All @@ -22,7 +22,13 @@ exports[`renders RangeControlEditor 1`] = `
fullWidth={false}
hasEmptyLabelSpace={false}
id="stepSize-0"
label="Step Size"
label={
<FormattedMessage
defaultMessage="Step Size"
id="inputControl.editor.rangeControl.stepSizeLabel"
values={Object {}}
/>
}
>
<EuiFieldNumber
compressed={false}
Expand All @@ -38,7 +44,13 @@ exports[`renders RangeControlEditor 1`] = `
fullWidth={false}
hasEmptyLabelSpace={false}
id="decimalPlaces-0"
label="Decimal Places"
label={
<FormattedMessage
defaultMessage="Decimal Places"
id="inputControl.editor.rangeControl.decimalPlacesLabel"
values={Object {}}
/>
}
>
<EuiFieldNumber
compressed={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import React, { Component } from 'react';
import { RangeControlEditor } from './range_control_editor';
import { ListControlEditor } from './list_control_editor';
import { getTitle } from '../../editor_utils';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';

import {
EuiAccordion,
Expand All @@ -34,7 +35,7 @@ import {
EuiSpacer,
} from '@elastic/eui';

export class ControlEditor extends Component {
class ControlEditorUi extends Component {

changeLabel = (evt) => {
this.props.handleLabelChange(this.props.controlIndex, evt);
Expand Down Expand Up @@ -101,7 +102,7 @@ export class ControlEditor extends Component {
<EuiForm>
<EuiFormRow
id={labelId}
label="Control Label"
label={<FormattedMessage id="inputControl.editor.controlEditor.controlLabel" defaultMessage="Control Label"/>}
>
<EuiFieldText
value={this.props.controlParams.label}
Expand All @@ -118,21 +119,30 @@ export class ControlEditor extends Component {
return (
<div>
<EuiButtonIcon
aria-label="Move control up"
aria-label={this.props.intl.formatMessage({
id: 'inputControl.editor.controlEditor.moveControlUpAriaLabel',
defaultMessage: 'Move control up'
})}
color="primary"
onClick={this.moveUpControl}
iconType="sortUp"
data-test-subj={`inputControlEditorMoveUpControl${this.props.controlIndex}`}
/>
<EuiButtonIcon
aria-label="Move control down"
aria-label={this.props.intl.formatMessage({
id: 'inputControl.editor.controlEditor.moveControlDownAriaLabel',
defaultMessage: 'Move control down'
})}
color="primary"
onClick={this.moveDownControl}
iconType="sortDown"
data-test-subj={`inputControlEditorMoveDownControl${this.props.controlIndex}`}
/>
<EuiButtonIcon
aria-label="Remove control"
aria-label={this.props.intl.formatMessage({
id: 'inputControl.editor.controlEditor.removeControlAriaLabel',
defaultMessage: 'Remove control'
})}
color="danger"
onClick={this.removeControl}
iconType="cross"
Expand Down Expand Up @@ -161,7 +171,7 @@ export class ControlEditor extends Component {
}
}

ControlEditor.propTypes = {
ControlEditorUi.propTypes = {
controlIndex: PropTypes.number.isRequired,
controlParams: PropTypes.object.isRequired,
handleLabelChange: PropTypes.func.isRequired,
Expand All @@ -179,3 +189,5 @@ ControlEditor.propTypes = {
})).isRequired,
handleParentChange: PropTypes.func.isRequired,
};

export const ControlEditor = injectI18n(ControlEditorUi);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import React, { Component } from 'react';
import { ControlEditor } from './control_editor';
import { addControl, moveControl, newControl, removeControl, setControl } from '../../editor_utils';
import { getLineageMap, getParentCandidates } from '../../lineage';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';

import {
EuiButton,
Expand All @@ -33,7 +34,7 @@ import {
EuiSelect,
} from '@elastic/eui';

export class ControlsTab extends Component {
class ControlsTabUi extends Component {

state = {
type: 'list'
Expand Down Expand Up @@ -138,6 +139,8 @@ export class ControlsTab extends Component {
}

render() {
const { intl } = this.props;

return (
<div>

Expand All @@ -151,12 +154,21 @@ export class ControlsTab extends Component {
>
<EuiSelect
options={[
{ value: 'range', text: 'Range slider' },
{ value: 'list', text: 'Options list' },
{ value: 'range', text: intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.rangeDropDownOptionLabel',
defaultMessage: 'Range slider' })
},
{ value: 'list', text: intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.listDropDownOptionLabel',
defaultMessage: 'Options list' })
},
]}
value={this.state.type}
onChange={evt => this.setState({ type: evt.target.value })}
aria-label="Select control type"
aria-label={intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.controlTypeAriaLabel',
defaultMessage: 'Select control type'
})}
/>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -169,9 +181,12 @@ export class ControlsTab extends Component {
onClick={this.handleAddControl}
iconType="plusInCircle"
data-test-subj="inputControlEditorAddBtn"
aria-label="Add control"
aria-label={intl.formatMessage({
id: 'inputControl.editor.controlsTab.select.addControlAriaLabel',
defaultMessage: 'Add control'
})}
>
Add
<FormattedMessage id="inputControl.editor.controlsTab.addButtonLabel" defaultMessage="Add"/>
</EuiButton>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -183,7 +198,9 @@ export class ControlsTab extends Component {
}
}

ControlsTab.propTypes = {
ControlsTabUi.propTypes = {
scope: PropTypes.object.isRequired,
stageEditorParams: PropTypes.func.isRequired
};

export const ControlsTab = injectI18n(ControlsTabUi);
Loading

0 comments on commit a633812

Please sign in to comment.