[Lens] Fix crash in transition from unique count to last value (#88916)

* [Lens] Fix transition from unique count to last value

* Fix test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Wylie Conlon 2021-01-27 18:44:17 -05:00 committed by GitHub
parent 5ce916b308
commit 445cb2ef87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 10 deletions

View file

@ -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;
@ -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;
});

View file

@ -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);
}

View file

@ -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*');