Skip to content

Commit 3f3c0ec

Browse files
[Ingest Pipelines] Processor forms for processors A-D (#72849)
* First few processors of the first batch - Also refactored options to live in scoped objects to avoid overriding type (important fix!) - Have not polished copy or form layout. * add type to shared imports * Refactors for repeated fields and added forms - date_index_name - dissect - dot_expander - drop Fields refactored: - Field - Ignore missing * Fix broken imports and some other small refactors * added text editor field and updated pattern and if fields * Large copy improvements and updates and other small refactors - Added help text for all fields - Updated layout so that required fields are always on first - Replaced circle radio group with a select drop down * update circle shape type field to select * Added "long" option for convert type * fix path import * fix types and i18n * add validation for dot expander fix append value to be a combobox * fix i18n Co-authored-by: Elastic Machine <[email protected]>
1 parent f98cf0e commit 3f3c0ec

File tree

26 files changed

+1347
-87
lines changed

26 files changed

+1347
-87
lines changed

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/field_components/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export { OnXJsonEditorUpdateHandler, XJsonEditor } from './xjson_editor';
7+
export { XJsonEditor } from './xjson_editor';
8+
export { TextEditor } from './text_editor';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { EuiPanel } from '@elastic/eui';
8+
import React, { FunctionComponent } from 'react';
9+
import { EuiFormRow } from '@elastic/eui';
10+
import {
11+
CodeEditor,
12+
FieldHook,
13+
getFieldValidityAndErrorMessage,
14+
} from '../../../../../../shared_imports';
15+
16+
interface Props {
17+
field: FieldHook<string>;
18+
editorProps: { [key: string]: any };
19+
}
20+
21+
export const TextEditor: FunctionComponent<Props> = ({ field, editorProps }) => {
22+
const { value, helpText, setValue, label } = field;
23+
const { errorMessage } = getFieldValidityAndErrorMessage(field);
24+
25+
return (
26+
<EuiFormRow
27+
label={label}
28+
helpText={helpText}
29+
isInvalid={typeof errorMessage === 'string'}
30+
error={errorMessage}
31+
fullWidth
32+
>
33+
<EuiPanel paddingSize="s" hasShadow={false}>
34+
<CodeEditor value={value} onChange={setValue} {...(editorProps as any)} />
35+
</EuiPanel>
36+
</EuiFormRow>
37+
);
38+
};

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/manage_processor_form/field_components/xjson_editor.tsx

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,20 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { EuiPanel } from '@elastic/eui';
87
import { XJsonLang } from '@kbn/monaco';
98
import React, { FunctionComponent, useCallback } from 'react';
10-
import { EuiFormRow } from '@elastic/eui';
11-
import {
12-
CodeEditor,
13-
FieldHook,
14-
getFieldValidityAndErrorMessage,
15-
Monaco,
16-
} from '../../../../../../shared_imports';
9+
import { FieldHook, Monaco } from '../../../../../../shared_imports';
1710

18-
export type OnXJsonEditorUpdateHandler<T = { [key: string]: any }> = (arg: {
19-
data: {
20-
raw: string;
21-
format(): T;
22-
};
23-
validate(): boolean;
24-
isValid: boolean | undefined;
25-
}) => void;
11+
import { TextEditor } from './text_editor';
2612

2713
interface Props {
2814
field: FieldHook<string>;
2915
editorProps: { [key: string]: any };
3016
}
3117

3218
export const XJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) => {
33-
const { value, helpText, setValue, label } = field;
19+
const { value, setValue } = field;
3420
const { xJson, setXJson, convertToJson } = Monaco.useXJsonMode(value);
35-
const { errorMessage } = getFieldValidityAndErrorMessage(field);
3621

3722
const onChange = useCallback(
3823
(s) => {
@@ -42,25 +27,18 @@ export const XJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) =>
4227
[setValue, setXJson, convertToJson]
4328
);
4429
return (
45-
<EuiFormRow
46-
label={label}
47-
helpText={helpText}
48-
isInvalid={typeof errorMessage === 'string'}
49-
error={errorMessage}
50-
fullWidth
51-
>
52-
<EuiPanel paddingSize="s" hasShadow={false}>
53-
<CodeEditor
54-
value={xJson}
55-
languageId={XJsonLang.ID}
56-
editorDidMount={(m) => {
57-
XJsonLang.registerGrammarChecker(m);
58-
}}
59-
options={{ minimap: { enabled: false } }}
60-
onChange={onChange}
61-
{...(editorProps as any)}
62-
/>
63-
</EuiPanel>
64-
</EuiFormRow>
30+
<TextEditor
31+
field={field}
32+
editorProps={{
33+
value: xJson,
34+
languageId: XJsonLang.ID,
35+
options: { minimap: { enabled: false } },
36+
editorDidMount: (m: any) => {
37+
XJsonLang.registerGrammarChecker(m);
38+
},
39+
onChange,
40+
...editorProps,
41+
}}
42+
/>
6543
);
6644
};

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@ export const ManageProcessorForm: FunctionComponent<Props> = ({
4040
const handleSubmit = useCallback(
4141
async (data: FormData, isValid: boolean) => {
4242
if (isValid) {
43-
const { type, customOptions, ...options } = data;
43+
const { type, customOptions, fields } = data;
4444
onSubmit({
4545
type,
46-
options: customOptions ? customOptions : options,
46+
options: customOptions ? customOptions : fields,
4747
});
4848
}
4949
},
5050
[onSubmit]
5151
);
5252

53+
const maybeProcessorOptions = processor?.options;
5354
const { form } = useForm({
54-
defaultValue: processor?.options,
55+
defaultValue: { fields: maybeProcessorOptions ?? {} },
5556
onSubmit: handleSubmit,
5657
});
5758

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {
1414
EuiFlyoutHeader,
1515
EuiFlyoutBody,
1616
EuiFlyoutFooter,
17-
EuiSpacer,
1817
EuiTabs,
1918
EuiTab,
2019
EuiTitle,
2120
EuiFlexGroup,
2221
EuiFlexItem,
22+
EuiSpacer,
2323
} from '@elastic/eui';
2424

2525
import { Form, FormDataProvider, FormHook } from '../../../../../shared_imports';

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import React, { FunctionComponent } from 'react';
8-
import { EuiHorizontalRule } from '@elastic/eui';
8+
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
99

1010
import { FormDataProvider } from '../../../../../shared_imports';
1111
import { ProcessorInternal } from '../../types';
@@ -36,6 +36,7 @@ export const ProcessorSettingsFields: FunctionComponent<Props> = ({ processor })
3636
return (
3737
<>
3838
<formDescriptor.FieldsComponent />
39+
<EuiSpacer size="m" />
3940
<CommonProcessorFields />
4041
</>
4142
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { FunctionComponent } from 'react';
8+
import { i18n } from '@kbn/i18n';
9+
10+
import {
11+
FIELD_TYPES,
12+
fieldValidators,
13+
UseField,
14+
ComboBoxField,
15+
} from '../../../../../../shared_imports';
16+
17+
import { FieldsConfig } from './shared';
18+
import { FieldNameField } from './common_fields/field_name_field';
19+
20+
const { emptyField } = fieldValidators;
21+
22+
const fieldsConfig: FieldsConfig = {
23+
value: {
24+
type: FIELD_TYPES.COMBO_BOX,
25+
deserializer: (v) => (Array.isArray(v) ? v : [String(v)]),
26+
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueFieldLabel', {
27+
defaultMessage: 'Value',
28+
}),
29+
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueFieldHelpText', {
30+
defaultMessage: 'The value to be appended by this processor.',
31+
}),
32+
validations: [
33+
{
34+
validator: emptyField(
35+
i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.valueRequiredError', {
36+
defaultMessage: 'A value to set is required.',
37+
})
38+
),
39+
},
40+
],
41+
},
42+
};
43+
44+
export const Append: FunctionComponent = () => {
45+
return (
46+
<>
47+
<FieldNameField
48+
helpText={i18n.translate('xpack.ingestPipelines.pipelineEditor.appendForm.fieldHelpText', {
49+
defaultMessage: 'The field to be appended to.',
50+
})}
51+
/>
52+
53+
<UseField config={fieldsConfig.value} component={ComboBoxField} path="fields.value" />
54+
</>
55+
);
56+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { FunctionComponent } from 'react';
8+
import { i18n } from '@kbn/i18n';
9+
10+
import { FIELD_TYPES, UseField, Field } from '../../../../../../shared_imports';
11+
12+
import { FieldsConfig } from './shared';
13+
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
14+
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+
};
27+
28+
export const Bytes: FunctionComponent = () => {
29+
return (
30+
<>
31+
<FieldNameField
32+
helpText={i18n.translate(
33+
'xpack.ingestPipelines.pipelineEditor.bytesForm.fieldNameHelpText',
34+
{ defaultMessage: 'The field to convert.' }
35+
)}
36+
/>
37+
38+
<UseField config={fieldsConfig.target_field} component={Field} path="fields.target_field" />
39+
40+
<IgnoreMissingField />
41+
</>
42+
);
43+
};

0 commit comments

Comments
 (0)