Skip to content

Commit 0daae40

Browse files
committed
Refactor to use new shared target_field component, and fix JSON serializer bug
1 parent daed879 commit 0daae40

File tree

12 files changed

+104
-171
lines changed

12 files changed

+104
-171
lines changed

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/bytes.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,9 @@
77
import React, { FunctionComponent } from 'react';
88
import { i18n } from '@kbn/i18n';
99

10-
import { FIELD_TYPES, UseField, Field } from '../../../../../../shared_imports';
11-
12-
import { FieldsConfig } from './shared';
1310
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
1411
import { FieldNameField } from './common_fields/field_name_field';
15-
16-
const fieldsConfig: FieldsConfig = {
17-
target_field: {
18-
type: FIELD_TYPES.TEXT,
19-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldLabel', {
20-
defaultMessage: 'Target field (optional)',
21-
}),
22-
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.bytesForm.targetFieldHelpText', {
23-
defaultMessage: 'The field to assign the converted value to',
24-
}),
25-
},
26-
};
12+
import { TargetField } from './common_fields/target_field';
2713

2814
export const Bytes: FunctionComponent = () => {
2915
return (
@@ -35,7 +21,7 @@ export const Bytes: FunctionComponent = () => {
3521
)}
3622
/>
3723

38-
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
24+
<TargetField />
3925

4026
<IgnoreMissingField />
4127
</>

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/circle.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {
1111
FIELD_TYPES,
1212
fieldValidators,
1313
UseField,
14-
Field,
1514
SelectField,
1615
NumericField,
1716
} from '../../../../../../shared_imports';
1817

1918
import { FieldsConfig } from './shared';
2019
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
2120
import { FieldNameField } from './common_fields/field_name_field';
21+
import { TargetField } from './common_fields/target_field';
2222

2323
const { emptyField } = fieldValidators;
2424

@@ -60,6 +60,7 @@ const fieldsConfig: FieldsConfig = {
6060
},
6161
shape_type: {
6262
type: FIELD_TYPES.SELECT,
63+
serializer: String,
6364
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.circleForm.shapeTypeFieldLabel', {
6465
defaultMessage: 'Shape type',
6566
}),
@@ -77,20 +78,6 @@ const fieldsConfig: FieldsConfig = {
7778
},
7879
],
7980
},
80-
81-
/* Optional fields config */
82-
target_field: {
83-
type: FIELD_TYPES.TEXT,
84-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.circleForm.targetFieldLabel', {
85-
defaultMessage: 'Target field (optional)',
86-
}),
87-
helpText: i18n.translate(
88-
'xpack.ingestPipelines.pipelineEditor.circleForm.targetFieldHelpText',
89-
{
90-
defaultMessage: 'By default field is updated in-place.',
91-
}
92-
),
93-
},
9481
};
9582

9683
export const Circle: FunctionComponent = () => {
@@ -135,7 +122,7 @@ export const Circle: FunctionComponent = () => {
135122
path="fields.shape_type"
136123
/>
137124

138-
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
125+
<TargetField />
139126

140127
<IgnoreMissingField />
141128
</>

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/common_fields/target_field.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const TargetField: FunctionComponent<Props> = (props) => {
3434
<UseField
3535
config={{
3636
...fieldsConfig.target_field,
37-
helpText: props.helpText ?? fieldsConfig.target_field.helpText,
3837
...props,
3938
}}
4039
component={Field}

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/convert.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
FIELD_TYPES,
1212
fieldValidators,
1313
UseField,
14-
Field,
1514
SelectField,
1615
} from '../../../../../../shared_imports';
1716

1817
import { FieldsConfig } from './shared';
1918
import { FieldNameField } from './common_fields/field_name_field';
2019
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
20+
import { TargetField } from './common_fields/target_field';
2121

2222
const { emptyField } = fieldValidators;
2323

@@ -42,19 +42,6 @@ const fieldsConfig: FieldsConfig = {
4242
},
4343
],
4444
},
45-
/* Optional fields config */
46-
target_field: {
47-
type: FIELD_TYPES.TEXT,
48-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldLabel', {
49-
defaultMessage: 'Target field (optional)',
50-
}),
51-
helpText: i18n.translate(
52-
'xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldHelpText',
53-
{
54-
defaultMessage: 'The field to assign the converted value to.',
55-
}
56-
),
57-
},
5845
};
5946

