From f18a66883374b8f1592ecd3ec6b1991983624158 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 10 May 2021 15:41:59 +0200 Subject: [PATCH 1/6] add support for registered_domain processor --- .../processors/registered_domain.test.tsx | 114 ++++++++++++++++++ .../processor_form/processors/index.ts | 1 + .../processors/registered_domain.tsx | 30 +++++ .../shared/map_processor_type_to_form.tsx | 20 +++ 4 files changed, 165 insertions(+) create mode 100644 x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx create mode 100644 x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx new file mode 100644 index 0000000000000..237c7e7058a16 --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx @@ -0,0 +1,114 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { act } from 'react-dom/test-utils'; +import { setup, SetupResult, getProcessorValue } from './processor.helpers'; + +// Default parameter values automatically added to the registered domain processor when saved +const defaultRegisteredDomainParameters = { + ignore_failure: undefined, + ignore_missing: undefined, + description: undefined, +}; + +const REGISTERED_DOMAIN_TYPE = 'registered_domain'; + +describe('Processor: Registered Domain', () => { + let onUpdate: jest.Mock; + let testBed: SetupResult; + + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + }); + + beforeEach(async () => { + onUpdate = jest.fn(); + + await act(async () => { + testBed = await setup({ + value: { + processors: [], + }, + onFlyoutOpen: jest.fn(), + onUpdate, + }); + }); + testBed.component.update(); + }); + + test('prevents form submission if required fields are not provided', async () => { + const { + actions: { addProcessor, saveNewProcessor, addProcessorType }, + form, + } = testBed; + + // Open flyout to add new processor + addProcessor(); + + // Add type (the other fields are not visible until a type is selected) + await addProcessorType(REGISTERED_DOMAIN_TYPE); + + // Click submit button with only the type defined + await saveNewProcessor(); + + // Expect form error as "field" is required parameter + expect(form.getErrorsMessages()).toEqual(['A field value is required.']); + }); + + test('saves with default parameter values', async () => { + const { + actions: { addProcessor, saveNewProcessor, addProcessorType }, + form, + } = testBed; + + // Open flyout to add new processor + addProcessor(); + // Add type (the other fields are not visible until a type is selected) + await addProcessorType(REGISTERED_DOMAIN_TYPE); + // Add "field" value (required) + form.setInputValue('fieldNameField.input', 'field_1'); + // Save the field + await saveNewProcessor(); + + const processors = getProcessorValue(onUpdate, REGISTERED_DOMAIN_TYPE); + expect(processors[0][REGISTERED_DOMAIN_TYPE]).toEqual({ + field: 'field_1', + ...defaultRegisteredDomainParameters, + }); + }); + + test('allows optional parameters to be set', async () => { + const { + actions: { addProcessor, addProcessorType, saveNewProcessor }, + form, + } = testBed; + + // Open flyout to add new processor + addProcessor(); + // Add type (the other fields are not visible until a type is selected) + await addProcessorType(REGISTERED_DOMAIN_TYPE); + // Add "field" value (required) + form.setInputValue('fieldNameField.input', 'field_1'); + + // Set optional parameteres + form.setInputValue('targetField.input', 'target_field'); + + // Save the field with new changes + await saveNewProcessor(); + + const processors = getProcessorValue(onUpdate, REGISTERED_DOMAIN_TYPE); + expect(processors[0][REGISTERED_DOMAIN_TYPE]).toEqual({ + field: 'field_1', + target_field: 'target_field', + ...defaultRegisteredDomainParameters, + }); + }); +}); diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/index.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/index.ts index 9dec9d3f0384f..4fb4365c477b5 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/index.ts +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/index.ts @@ -28,6 +28,7 @@ export { Json } from './json'; export { Kv } from './kv'; export { Lowercase } from './lowercase'; export { Pipeline } from './pipeline'; +export { RegisteredDomain } from './registered_domain'; export { Remove } from './remove'; export { Rename } from './rename'; export { Script } from './script'; diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx new file mode 100644 index 0000000000000..40c72de313d66 --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { FunctionComponent } from 'react'; +import { i18n } from '@kbn/i18n'; + +import { FieldNameField } from './common_fields/field_name_field'; +import { TargetField } from './common_fields/target_field'; +import { IgnoreMissingField } from './common_fields/ignore_missing_field'; + +export const RegisteredDomain: FunctionComponent = () => { + return ( + <> + + + + + + + ); +}; diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx index 5ab2d68aa193f..5b3a52ccd75a9 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx @@ -34,6 +34,7 @@ import { Kv, Lowercase, Pipeline, + RegisteredDomain, Remove, Rename, Script, @@ -518,6 +519,25 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = { }, }), }, + registered_domain: { + FieldsComponent: RegisteredDomain, + docLinkPath: '/registered-domain-processor.html', + label: i18n.translate('xpack.ingestPipelines.processors.label.registeredDomain', { + defaultMessage: 'Registered Domain', + }), + typeDescription: i18n.translate('xpack.ingestPipelines.processors.description.registeredDomain', { + defaultMessage: + 'Extracts the registered domain (also known as the effective top-level domain or eTLD), sub-domain, and top-level domain from a fully qualified domain name.', + }), + getDefaultDescription: ({ field }) => + i18n.translate('xpack.ingestPipelines.processors.defaultDescription.registeredDomain', { + defaultMessage: + 'Extracts the registered domain, sub-domain and top-level domain from "{field}"', + values: { + field + }, + }), + }, remove: { FieldsComponent: Remove, docLinkPath: '/remove-processor.html', From 0522a5cec42a7080becb89e3ad0126b67803be8a Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Mon, 10 May 2021 19:16:33 +0200 Subject: [PATCH 2/6] Ignore missing field should default to true --- .../processors/registered_domain.test.tsx | 31 +++++++------------ .../processors/registered_domain.tsx | 4 +-- .../shared/map_processor_type_to_form.tsx | 15 +++++---- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx index 237c7e7058a16..0ba9b5eb16e17 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx @@ -10,9 +10,10 @@ import { setup, SetupResult, getProcessorValue } from './processor.helpers'; // Default parameter values automatically added to the registered domain processor when saved const defaultRegisteredDomainParameters = { - ignore_failure: undefined, - ignore_missing: undefined, description: undefined, + if: undefined, + ignore_missing: true, + ignore_failure: undefined, }; const REGISTERED_DOMAIN_TYPE = 'registered_domain'; @@ -41,21 +42,21 @@ describe('Processor: Registered Domain', () => { onUpdate, }); }); + testBed.component.update(); + + // Open flyout to add new processor + testBed.actions.addProcessor(); + // Add type (the other fields are not visible until a type is selected) + await testBed.actions.addProcessorType(REGISTERED_DOMAIN_TYPE); }); test('prevents form submission if required fields are not provided', async () => { const { - actions: { addProcessor, saveNewProcessor, addProcessorType }, + actions: { saveNewProcessor }, form, } = testBed; - // Open flyout to add new processor - addProcessor(); - - // Add type (the other fields are not visible until a type is selected) - await addProcessorType(REGISTERED_DOMAIN_TYPE); - // Click submit button with only the type defined await saveNewProcessor(); @@ -65,14 +66,10 @@ describe('Processor: Registered Domain', () => { test('saves with default parameter values', async () => { const { - actions: { addProcessor, saveNewProcessor, addProcessorType }, + actions: { saveNewProcessor }, form, } = testBed; - // Open flyout to add new processor - addProcessor(); - // Add type (the other fields are not visible until a type is selected) - await addProcessorType(REGISTERED_DOMAIN_TYPE); // Add "field" value (required) form.setInputValue('fieldNameField.input', 'field_1'); // Save the field @@ -87,14 +84,10 @@ describe('Processor: Registered Domain', () => { test('allows optional parameters to be set', async () => { const { - actions: { addProcessor, addProcessorType, saveNewProcessor }, + actions: { saveNewProcessor }, form, } = testBed; - // Open flyout to add new processor - addProcessor(); - // Add type (the other fields are not visible until a type is selected) - await addProcessorType(REGISTERED_DOMAIN_TYPE); // Add "field" value (required) form.setInputValue('fieldNameField.input', 'field_1'); diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx index 40c72de313d66..b50d41021ea59 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx @@ -18,13 +18,13 @@ export const RegisteredDomain: FunctionComponent = () => { - + ); }; diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx index 5b3a52ccd75a9..099c5c60199ef 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx @@ -523,18 +523,21 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = { FieldsComponent: RegisteredDomain, docLinkPath: '/registered-domain-processor.html', label: i18n.translate('xpack.ingestPipelines.processors.label.registeredDomain', { - defaultMessage: 'Registered Domain', - }), - typeDescription: i18n.translate('xpack.ingestPipelines.processors.description.registeredDomain', { - defaultMessage: - 'Extracts the registered domain (also known as the effective top-level domain or eTLD), sub-domain, and top-level domain from a fully qualified domain name.', + defaultMessage: 'Registered domain', }), + typeDescription: i18n.translate( + 'xpack.ingestPipelines.processors.description.registeredDomain', + { + defaultMessage: + 'Extracts the registered domain (also known as the effective top-level domain or eTLD), sub-domain, and top-level domain from a fully qualified domain name.', + } + ), getDefaultDescription: ({ field }) => i18n.translate('xpack.ingestPipelines.processors.defaultDescription.registeredDomain', { defaultMessage: 'Extracts the registered domain, sub-domain and top-level domain from "{field}"', values: { - field + field, }, }), }, From 3e2566870809e67e6a906b43286320db0b04a575 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 11 May 2021 14:03:24 +0200 Subject: [PATCH 3/6] Add custom serializer to overwrite the default one from the shared field --- .../processors/registered_domain.test.tsx | 25 ++++++++++++++++++- .../common_fields/ignore_missing_field.tsx | 2 +- .../processors/registered_domain.tsx | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx index 0ba9b5eb16e17..962e099f5b667 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/registered_domain.test.tsx @@ -12,7 +12,7 @@ import { setup, SetupResult, getProcessorValue } from './processor.helpers'; const defaultRegisteredDomainParameters = { description: undefined, if: undefined, - ignore_missing: true, + ignore_missing: undefined, ignore_failure: undefined, }; @@ -82,6 +82,29 @@ describe('Processor: Registered Domain', () => { }); }); + test('should still send ignore_missing:false when the toggle is disabled', async () => { + const { + actions: { saveNewProcessor }, + form, + } = testBed; + + // Add "field" value (required) + form.setInputValue('fieldNameField.input', 'field_1'); + + // Disable ignore missing toggle + form.toggleEuiSwitch('ignoreMissingSwitch.input'); + + // Save the field with new changes + await saveNewProcessor(); + + const processors = getProcessorValue(onUpdate, REGISTERED_DOMAIN_TYPE); + expect(processors[0][REGISTERED_DOMAIN_TYPE]).toEqual({ + ...defaultRegisteredDomainParameters, + field: 'field_1', + ignore_missing: false, + }); + }); + test('allows optional parameters to be set', async () => { const { actions: { saveNewProcessor }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx index 744e9798c4fb0..2fe23cbedf694 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx @@ -43,7 +43,7 @@ export const fieldsConfig: FieldsConfig = { }, }; -type Props = Partial; +type Props = Partial>; export const IgnoreMissingField: FunctionComponent = (props) => ( { return ( @@ -24,7 +25,7 @@ export const RegisteredDomain: FunctionComponent = () => { - + ); }; From 36bb550e479ecbcedfff0def97d3e63731f1f540 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 11 May 2021 17:31:41 +0200 Subject: [PATCH 4/6] Use type casting instead of recurring to any --- .../processors/common_fields/ignore_missing_field.tsx | 2 +- .../processor_form/processors/registered_domain.tsx | 5 +++-- x-pack/plugins/ingest_pipelines/public/shared_imports.ts | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx index 2fe23cbedf694..744e9798c4fb0 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/common_fields/ignore_missing_field.tsx @@ -43,7 +43,7 @@ export const fieldsConfig: FieldsConfig = { }, }; -type Props = Partial>; +type Props = Partial; export const IgnoreMissingField: FunctionComponent = (props) => ( { return ( @@ -25,7 +26,7 @@ export const RegisteredDomain: FunctionComponent = () => { - + } /> ); }; diff --git a/x-pack/plugins/ingest_pipelines/public/shared_imports.ts b/x-pack/plugins/ingest_pipelines/public/shared_imports.ts index 4afd434b89372..8ed57221a1395 100644 --- a/x-pack/plugins/ingest_pipelines/public/shared_imports.ts +++ b/x-pack/plugins/ingest_pipelines/public/shared_imports.ts @@ -52,6 +52,7 @@ export { ValidationConfig, useFormData, FormOptions, + SerializerFunc, } from '../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib'; export { From 25912a8714c87dd85835153b5fe31630bc6dce1b Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 11 May 2021 18:16:08 +0200 Subject: [PATCH 5/6] Prettier fixes --- .../processor_form/processors/registered_domain.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx index 6cfb6d1aaae70..4118a125914b2 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/registered_domain.tsx @@ -26,7 +26,10 @@ export const RegisteredDomain: FunctionComponent = () => { - } /> + } + /> ); }; From 02558f493f7486df80e8db5c153e318ef93914e4 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Fri, 14 May 2021 15:12:38 +0200 Subject: [PATCH 6/6] Copy changes --- .../components/shared/map_processor_type_to_form.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx index 099c5c60199ef..b5e42ea56bdf8 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/map_processor_type_to_form.tsx @@ -529,13 +529,13 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = { 'xpack.ingestPipelines.processors.description.registeredDomain', { defaultMessage: - 'Extracts the registered domain (also known as the effective top-level domain or eTLD), sub-domain, and top-level domain from a fully qualified domain name.', + 'Extracts the registered domain (effective top-level domain), sub-domain, and top-level domain from a fully qualified domain name.', } ), getDefaultDescription: ({ field }) => i18n.translate('xpack.ingestPipelines.processors.defaultDescription.registeredDomain', { defaultMessage: - 'Extracts the registered domain, sub-domain and top-level domain from "{field}"', + 'Extracts the registered domain, sub-domain, and top-level domain from "{field}"', values: { field, },