diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.test.tsx index dcb234b5489031..90bba1b4ed14ae 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.test.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.test.tsx @@ -395,4 +395,39 @@ describe('Pipeline Editor', () => { assertTestProcessor({ description: processorDescriptions.none, descriptionVisible: false }); }); }); + + describe('object values', () => { + const mockData: Pick = { + processors: [ + { + set: { + field: 'test', + value: { test: 'test' }, + }, + }, + { + append: { + field: 'test', + value: { test: 'test' }, + }, + }, + ], + }; + it('editor works when value is an object', async () => { + onUpdate = jest.fn(); + testBed = await setup({ + value: { + ...mockData, + }, + onFlyoutOpen: jest.fn(), + onUpdate, + }); + expect(testBed.find(`processors>0.inlineTextInputNonEditableText`).text()).toBe( + 'Sets value of "test" to "{"test":"test"}"' + ); + expect(testBed.find(`processors>1.inlineTextInputNonEditableText`).text()).toBe( + 'Appends "{"test":"test"}" to the "test" field' + ); + }); + }); }); 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 a4a838f92d1ab7..5d672deb739d3b 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 @@ -10,6 +10,7 @@ import React, { ReactNode } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiCode, EuiLink } from '@elastic/eui'; +import { stringifyValueDescription } from './stringify_value_description'; import { LicenseType } from '../../../../../types'; import { @@ -127,7 +128,7 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = { defaultMessage: 'Appends "{value}" to the "{field}" field', values: { field, - value, + value: stringifyValueDescription(value), }, }), }, @@ -810,7 +811,7 @@ export const mapProcessorTypeToDescriptor: MapProcessorTypeToDescriptor = { defaultMessage: 'Sets value of "{field}" to "{value}"', values: { field, - value, + value: stringifyValueDescription(value), }, }); }, diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/stringify_value_description.test.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/stringify_value_description.test.ts new file mode 100644 index 00000000000000..62389782a601da --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/stringify_value_description.test.ts @@ -0,0 +1,29 @@ +/* + * 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 { stringifyValueDescription } from './stringify_value_description'; + +describe('StringifyValueDescription', () => { + it('works for a json object', () => { + expect(stringifyValueDescription({ test: 'test' })).toEqual('{"test":"test"}'); + }); + it('works for an array', () => { + expect(stringifyValueDescription(['a', 'b'])).toEqual('["a","b"]'); + }); + it('works for a string', () => { + expect(stringifyValueDescription('test')).toEqual('test'); + }); + it('works for a number', () => { + expect(stringifyValueDescription(123)).toEqual('123'); + }); + it('empty string for undefined', () => { + expect(stringifyValueDescription(undefined)).toEqual(''); + }); + it('empty string for null', () => { + expect(stringifyValueDescription(null)).toEqual(''); + }); +}); diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/stringify_value_description.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/stringify_value_description.ts new file mode 100644 index 00000000000000..d2ad726aed64e1 --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/shared/stringify_value_description.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + +export const stringifyValueDescription = (value: unknown): string => { + if (!value) { + return ''; + } + if (typeof value === 'object') { + try { + // if the value is a json object, it will be stringified as json + return JSON.stringify(value); + } catch (e) { + // ignore any errors + } + } + // otherwise just return a stringified value + return String(value); +};