diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/__snapshots__/popover_form.test.tsx.snap b/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/__snapshots__/popover_form.test.tsx.snap index 5f74967ff423c..966b3487ebfb2 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/__snapshots__/popover_form.test.tsx.snap +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/__snapshots__/popover_form.test.tsx.snap @@ -2,12 +2,12 @@ exports[`Transform: Aggregation Minimal initialization 1`] = ` ', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + test('Minimal initialization', () => { const defaultData: PivotAggsConfig = { agg: PIVOT_SUPPORTED_AGGS.CARDINALITY, @@ -37,4 +40,67 @@ describe('Transform: Aggregation ', () => { expect(wrapper).toMatchSnapshot(); }); + + test('preserves the field for unsupported aggs', async () => { + const mockOnChange = jest.fn(); + const { getByTestId } = render( + + + + ); + + const aggNameInput = getByTestId('transformAggName'); + fireEvent.change(aggNameInput, { + target: { value: 'betterName' }, + }); + + const applyButton = getByTestId('transformApplyAggChanges'); + fireEvent.click(applyButton); + + expect(mockOnChange).toHaveBeenCalledTimes(1); + expect(mockOnChange).toHaveBeenCalledWith({ + field: 'AvgTicketPrice', + keyed: true, + ranges: [ + { + to: 500, + }, + { + from: 500, + to: 700, + }, + { + from: 700, + }, + ], + // @ts-ignore + agg: 'range', + aggName: 'betterName', + dropDownName: 'AvgTicketPrice.ranges', + }); + }); }); diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx index 56eeea8a242c0..0585d4553a99c 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx @@ -100,8 +100,8 @@ export const PopoverForm: React.FC = ({ defaultData, otherAggNames, onCha ...aggConfigDef, agg, aggName, - field: resultField, dropDownName: defaultData.dropDownName, + ...(isUnsupportedAgg ? {} : { field: resultField }), }; return updatedItem; @@ -153,7 +153,7 @@ export const PopoverForm: React.FC = ({ defaultData, otherAggNames, onCha } return ( - + = ({ defaultData, otherAggNames, onCha fontSize="s" language="json" paddingSize="s" - style={{ width: '100%', height: '200px' }} + css={{ width: '100%', height: '200px' }} > {JSON.stringify(getEsAggFromAggConfig(defaultData), null, 2)}