From 2ed822b2b94cfe64cccc5abae262fe1388d9f7ab Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Fri, 24 Apr 2020 11:09:07 +0200 Subject: [PATCH] More lenient treatment of on-failure value - accept an empty string (strips out value) - accept an empty array (strips out value) - still only show if toggle is clicked - removed the message about not accepting an empty array for on- failure processors --- .../components/pipeline_form/schema.tsx | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/schema.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/schema.tsx index 55ee62132cf52..e1809069ac11c 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/schema.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/schema.tsx @@ -6,15 +6,7 @@ import { i18n } from '@kbn/i18n'; -import { - FormSchema, - FIELD_TYPES, - fieldValidators, - fieldFormatters, - isJSON, - isEmptyString, - ValidationFuncArg, -} from '../../../shared_imports'; +import { FormSchema, FIELD_TYPES, fieldValidators, fieldFormatters } from '../../../shared_imports'; const { emptyField, isJsonField } = fieldValidators; const { toInt } = fieldFormatters; @@ -97,27 +89,26 @@ export const pipelineFormSchema: FormSchema = { label: i18n.translate('xpack.ingestPipelines.form.onFailureFieldLabel', { defaultMessage: 'On-failure processors (optional)', }), - serializer: parseJson, + serializer: value => { + const result = parseJson(value); + // If an empty array was passed, strip out this value entirely. + if (!result.length) { + return undefined; + } + return result; + }, deserializer: stringifyJson, validations: [ { - validator: ({ value }: ValidationFuncArg) => { - if (isJSON(value)) { - const parsedJSON = JSON.parse(value); - if (!parsedJSON.length) { - return { - message: 'At least one on-failure processor must be defined.', - }; - } - } else { - if (!isEmptyString(value)) { - return { - message: i18n.translate('xpack.ingestPipelines.form.onFailureProcessorsJsonError', { - defaultMessage: 'The on-failure processors JSON is not valid.', - }), - }; - } + validator: validationArg => { + if (!validationArg.value) { + return; } + return isJsonField( + i18n.translate('xpack.ingestPipelines.form.onFailureProcessorsJsonError', { + defaultMessage: 'The on-failure processors JSON is not valid.', + }) + )(validationArg); }, }, ],