Skip to content

Commit

Permalink
[Ingest Pipelines] Processor forms for processors K-S (#75638) (#76762)
Browse files Browse the repository at this point in the history
* added kv processor form

* added lowercase processor form

* Added pipeline processor form

* added remove processor form

* added rename processor form

* Add script processor form

Also:

- Also refactored name of defaultBoolToUndef to undefinedIfValue
  to make it more broadly applicable for deserializing when
  default values have been provided
- Refactor to pass in original processor options value so that
  a form can initialize based on those values

* Updated the existing set processor form

- also fixed a bug that would render a horizontal line even if
  the form has no fields of its own (like the drop processor form)

* Added set_security_user form

* Added split processor form

- also added comments to set_security_user processor

* added sort processor form

* fix: duplicate i18n identifier

* added field to kv processor form for trim value

* replaced all editor heights with a clearer indication of the source of common heights

* remove unused translations

* remove unused translation

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jloleysens and elasticmachine authored Sep 8, 2020
1 parent fdce4e1 commit 495c7f8
Show file tree
Hide file tree
Showing 31 changed files with 1,011 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ interface Props {
editorProps: { [key: string]: any };
}

const defaultEditorOptions = {
minimap: { enabled: false },
lineNumbers: 'off',
};

export const XJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) => {
const { value, setValue } = field;
const { xJson, setXJson, convertToJson } = Monaco.useXJsonMode(value);
Expand All @@ -31,7 +36,7 @@ export const XJsonEditor: FunctionComponent<Props> = ({ field, editorProps }) =>
editorProps={{
value: xJson,
languageId: XJsonLang.ID,
options: { minimap: { enabled: false } },
options: defaultEditorOptions,
onChange,
...editorProps,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ export const ProcessorSettingsFields: FunctionComponent<Props> = ({ processor })
const formDescriptor = getProcessorDescriptor(type as any);

if (formDescriptor?.FieldsComponent) {
const renderedFields = (
<formDescriptor.FieldsComponent
key={type}
initialFieldValues={processor?.options}
/>
);
return (
<>
<formDescriptor.FieldsComponent key={type} />
<EuiHorizontalRule />
{renderedFields ? (
<>
{renderedFields}
<EuiHorizontalRule />
</>
) : (
renderedFields
)}
<CommonProcessorFields />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
} from '../../../../../../../shared_imports';

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

const ignoreFailureConfig: FieldConfig = {
defaultValue: false,
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(false),
serializer: from.undefinedIfValue(false),
label: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.commonFields.ignoreFailureFieldLabel',
{
Expand Down Expand Up @@ -64,8 +64,11 @@ export const CommonProcessorFields: FunctionComponent = () => {
componentProps={{
editorProps: {
languageId: 'painless',
height: 75,
options: { minimap: { enabled: false } },
height: EDITOR_PX_HEIGHT.extraSmall,
options: {
lineNumbers: 'off',
minimap: { enabled: false },
},
},
}}
path="fields.if"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const fieldsConfig: FieldsConfig = {
type: FIELD_TYPES.TOGGLE,
defaultValue: false,
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(false),
serializer: from.undefinedIfValue(false),
label: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.commonFields.ignoreMissingFieldLabel',
{
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: 'Field to assign the value to. If empty, the field is updated in-place.',
}
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
const { emptyField, isJsonField } = fieldValidators;

import { XJsonEditor } from '../field_components';
import { EDITOR_PX_HEIGHT } from './shared';

const customConfig: FieldConfig = {
type: FIELD_TYPES.TEXT,
Expand Down Expand Up @@ -78,7 +79,7 @@ export const Custom: FunctionComponent<Props> = ({ defaultOptions }) => {
componentProps={{
editorProps: {
'data-test-subj': 'processorOptionsEditor',
height: 300,
height: EDITOR_PX_HEIGHT.large,
'aria-label': i18n.translate(
'xpack.ingestPipelines.pipelineEditor.customForm.optionsFieldAriaLabel',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {

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

const { emptyField } = fieldValidators;

Expand Down Expand Up @@ -80,7 +81,7 @@ export const Dissect: FunctionComponent = () => {
component={TextEditor}
componentProps={{
editorProps: {
height: 75,
height: EDITOR_PX_HEIGHT.extraSmall,
options: { minimap: { enabled: false } },
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const fieldsConfig: FieldsConfig = {
type: FIELD_TYPES.TOGGLE,
defaultValue: true,
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef,
serializer: from.undefinedIfValue,
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.enrichForm.overrideFieldLabel', {
defaultMessage: 'Override',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FIELD_TYPES, fieldValidators, UseField } from '../../../../../../shared
import { XJsonEditor } from '../field_components';

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

const { emptyField, isJsonField } = fieldValidators;

Expand All @@ -31,15 +31,18 @@ const fieldsConfig: FieldsConfig = {
validations: [
{
validator: emptyField(
i18n.translate('xpack.ingestPipelines.pipelineEditor.failForm.processorRequiredError', {
defaultMessage: 'A processor is required.',
})
i18n.translate(
'xpack.ingestPipelines.pipelineEditor.foreachForm.processorRequiredError',
{
defaultMessage: 'A processor is required.',
}
)
),
},
{
validator: isJsonField(
i18n.translate(
'xpack.ingestPipelines.pipelineEditor.failForm.processorInvalidJsonError',
'xpack.ingestPipelines.pipelineEditor.foreachForm.processorInvalidJsonError',
{
defaultMessage: 'Invalid JSON',
}
Expand All @@ -64,9 +67,9 @@ export const Foreach: FunctionComponent = () => {
component={XJsonEditor}
componentProps={{
editorProps: {
height: 200,
height: EDITOR_PX_HEIGHT.medium,
'aria-label': i18n.translate(
'xpack.ingestPipelines.pipelineEditor.customForm.optionsFieldAriaLabel',
'xpack.ingestPipelines.pipelineEditor.foreachForm.optionsFieldAriaLabel',
{
defaultMessage: 'Configuration JSON editor',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const fieldsConfig: FieldsConfig = {
type: FIELD_TYPES.TOGGLE,
defaultValue: true,
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(true),
serializer: from.undefinedIfValue(true),
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.geoIPForm.firstOnlyFieldLabel', {
defaultMessage: 'First only',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { XJsonEditor } from '../field_components';

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

const { emptyField, isJsonField } = fieldValidators;

Expand Down Expand Up @@ -80,7 +80,7 @@ const fieldsConfig: FieldsConfig = {
type: FIELD_TYPES.TOGGLE,
defaultValue: false,
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(false),
serializer: from.undefinedIfValue(false),
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.grokForm.traceMatchFieldLabel', {
defaultMessage: 'Trace match',
}),
Expand Down Expand Up @@ -110,7 +110,7 @@ export const Grok: FunctionComponent = () => {
config={fieldsConfig.pattern_definitions}
componentProps={{
editorProps: {
height: 200,
height: EDITOR_PX_HEIGHT.medium,
'aria-label': i18n.translate(
'xpack.ingestPipelines.pipelineEditor.grokForm.patternDefinitionsAriaLabel',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FIELD_TYPES, fieldValidators, UseField, Field } from '../../../../../..

import { TextEditor } from '../field_components';

import { FieldsConfig } from './shared';
import { EDITOR_PX_HEIGHT, 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';
Expand Down Expand Up @@ -78,7 +78,7 @@ export const Gsub: FunctionComponent = () => {
component={TextEditor}
componentProps={{
editorProps: {
height: 75,
height: EDITOR_PX_HEIGHT.extraSmall,
options: { minimap: { enabled: false } },
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ export { HtmlStrip } from './html_strip';
export { Inference } from './inference';
export { Join } from './join';
export { Json } from './json';
export { Kv } from './kv';
export { Lowercase } from './lowercase';
export { Pipeline } from './pipeline';
export { Remove } from './remove';
export { Rename } from './rename';
export { Script } from './script';
export { SetProcessor } from './set';
export { SetSecurityUser } from './set_security_user';
export { Split } from './split';
export { Sort } from './sort';

export { FormFieldsComponent } from './shared';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { XJsonEditor } from '../field_components';

import { TargetField } from './common_fields/target_field';

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

const { emptyField, isJsonField } = fieldValidators;

Expand Down Expand Up @@ -177,7 +177,7 @@ export const Inference: FunctionComponent = () => {
component={XJsonEditor}
componentProps={{
editorProps: {
height: 200,
height: EDITOR_PX_HEIGHT.medium,
options: { minimap: { enabled: false } },
},
}}
Expand All @@ -192,7 +192,7 @@ export const Inference: FunctionComponent = () => {
component={XJsonEditor}
componentProps={{
editorProps: {
height: 200,
height: EDITOR_PX_HEIGHT.medium,
options: { minimap: { enabled: false } },
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const fieldsConfig: FieldsConfig = {
{
validator: emptyField(
i18n.translate('xpack.ingestPipelines.pipelineEditor.joinForm.separatorRequiredError', {
defaultMessage: 'A separator value is required.',
defaultMessage: 'A value is required.',
})
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const fieldsConfig: FieldsConfig = {
defaultMessage: 'Add to root',
}),
deserializer: to.booleanOrUndef,
serializer: from.defaultBoolToUndef(false),
serializer: from.undefinedIfValue(false),
helpText: i18n.translate(
'xpack.ingestPipelines.pipelineEditor.jsonForm.addToRootFieldHelpText',
{
Expand Down
Loading

0 comments on commit 495c7f8

Please sign in to comment.