Skip to content

Commit

Permalink
[Lens] Fix transferable logic to handle newer operations on datasourc…
Browse files Browse the repository at this point in the history
…e change (#96617) (#96797)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Marco Liberati <[email protected]>
  • Loading branch information
kibanamachine and dej611 authored Apr 12, 2021
1 parent 798a96a commit 01b2aaa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,38 @@ describe('state_helpers', () => {
});
});

it('should remove operations indirectly referencing unavailable fields', () => {
const layer: IndexPatternLayer = {
columnOrder: ['col1', 'col2'],
columns: {
col1: {
label: '',
dataType: 'number',
operationType: 'moving_average',
isBucketed: false,
scale: 'ratio',
references: ['col2'],
timeScale: undefined,
filter: undefined,
params: {
window: 7,
},
},
col2: {
dataType: 'number',
isBucketed: false,
label: '',
operationType: 'average',
sourceField: 'xxx',
},
},
indexPatternId: 'original',
};
const updatedLayer = updateLayerIndexPattern(layer, newIndexPattern);
expect(updatedLayer.columnOrder).toEqual([]);
expect(updatedLayer.columns).toEqual({});
});

it('should remove operations referencing fields with insufficient capabilities', () => {
const layer: IndexPatternLayer = {
columnOrder: ['col1', 'col2'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,17 @@ export function updateLayerIndexPattern(
layer: IndexPatternLayer,
newIndexPattern: IndexPattern
): IndexPatternLayer {
const keptColumns: IndexPatternLayer['columns'] = _.pickBy(layer.columns, (column) =>
isColumnTransferable(column, newIndexPattern)
);
const keptColumns: IndexPatternLayer['columns'] = _.pickBy(layer.columns, (column) => {
if ('references' in column) {
return (
isColumnTransferable(column, newIndexPattern) &&
column.references.every((columnId) =>
isColumnTransferable(layer.columns[columnId], newIndexPattern)
)
);
}
return isColumnTransferable(column, newIndexPattern);
});
const newColumns: IndexPatternLayer['columns'] = _.mapValues(keptColumns, (column) => {
const operationDefinition = operationDefinitionMap[column.operationType];
return operationDefinition.transfer
Expand Down

0 comments on commit 01b2aaa

Please sign in to comment.