Skip to content

Commit

Permalink
More lenient treatment of on-failure value
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jloleysens committed Apr 24, 2020
1 parent eba5305 commit 2ed822b
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';

const { emptyField, isJsonField } = fieldValidators;
const { toInt } = fieldFormatters;
Expand Down Expand Up @@ -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<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 2ed822b

Please sign in to comment.