Skip to content

Commit

Permalink
Add descriptions to ingest processors E-J
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodewig committed Sep 3, 2020
1 parent ba9ad8d commit e9d4aae
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { EuiComboBox, EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, ReactNode } from 'react';
import { flow } from 'fp-ts/lib/function';
import { map } from 'fp-ts/lib/Array';

Expand Down Expand Up @@ -68,13 +68,18 @@ export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) =>
<UseField<string> config={typeConfig} defaultValue={initialType} path="type">
{(typeField) => {
let selectedOptions: ProcessorTypeAndLabel[];
let description: string | ReactNode = '';

if (typeField.value?.length) {
const type = typeField.value;
const descriptor = getProcessorDescriptor(type);
selectedOptions = descriptor
? [{ label: descriptor.label, value: type }]
: // If there is no label for this processor type, just use the type as the label
[{ label: type, value: type }];
const processorDescriptor = getProcessorDescriptor(type);
if (processorDescriptor) {
description = processorDescriptor.description || '';
selectedOptions = [{ label: processorDescriptor.label, value: type }];
} else {
// If there is no label for this processor type, just use the type as the label
selectedOptions = [{ label: type, value: type }];
}
} else {
selectedOptions = [];
}
Expand Down Expand Up @@ -102,9 +107,7 @@ export const ProcessorTypeField: FunctionComponent<Props> = ({ initialType }) =>
<EuiFormRow
label={typeField.label}
labelAppend={typeField.labelAppend}
helpText={
typeof typeField.helpText === 'function' ? typeField.helpText() : typeField.helpText
}
helpText={typeof description === 'function' ? description() : description}
error={error}
isInvalid={isInvalid}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const fieldsConfig: FieldsConfig = {
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.',
defaultMessage: 'Output field. If empty, the input field is updated in place.',
}
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,7 @@ export const Gsub: FunctionComponent = () => {

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

<TargetField
helpText={
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.gsubForm.targetFieldHelpText"
defaultMessage="Field used to contain updated text. Defaults to {field}."
values={{
field: <EuiCode>{'field'}</EuiCode>,
}}
/>
}
/>
<TargetField />

<IgnoreMissingField />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,7 @@ export const HtmlStrip: FunctionComponent = () => {
)}
/>

<TargetField
helpText={
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.htmlStripForm.targetFieldHelpText"
defaultMessage="Field used to contain stripped text. Defaults to {field}."
values={{ field: <EuiCode>{'field'}</EuiCode> }}
/>
}
/>
<TargetField />

<IgnoreMissingField />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,7 @@ export const Join: FunctionComponent = () => {

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

<TargetField
helpText={
<FormattedMessage
id="xpack.ingestPipelines.pipelineEditor.joinForm.targetFieldHelpText"
defaultMessage="Field used to contain the joined value. Defaults to {field}."
values={{
field: <EuiCode>{'field'}</EuiCode>,
}}
/>
}
/>
<TargetField />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ export const Json: FunctionComponent = () => {
)}
/>

<TargetField
helpText={i18n.translate(
'xpack.ingestPipelines.pipelineEditor.jsonForm.targetFieldHelpText',
{ defaultMessage: 'Field used to contain the JSON object.' }
)}
/>
<TargetField />

<UseField
config={fieldsConfig.add_to_root}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

import { i18n } from '@kbn/i18n';
import { FunctionComponent } from 'react';
import React, { FunctionComponent, ReactNode } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCode, EuiLink } from '@elastic/eui';

import {
Append,
Expand Down Expand Up @@ -40,6 +42,7 @@ interface FieldDescriptor {
* A sentence case label that can be displayed to users
*/
label: string;
description?: string | ReactNode;
}

type MapProcessorTypeToDescriptor = Record<string, FieldDescriptor>;
Expand Down Expand Up @@ -121,69 +124,123 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = {
label: i18n.translate('xpack.ingestPipelines.processors.label.enrich', {
defaultMessage: 'Enrich',
}),
description: () => (
<FormattedMessage
id="xpack.ingestPipelines.processors.description.enrich"
defaultMessage="Adds enrich data to incoming documents based on an {enrichPolicyLink}."
values={{
enrichPolicyLink: (
<EuiLink external target="_blank" href={esDocUrl + '/ingest-enriching-data.html'}>
{'enrich policy'}
</EuiLink>
),
}}
/>
),
},
fail: {
FieldsComponent: Fail,
docLinkPath: '/fail-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.fail', {
defaultMessage: 'Fail',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.fail', {
defaultMessage:
'Returns a custom error message on failure. Often used to notify requesters of required conditions.',
}),
},
foreach: {
FieldsComponent: Foreach,
docLinkPath: '/foreach-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.foreach', {
defaultMessage: 'Foreach',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.foreach', {
defaultMessage: 'Applies an ingest processor to each value in an array.',
}),
},
geoip: {
FieldsComponent: GeoIP,
docLinkPath: '/geoip-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.geoip', {
defaultMessage: 'GeoIP',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.geoip', {
defaultMessage:
'Adds geo data based on an IP address. Uses geo data from a Maxmind database file.',
}),
},
grok: {
FieldsComponent: Grok,
docLinkPath: '/grok-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.grok', {
defaultMessage: 'Grok',
}),
description: () => (
<FormattedMessage
id="xpack.ingestPipelines.processors.description.grok"
defaultMessage="Uses {grokLink} expressions to extract matches from a field.."
values={{
grokLink: (
<EuiLink external target="_blank" href={esDocUrl + '/grok-processor.html'}>
{'grok'}
</EuiLink>
),
}}
/>
),
},
gsub: {
FieldsComponent: Gsub,
docLinkPath: '/gsub-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.gsub', {
defaultMessage: 'Gsub',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.gsub', {
defaultMessage: 'Uses a regular expression to replace field substrings.',
}),
},
html_strip: {
FieldsComponent: HtmlStrip,
docLinkPath: '/htmlstrip-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.htmlStrip', {
defaultMessage: 'HTML strip',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.htmlStrip', {
defaultMessage: 'Removes HTML tags from a field.',
}),
},
inference: {
FieldsComponent: Inference,
docLinkPath: '/inference-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.inference', {
defaultMessage: 'Inference',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.inference', {
defaultMessage:
'Uses a pre-trained data frame analytics model to infer against incoming data.',
}),
},
join: {
FieldsComponent: Join,
docLinkPath: '/join-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.join', {
defaultMessage: 'Join',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.join', {
defaultMessage:
'Joins array elements into a string. Inserts a separator between each element.',
}),
},
json: {
FieldsComponent: Json,
docLinkPath: '/json-processor.html',
label: i18n.translate('xpack.ingestPipelines.processors.label.json', {
defaultMessage: 'JSON',
}),
description: i18n.translate('xpack.ingestPipelines.processors.description.json', {
defaultMessage: 'Creates a JSON object from a compatible string.',
}),
},
kv: {
FieldsComponent: undefined, // TODO: Implement
Expand Down

0 comments on commit e9d4aae

Please sign in to comment.