Skip to content

Commit

Permalink
fix types and i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Aug 12, 2020
1 parent 106701f commit 5ff03ea
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Bytes: FunctionComponent = () => {
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldHelpText',
'xpack.ingestPipelines.pipelineEditor.bytesForm.fieldNameHelpText',
{ defaultMessage: 'The field to convert.' }
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,12 @@ interface Props {

const { emptyField } = fieldValidators;

const typeConfig: FieldConfig = {
const typeConfig: FieldConfig<any, string> = {
type: FIELD_TYPES.COMBO_BOX,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.typeField.typeFieldLabel', {
defaultMessage: 'Processor',
}),
deserializer: (value: string | undefined) => {
if (value) {
return [value];
}
return [];
},
serializer: (value: string[]) => {
return value[0];
},
deserializer: String,
validations: [
{
validator: emptyField(
Expand All @@ -73,11 +65,11 @@ const typeConfig: FieldConfig = {

export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) => {
return (
<UseField<string[]> config={typeConfig} defaultValue={initialType} path="type">
<UseField<string> config={typeConfig} defaultValue={initialType} path="type">
{(typeField) => {
let selectedOptions: ProcessorTypeAndLabel[];
if (typeField.value?.length) {
const [type] = typeField.value;
const type = typeField.value;
const descriptor = getProcessorDescriptor(type);
selectedOptions = descriptor
? [{ label: descriptor.label, value: type }]
Expand All @@ -103,9 +95,7 @@ export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) =>
return false;
}

const newValue = [...(typeField.value as string[]), value];

typeField.setValue(newValue);
typeField.setValue(value);
};

return (
Expand All @@ -131,8 +121,9 @@ export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) =>
options={processorTypesAndLabels}
selectedOptions={selectedOptions}
onCreateOption={onCreateComboOption}
onChange={(options: EuiComboBoxOptionOption[]) => {
typeField.setValue(options.map(({ value }) => value));
onChange={(options: Array<EuiComboBoxOptionOption<string>>) => {
const [selection] = options;
typeField.setValue(selection?.value! ?? '');
}}
noSuggestions={false}
singleSelection={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ const fieldsConfig: FieldsConfig = {
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldLabel', {
defaultMessage: 'The field to assign the converted value to.',
}),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldHelpText',
{
defaultMessage: 'The field to assign the converted value to.',
}
),
},
};

Expand All @@ -59,7 +62,7 @@ export const Convert: FunctionComponent = () => {
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldHelpText',
'xpack.ingestPipelines.pipelineEditor.convertForm.fieldNameHelpText',
{ defaultMessage: 'The field whose value is to be converted.' }
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ export const CSV: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.convertForm.fieldNameHelpText',
{ defaultMessage: 'The field to extract data from.' }
)}
helpText={i18n.translate('xpack.ingestPipelines.pipelineEditor.csvForm.fieldNameHelpText', {
defaultMessage: 'The field to extract data from.',
})}
/>

<UseField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const fieldsConfig: FieldsConfig = {
),
helpText: (
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.dateForm.timezoneHelpText"
id="xpack.ingestPipelines.pipelineEditor.dateIndexNameForm.timezoneHelpText"
defaultMessage="The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names. Default value is {timezone}."
values={{ timezone: <EuiCode inline>{'UTC'}</EuiCode> }}
/>
Expand All @@ -134,7 +134,7 @@ const fieldsConfig: FieldsConfig = {
),
helpText: (
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.dateForm.localeHelpText"
id="xpack.ingestPipelines.pipelineEditor.dateIndexForm.localeHelpText"
defaultMessage="The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days. Default value is {locale}"
values={{ locale: <EuiCode inline>{'ENGLISH'}</EuiCode> }}
/>
Expand Down

0 comments on commit 5ff03ea

Please sign in to comment.