Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Jan 27, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -2175,7 +2175,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 @@ -2197,9 +2197,9 @@ describe('state_helpers', () => {
col1: { operationType: 'testIncompleteReference' },
},
});
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 @@ -867,11 +867,7 @@ export function updateLayerIndexPattern(
export function getErrorMessages(layer: IndexPatternLayer): string[] | undefined {
const errors: string[] = [];
Object.entries(layer.columns).forEach(([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) {
errors.push(...(def.getErrorMessage(layer, columnId) ?? []));
}
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