From 28d8bc810b5cc27a3184811b25f81fed3f95ba3d Mon Sep 17 00:00:00 2001 From: Marta Bondyra Date: Tue, 8 Feb 2022 13:36:19 +0100 Subject: [PATCH] [Lens] fix Formula to Quick functions does not preserve custom formatting (#124840) * [Lens] fix transitioning from Formula to Quick functions does not preserve chosen format * linter --- .../operations/layer_helpers.test.ts | 45 +++++++++++++++++++ .../operations/layer_helpers.ts | 1 + 2 files changed, 46 insertions(+) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts index dad1250b39e14..1b432c4a34add 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts @@ -2119,6 +2119,51 @@ describe('state_helpers', () => { }, }); }); + + it('should carry over a custom formatting when transitioning from a managed reference', () => { + const actual = replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1', 'col2'], + columns: { + col1: { + label: 'MY CUSTOM LABEL', + customLabel: true, + dataType: 'number', + operationType: 'formula', + isBucketed: false, + scale: 'ratio', + params: { + isFormulaBroken: false, + formula: 'average(bytes)', + format: { + id: 'number', + params: { decimals: 2 }, + }, + }, + references: [], + } as FormulaIndexPatternColumn, + }, + }, + indexPattern, + columnId: 'col1', + op: 'average', + field: indexPattern.fields[2], // bytes field + visualizationGroups: [], + shouldResetLabel: undefined, + }); + + expect(actual.columns.col1).toEqual( + expect.objectContaining({ + params: { + format: { + id: 'number', + params: { decimals: 2 }, + }, + }, + }) + ); + }); }); it('should allow making a replacement on an operation that is being referenced, even if it ends up invalid', () => { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts index 7985500798b38..438d728b7df1f 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts @@ -422,6 +422,7 @@ export function replaceColumn({ op, field, visualizationGroups, + incompleteParams: previousColumn, }); // if the formula label is not the default one, propagate it to the new operation