Skip to content

Commit

Permalink
Add custom serializer to overwrite the default one from the shared field
Browse files Browse the repository at this point in the history
  • Loading branch information
sabarasaba committed May 11, 2021
1 parent 0522a5c commit 3e25668
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const fieldsConfig: FieldsConfig = {
},
};

type Props = Partial<FieldConfig>;
type Props = Partial<FieldConfig<any>>;

export const IgnoreMissingField: FunctionComponent<Props> = (props) => (
<UseField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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';
import { from } from './shared';

export const RegisteredDomain: FunctionComponent = () => {
return (
Expand All @@ -24,7 +25,7 @@ export const RegisteredDomain: FunctionComponent = () => {

<TargetField />

<IgnoreMissingField defaultValue={true} />
<IgnoreMissingField defaultValue={true} serializer={from.undefinedIfValue(true)} />
</>
);
};

0 comments on commit 3e25668

Please sign in to comment.