Skip to content

Commit

Permalink
[Ingest pipelines] Forms for processors T-U (#76710) (#77364)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Sep 14, 2020
1 parent 0764fc7 commit c09124c
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 { EuiComboBoxOptionOption } from '@elastic/eui';
import { ComboBoxField, FIELD_TYPES, UseField } from '../../../../../../../shared_imports';

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

const fieldsConfig: FieldsConfig = {
properties: {
type: FIELD_TYPES.COMBO_BOX,
deserializer: to.arrayOfStrings,
serializer: (v: string[]) => (v.length ? v : undefined),
label: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.commonFields.propertiesFieldLabel',
{
defaultMessage: 'Properties (optional)',
}
),
},
};

interface Props {
helpText?: React.ReactNode;
propertyOptions?: EuiComboBoxOptionOption[];
}

export const PropertiesField: FunctionComponent<Props> = ({ helpText, propertyOptions }) => {
return (
<UseField
config={{
...fieldsConfig.properties,
helpText,
}}
component={ComboBoxField}
path="fields.properties"
componentProps={{
euiFieldProps: {
options: propertyOptions || [],
noSuggestions: !propertyOptions,
},
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCode } from '@elastic/eui';

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

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

const fieldsConfig: FieldsConfig = {
/* Optional field config */
Expand All @@ -42,21 +37,6 @@ const fieldsConfig: FieldsConfig = {
),
},

properties: {
type: FIELD_TYPES.COMBO_BOX,
deserializer: to.arrayOfStrings,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.geoIPForm.propertiesFieldLabel', {
defaultMessage: 'Properties (optional)',
}),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.geoIPForm.propertiesFieldHelpText',
{
defaultMessage:
'Properties added to the target field. Valid properties depend on the database file used.',
}
),
},

first_only: {
type: FIELD_TYPES.TOGGLE,
defaultValue: true,
Expand Down Expand Up @@ -95,10 +75,14 @@ export const GeoIP: FunctionComponent = () => {

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

<UseField
component={ComboBoxField}
config={fieldsConfig.properties}
path="fields.properties"
<PropertiesField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.geoIPForm.propertiesFieldHelpText',
{
defaultMessage:
'Properties added to the target field. Valid properties depend on the database file used.',
}
)}
/>

<UseField component={ToggleField} config={fieldsConfig.first_only} path="fields.first_only" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ export { SetProcessor } from './set';
export { SetSecurityUser } from './set_security_user';
export { Split } from './split';
export { Sort } from './sort';
export { Trim } from './trim';
export { Uppercase } from './uppercase';
export { UrlDecode } from './url_decode';
export { UserAgent } from './user_agent';

export { FormFieldsComponent } from './shared';
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';
import { TargetField } from './common_fields/target_field';

export const Trim: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.trimForm.fieldNameHelpText',
{ defaultMessage: 'The field to trim whitespace from.' }
)}
/>

<TargetField />

<IgnoreMissingField />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';
import { TargetField } from './common_fields/target_field';

export const Uppercase: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.uppercaseForm.fieldNameHelpText',
{ defaultMessage: 'The field to make uppercase.' }
)}
/>

<TargetField />

<IgnoreMissingField />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldNameField } from './common_fields/field_name_field';
import { TargetField } from './common_fields/target_field';

export const UrlDecode: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.urlDecodeForm.fieldNameHelpText',
{ defaultMessage: 'The field to decode.' }
)}
/>

<TargetField />

<IgnoreMissingField />
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { EuiComboBoxOptionOption } from '@elastic/eui';
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';
import { TargetField } from './common_fields/target_field';
import { PropertiesField } from './common_fields/properties_field';

const propertyOptions: EuiComboBoxOptionOption[] = [
{ label: 'name' },
{ label: 'os' },
{ label: 'device' },
{ label: 'original' },
{ label: 'version' },
];

const fieldsConfig: FieldsConfig = {
/* Optional fields config */
regex_file: {
type: FIELD_TYPES.TEXT,
deserializer: String,
label: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.userAgentForm.regexFileFieldLabel',
{
defaultMessage: 'Regex file (optional)',
}
),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.userAgentForm.regexFileFieldHelpText',
{
defaultMessage:
'A filename containing the regular expressions for parsing the user agent string.',
}
),
},
};

export const UserAgent: FunctionComponent = () => {
return (
<>
<FieldNameField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.userAgentForm.fieldNameHelpText',
{ defaultMessage: 'The field containing the user agent string.' }
)}
/>

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

<TargetField />

<PropertiesField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.userAgentForm.propertiesFieldHelpText',
{ defaultMessage: 'Properties added to the target field.' }
)}
propertyOptions={propertyOptions}
/>

<IgnoreMissingField />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import {
SetSecurityUser,
Split,
Sort,
Trim,
Uppercase,
UrlDecode,
UserAgent,
FormFieldsComponent,
} from '../manage_processor_form/processors';

Expand Down Expand Up @@ -404,28 +408,28 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = {
}),
},
trim: {
FieldsComponent: undefined, // TODO: Implement
FieldsComponent: Trim,
docLinkPath: '/trim-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.trim', {
defaultMessage: 'Trim',
}),
},
uppercase: {
FieldsComponent: undefined, // TODO: Implement
FieldsComponent: Uppercase,
docLinkPath: '/uppercase-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.uppercase', {
defaultMessage: 'Uppercase',
}),
},
urldecode: {
FieldsComponent: undefined, // TODO: Implement
FieldsComponent: UrlDecode,
docLinkPath: '/urldecode-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.urldecode', {
defaultMessage: 'URL decode',
}),
},
user_agent: {
FieldsComponent: undefined, // TODO: Implement
FieldsComponent: UserAgent,
docLinkPath: '/user-agent-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.userAgent', {
defaultMessage: 'User agent',
Expand Down

0 comments on commit c09124c

Please sign in to comment.