Skip to content

Commit

Permalink
[Lens] fix Formula to Quick functions does not preserve custom format…
Browse files Browse the repository at this point in the history
…ting (#124840)

* [Lens] fix transitioning from Formula to Quick functions does not preserve chosen format

* linter
  • Loading branch information
mbondyra authored Feb 8, 2022
1 parent e312c36 commit 28d8bc8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 28d8bc8

Please sign in to comment.