6047
export const Convert: FunctionComponent = () => {
@@ -128,7 +115,14 @@ export const Convert: FunctionComponent = () => {
128115
path="fields.type"
129116
/>
130117

131-
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
118+
<TargetField
119+
helpText={i18n.translate(
120+
'xpack.ingestPipelines.pipelineEditor.convertForm.targetFieldHelpText',
121+
{
122+
defaultMessage: 'The field to assign the converted value to.',
123+
}
124+
)}
125+
/>
132126

133127
<IgnoreMissingField />
134128
</>

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/date.tsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919

2020
import { FieldsConfig, to } from './shared';
2121
import { FieldNameField } from './common_fields/field_name_field';
22+
import { TargetField } from './common_fields/target_field';
2223

2324
const { minLengthField } = fieldValidators;
2425

@@ -49,22 +50,6 @@ const fieldsConfig: FieldsConfig = {
4950
],
5051
},
5152
/* Optional fields config */
52-
target_field: {
53-
type: FIELD_TYPES.TEXT,
54-
serializer: (v) => (v ? undefined : v),
55-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.dateForm.targetFieldFieldLabel', {
56-
defaultMessage: 'Target field (optional)',
57-
}),
58-
helpText: (
59-
<FormattedMessage
60-
id="xpack.ingestPipelines.pipelineEditor.dateForm.targetFieldHelpText"
61-
defaultMessage="The field that will hold the parsed date. Default field is {defaultField}."
62-
values={{
63-
defaultField: <EuiCode inline>{'@timestamp'}</EuiCode>,
64-
}}
65-
/>
66-
),
67-
},
6853
timezone: {
6954
type: FIELD_TYPES.TEXT,
7055
serializer: (v) => (v ? v : undefined),
@@ -110,7 +95,17 @@ export const DateProcessor: FunctionComponent = () => {
11095

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

113-
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
98+
<TargetField
99+
helpText={
100+
<FormattedMessage
101+
id="xpack.ingestPipelines.pipelineEditor.dateForm.targetFieldHelpText"
102+
defaultMessage="The field that will hold the parsed date. Default field is {defaultField}."
103+
values={{
104+
defaultField: <EuiCode inline>{'@timestamp'}</EuiCode>,
105+
}}
106+
/>
107+
}
108+
/>
114109

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

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/enrich.tsx

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import {
1414
ToggleField,
1515
NumericField,
1616
SelectField,
17+
ValidationConfig,
1718
} from '../../../../../../shared_imports';
1819

1920
import { FieldNameField } from './common_fields/field_name_field';
2021
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
22+
import { TargetField } from './common_fields/target_field';
23+
2124
import { FieldsConfig, from, to } from './shared';
2225

2326
const { emptyField, numberSmallerThanField, numberGreaterThanField } = fieldValidators;
@@ -41,6 +44,14 @@ const maxMatchesValidators = {
4144
}),
4245
};
4346

