Skip to content

Commit

Permalink
[Ingest Pipelines] Processor forms for processors E-J (elastic#75054)
Browse files Browse the repository at this point in the history
* Added the enrich processor form (big one)

* added fail processor form

* Added foreach processor form

* Added geoip processor form and refactored some deserialization

* added grok processor form and updated comments and some i18n ids

* updated existing gsub processor form to be in line with other forms

* added html_strip processor form

* refactored some serialize and deserialize functions and added inference processor form

* fix copy-pasta mistake in inference form and add join processor form

* Added JSON processor field

- Also factored out target_field field to common field (still have
  to update the all instances)
- Built out special logic for handling add_to_root and
  target_field combo on JSON processor form
- Created another serializer, for default boolean -> undefined.

* remove unused variable

* Refactor to use new shared target_field component, and fix JSON serializer bug

* fix i18n

* address pr feedback

* Fix enrich max fields help text copy

* add link to enrich policy docs in help text

* fix error validation message in enrich policy form and replace space with horizontal rule

* address copy feedback

* fix i18n id typo

* fix i18n

* address additional round of feedback and fix json form help text

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
2 people authored and thomasneirynck committed Aug 21, 2020
1 parent 2c10325 commit d6ee7fa
Show file tree
Hide file tree
Showing 26 changed files with 1,300 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { FunctionComponent } from 'react';
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
import { EuiHorizontalRule } from '@elastic/eui';

import { FormDataProvider } from '../../../../../shared_imports';
import { ProcessorInternal } from '../../types';
Expand Down Expand Up @@ -36,7 +36,7 @@ export const ProcessorSettingsFields: FunctionComponent<Props> = ({ processor })
return (
<>
<formDescriptor.FieldsComponent />
<EuiSpacer size="m" />
<EuiHorizontalRule />
<CommonProcessorFields />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {
ComboBoxField,
} from '../../../../../../shared_imports';

import { FieldsConfig } from './shared';
import { FieldsConfig, to } from './shared';
import { FieldNameField } from './common_fields/field_name_field';

const { emptyField } = fieldValidators;

const fieldsConfig: FieldsConfig = {
value: {
type: FIELD_TYPES.COMBO_BOX,
deserializer: (v) => (Array.isArray(v) ? v : [String(v)]),
deserializer: to.arrayOfStrings,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueFieldLabel', {
defaultMessage: 'Value',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,9 @@
import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

import { FIELD_TYPES, UseField, Field } from '../../../../../../shared_imports';

import { FieldsConfig } from './shared';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';

const fieldsConfig: FieldsConfig = {
target_field: {
type: FIELD_TYPES.TEXT,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldHelpText', {
defaultMessage: 'The field to assign the converted value to',
}),
},
};
import { TargetField } from './common_fields/target_field';

export const Bytes: FunctionComponent = () => {
return (
Expand All @@ -35,7 +21,7 @@ export const Bytes: FunctionComponent = () => {
)}
/>

<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
<TargetField />

<IgnoreMissingField />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,19 @@ import {
FIELD_TYPES,
fieldValidators,
UseField,
Field,
SelectField,
NumericField,
} from '../../../../../../shared_imports';

import { FieldsConfig } from './shared';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';
import { TargetField } from './common_fields/target_field';

const { emptyField } = fieldValidators;

const fieldsConfig: FieldsConfig = {
target_field: {
type: FIELD_TYPES.TEXT,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.circleForm.targetFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.circleForm.targetFieldHelpText',
{
defaultMessage: 'By default field is updated in-place.',
}
),
},
/* Required fields config */
error_distance: {
type: FIELD_TYPES.NUMBER,
deserializer: (v) => (typeof v === 'number' && !isNaN(v) ? v : 1.0),
Expand Down Expand Up @@ -71,6 +60,7 @@ const fieldsConfig: FieldsConfig = {
},
shape_type: {
type: FIELD_TYPES.SELECT,
serializer: String,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.circleForm.shapeTypeFieldLabel', {
defaultMessage: 'Shape type',
}),
Expand Down Expand Up @@ -132,7 +122,7 @@ export const Circle: FunctionComponent = () => {
path="fields.shape_type"
/>

<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
<TargetField />

<IgnoreMissingField />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
} from '../../../../../../../shared_imports';

import { TextEditor } from '../../field_components';
import { to, from } from '../shared';

const ignoreFailureConfig: FieldConfig = {
defaultValue: false,
serializer: (v) => (v === false ? undefined : v),
deserializer: (v) => (typeof v === 'boolean' ? v : undefined),
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(false),
label: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.commonFields.ignoreFailureFieldLabel',
{
Expand Down Expand Up @@ -62,7 +63,7 @@ export const CommonProcessorFields: FunctionComponent = () => {
component={TextEditor}
componentProps={{
editorProps: {
language: 'painless',
languageId: 'painless',
height: 75,
options: { minimap: { enabled: false } },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,47 @@
*/
import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';
import { FIELD_TYPES, UseField, ToggleField } from '../../../../../../../shared_imports';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCode } from '@elastic/eui';

import { FieldsConfig } from '../shared';
import {
FIELD_TYPES,
UseField,
ToggleField,
FieldConfig,
} from '../../../../../../../shared_imports';

import { FieldsConfig, to, from } from '../shared';

export const fieldsConfig: FieldsConfig = {
ignore_missing: {
type: FIELD_TYPES.TOGGLE,
defaultValue: false,
serializer: (v) => (v === false ? undefined : v),
deserializer: (v) => (typeof v === 'boolean' ? v : undefined),
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(false),
label: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.commonFields.ignoreMissingFieldLabel',
{
defaultMessage: 'Ignore missing',
}
),
helpText: (
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.commonFields.ignoreMissingFieldHelpText"
defaultMessage="Ignore documents with a missing {field}"
values={{
field: <EuiCode>{'field'}</EuiCode>,
}}
/>
),
},
};

interface Props {
helpText?: string;
}
type Props = Partial<FieldConfig>;

export const IgnoreMissingField: FunctionComponent<Props> = ({ helpText }) => (
export const IgnoreMissingField: FunctionComponent<Props> = (props) => (
<UseField
config={{ ...fieldsConfig.ignore_missing, helpText }}
config={{ ...fieldsConfig.ignore_missing, ...props }}
component={ToggleField}
path="fields.ignore_missing"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

import { Field, FIELD_TYPES, UseField, FieldConfig } from '../../../../../../../shared_imports';

import { FieldsConfig } from '../shared';

const fieldsConfig: FieldsConfig = {
target_field: {
type: FIELD_TYPES.TEXT,
deserializer: String,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.commonFields.targetFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.commonFields.targetFieldHelpText',
{
defaultMessage:
'The field to assign the joined value to. If empty, the field is updated in-place.',
}
),
},
};

type Props = Partial<FieldConfig>;

export const TARGET_FIELD_PATH = 'fields.target_field';

export const TargetField: FunctionComponent<Props> = (props) => {
return (
<UseField
config={{
...fieldsConfig.target_field,
...props,
}}
component={Field}
path={TARGET_FIELD_PATH}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
FIELD_TYPES,
fieldValidators,
UseField,
Field,
SelectField,
} from '../../../../../../shared_imports';

import { FieldsConfig } from './shared';
import { FieldNameField } from './common_fields/field_name_field';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { TargetField } from './common_fields/target_field';

const { emptyField } = fieldValidators;

Expand All @@ -42,19 +42,6 @@ const fieldsConfig: FieldsConfig = {
},
],
},
/* Optional fields config */
target_field: {
type: FIELD_TYPES.TEXT,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldHelpText',
{
defaultMessage: 'The field to assign the converted value to.',
}
),
},
};

export const Convert: FunctionComponent = () => {
Expand Down Expand Up @@ -128,7 +115,14 @@ export const Convert: FunctionComponent = () => {
path="fields.type"
/>

<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
<TargetField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldHelpText',
{
defaultMessage: 'The field to assign the converted value to.',
}
)}
/>

<IgnoreMissingField />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FieldsConfig } from './shared';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';

import { isArrayOfStrings } from './shared';
import { to } from './shared';

const { minLengthField } = fieldValidators;

Expand All @@ -47,9 +47,7 @@ const fieldsConfig: FieldsConfig = {
/* Required fields config */
target_fields: {
type: FIELD_TYPES.COMBO_BOX,
deserializer: (v) => {
return isArrayOfStrings(v) ? v : [];
},
deserializer: to.arrayOfStrings,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.csvForm.targetFieldsFieldLabel', {
defaultMessage: 'Target fields',
}),
Expand Down Expand Up @@ -112,7 +110,7 @@ const fieldsConfig: FieldsConfig = {
trim: {
type: FIELD_TYPES.TOGGLE,
defaultValue: false,
deserializer: (v) => (typeof v === 'boolean' ? v : undefined),
deserializer: to.booleanOrUndef,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.csvForm.trimFieldLabel', {
defaultMessage: 'Trim',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ import {
ComboBoxField,
} from '../../../../../../shared_imports';

import { FieldsConfig, isArrayOfStrings } from './shared';
import { FieldsConfig, to } from './shared';
import { FieldNameField } from './common_fields/field_name_field';
import { TargetField } from './common_fields/target_field';

const { minLengthField } = fieldValidators;

const fieldsConfig: FieldsConfig = {
/* Required fields config */
formats: {
type: FIELD_TYPES.COMBO_BOX,
deserializer: (v) => {
return isArrayOfStrings(v) ? v : [];
},
deserializer: to.arrayOfStrings,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.dateForm.formatsFieldLabel', {
defaultMessage: 'Formats',
}),
Expand All @@ -51,22 +50,6 @@ const fieldsConfig: FieldsConfig = {
],
},
/* Optional fields config */
target_field: {
type: FIELD_TYPES.TEXT,
serializer: (v) => (v ? undefined : v),
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.dateForm.targetFieldFieldLabel', {
defaultMessage: 'Target field (optional)',
}),
helpText: (
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.dateForm.targetFieldHelpText"
defaultMessage="The field that will hold the parsed date. Default field is {defaultField}."
values={{
defaultField: <EuiCode inline>{'@timestamp'}</EuiCode>,
}}
/>
),
},
timezone: {
type: FIELD_TYPES.TEXT,
serializer: (v) => (v ? v : undefined),
Expand Down Expand Up @@ -112,7 +95,17 @@ export const DateProcessor: FunctionComponent = () => {

<UseField config={fieldsConfig.formats} component={ComboBoxField} path="fields.formats" />

<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
<TargetField
helpText={
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.dateForm.targetFieldHelpText"
defaultMessage="The field that will hold the parsed date. Default field is {defaultField}."
values={{
defaultField: <EuiCode inline>{'@timestamp'}</EuiCode>,
}}
/>
}
/>

<UseField config={fieldsConfig.timezone} component={Field} path="fields.timezone" />

Expand Down
Loading

0 comments on commit d6ee7fa

Please sign in to comment.