[Lens] Fix wrong error detection on transition to Top values operation (#102384) (#102611)

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2021-06-18 06:51:55 -04:00 committed by GitHub
parent ef5da0fa6c
commit 0e04be09f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View file

@ -194,14 +194,16 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn, 'field
return { dataType: type as DataType, isBucketed: true, scale: 'ordinal' };
}
},
getErrorMessage: (layer, columnId, indexPattern) =>
[
getErrorMessage: (layer, columnId, indexPattern) => {
const messages = [
...(getInvalidFieldMessage(
layer.columns[columnId] as FieldBasedIndexPatternColumn,
indexPattern
) || []),
getDisallowedTermsMessage(layer, columnId, indexPattern) || '',
].filter(Boolean),
].filter(Boolean);
return messages.length ? messages : undefined;
},
isTransferable: (column, newIndexPattern) => {
const newField = newIndexPattern.getFieldByName(column.sourceField);

View file

@ -996,8 +996,8 @@ describe('terms', () => {
indexPatternId: '',
};
});
it('returns empty array', () => {
expect(termsOperation.getErrorMessage!(layer, 'col1', indexPattern)).toEqual([]);
it('returns undefined for no errors found', () => {
expect(termsOperation.getErrorMessage!(layer, 'col1', indexPattern)).toEqual(undefined);
});
it('returns error message if the sourceField does not exist in index pattern', () => {
layer = {

View file

@ -627,7 +627,7 @@ export function canTransition({
Boolean(newColumn) &&
!newLayer.incompleteColumns?.[columnId] &&
filterOperations(newColumn) &&
!newDefinition.getErrorMessage?.(newLayer, columnId, indexPattern)
!newDefinition.getErrorMessage?.(newLayer, columnId, indexPattern)?.length
);
} catch (e) {
return false;