47+
const targetFieldValidator: ValidationConfig = {
48+
validator: emptyField(
49+
i18n.translate('xpack.ingestPipelines.pipelineEditor.enrichForm.targetFieldRequiredError', {
50+
defaultMessage: 'A target field value is required.',
51+
})
52+
),
53+
};
54+
4455
const fieldsConfig: FieldsConfig = {
4556
/* Required fields config */
4657
policy_name: {
@@ -65,31 +76,6 @@ const fieldsConfig: FieldsConfig = {
6576
],
6677
},
6778

68-
target_field: {
69-
type: FIELD_TYPES.TEXT,
70-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.enrichForm.targetFieldLabel', {
71-
defaultMessage: 'Target field',
72-
}),
73-
helpText: i18n.translate(
74-
'xpack.ingestPipelines.pipelineEditor.enrichForm.targetFieldHelpText',
75-
{
76-
defaultMessage: 'Field added to incoming documents to contain enrich data.',
77-
}
78-
),
79-
validations: [
80-
{
81-
validator: emptyField(
82-
i18n.translate(
83-
'xpack.ingestPipelines.pipelineEditor.enrichForm.targetFieldRequiredError',
84-
{
85-
defaultMessage: 'A target field value is required.',
86-
}
87-
)
88-
),
89-
},
90-
],
91-
},
92-
9379
/* Optional fields config */
9480
override: {
9581
type: FIELD_TYPES.TOGGLE,
@@ -173,7 +159,18 @@ export const Enrich: FunctionComponent = () => {
173159

174160
<UseField config={fieldsConfig.policy_name} component={Field} path="fields.policy_name" />
175161

176-
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
162+
<TargetField
163+
label={i18n.translate('xpack.ingestPipelines.pipelineEditor.enrichForm.targetFieldLabel', {
164+
defaultMessage: 'Target field',
165+
})}
166+
helpText={i18n.translate(
167+
'xpack.ingestPipelines.pipelineEditor.enrichForm.targetFieldHelpText',
168+
{
169+
defaultMessage: 'Field added to incoming documents to contain enrich data.',
170+
}
171+
)}
172+
validations={[targetFieldValidator]}
173+
/>
177174

178175
<UseField config={fieldsConfig.override} component={ToggleField} path="fields.override" />
179176

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/geoip.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,10 @@ import {
2020
import { FieldNameField } from './common_fields/field_name_field';
2121
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
2222
import { FieldsConfig, from, to } from './shared';
23+
import { TargetField } from './common_fields/target_field';
2324

2425
const fieldsConfig: FieldsConfig = {
2526
/* Optional field config */
26-
target_field: {
27-
type: FIELD_TYPES.TEXT,
28-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.geoIPForm.targetFieldLabel', {
29-
defaultMessage: 'Target field (optional)',
30-
}),
31-
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.geoIPForm.targetFieldHelpText', {
32-
defaultMessage:
33-
'The field that will hold the geographical information looked up from the Maxmind database.',
34-
}),
35-
},
3627
database_file: {
3728
type: FIELD_TYPES.TEXT,
3829
serializer: (v) => (v === 'GeoLite2-City.mmdb' ? undefined : v),
@@ -84,7 +75,15 @@ export const GeoIP: FunctionComponent = () => {
8475
)}
8576
/>
8677

87-
<UseField component={Field} config={fieldsConfig.target_field} path="fields.target_field" />
78+
<TargetField
79+
helpText={i18n.translate(
80+
'xpack.ingestPipelines.pipelineEditor.geoIPForm.targetFieldHelpText',
81+
{
82+
defaultMessage:
83+
'The field that will hold the geographical information looked up from the Maxmind database.',
84+
}
85+
)}
86+
/>
8887

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

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/processors/gsub.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { TextEditor } from '../field_components';
1414
import { FieldsConfig } from './shared';
1515
import { FieldNameField } from './common_fields/field_name_field';
1616
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
17+
import { TargetField } from './common_fields/target_field';
1718

1819
const { emptyField } = fieldValidators;
1920

@@ -58,18 +59,6 @@ const fieldsConfig: FieldsConfig = {
5859
},
5960
],
6061
},
61-
62-
/* Optional fields config */
63-
target_field: {
64-
type: FIELD_TYPES.TEXT,
65-
deserializer: String,
66-
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.gsubForm.targetFieldLabel', {
67-
defaultMessage: 'Target field (optional)',
68-
}),
69-
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.gsubForm.targetFieldHelpText', {
70-
defaultMessage: 'The field to assign the converted value to.',
71-
}),
72-
},
7362
};
7463

7564
export const Gsub: FunctionComponent = () => {
@@ -96,7 +85,14 @@ export const Gsub: FunctionComponent = () => {
9685

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

99-
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
88+
<TargetField
89+
helpText={i18n.translate(
90+
'xpack.ingestPipelines.pipelineEditor.gsubForm.targetFieldHelpText',
91+
{
92+
defaultMessage: 'The field to assign the converted value to.',
93+
}
94+
)}
95+
/>
10096

10197
<IgnoreMissingField />
10298
</>

0 commit comments

Comments
 (0)