Skip to content

Commit

Permalink
Merge branch 'feature/ingest-node-pipelines' of github.com:elastic/ki…
Browse files Browse the repository at this point in the history
…bana into ingest-pipelines/simulate
  • Loading branch information
alisonelizabeth committed Apr 25, 2020
2 parents 2bd7408 + a2b4049 commit 9963448
Showing 1 changed file with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
import { parseJson, stringifyJson } from '../../lib';

const { emptyField, isJsonField } = fieldValidators;
Expand Down Expand Up @@ -78,27 +70,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<any, any>) => {
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);
},
},
],
Expand Down

0 comments on commit 9963448

Please sign in to comment.