Skip to content

Commit

Permalink
[Lens] Fix crash in transition from unique count to last value (#88916)
Browse files Browse the repository at this point in the history
* [Lens] Fix transition from unique count to last value

* Fix test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
Wylie Conlon and kibanamachine authored Jan 27, 2021
1 parent 5ce916b commit 445cb2e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ describe('state_helpers', () => {
expect(errors).toHaveLength(1);
});

it('should consider incompleteColumns before layer columns', () => {
it('should ignore incompleteColumns when checking for errors', () => {
const savedRef = jest.fn().mockReturnValue(['error 1']);
const incompleteRef = jest.fn();
operationDefinitionMap.testReference.getErrorMessage = savedRef;
Expand All @@ -2206,9 +2206,9 @@ describe('state_helpers', () => {
},
indexPattern
);
expect(savedRef).not.toHaveBeenCalled();
expect(incompleteRef).toHaveBeenCalled();
expect(errors).toBeUndefined();
expect(savedRef).toHaveBeenCalled();
expect(incompleteRef).not.toHaveBeenCalled();
expect(errors).toHaveLength(1);

delete operationDefinitionMap.testIncompleteReference;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,12 +870,7 @@ export function getErrorMessages(
): string[] | undefined {
const errors: string[] = Object.entries(layer.columns)
.flatMap(([columnId, column]) => {
// If we're transitioning to another operation, check for "new" incompleteColumns rather
// than "old" saved operation on the layer
const columnFinalRef =
layer.incompleteColumns?.[columnId]?.operationType || column.operationType;
const def = operationDefinitionMap[columnFinalRef];

const def = operationDefinitionMap[column.operationType];
if (def.getErrorMessage) {
return def.getErrorMessage(layer, columnId, indexPattern);
}
Expand Down
22 changes: 22 additions & 0 deletions x-pack/test/functional/apps/lens/smokescreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,28 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
);
});

it('should transition from unique count to last value', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();

await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension',
operation: 'cardinality',
field: 'ip',
});
await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-dimensionTrigger',
operation: 'last_value',
field: 'bytes',
isPreviousIncompatible: true,
});

expect(await PageObjects.lens.getDimensionTriggerText('lnsXY_yDimensionPanel')).to.eql(
'Last value of bytes'
);
});

it('should allow to change index pattern', async () => {
await PageObjects.lens.switchFirstLayerIndexPattern('log*');
expect(await PageObjects.lens.getFirstLayerIndexPattern()).to.equal('log*');
Expand Down

0 comments on commit 445cb2e

Please sign in to comment.