Skip to content

Commit

Permalink
[Lens] Use a size of 5 for first string field in visualization (#64726)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wylie Conlon authored Apr 30, 2020
1 parent bcda109 commit 4e58d7a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1380,5 +1380,43 @@ describe('IndexPatternDimensionEditorPanel', () => {
},
});
});

it('does not set the size of the terms aggregation', () => {
const dragging = {
field: { type: 'string', name: 'mystring', aggregatable: true },
indexPatternId: 'foo',
};
const testState = dragDropState();
onDrop({
...defaultProps,
dragDropContext: {
...dragDropContext,
dragging,
},
droppedItem: dragging,
state: testState,
columnId: 'col2',
filterOperations: (op: OperationMetadata) => op.isBucketed,
layerId: 'myLayer',
});

expect(setState).toBeCalledTimes(1);
expect(setState).toHaveBeenCalledWith({
...testState,
layers: {
myLayer: {
...testState.layers.myLayer,
columnOrder: ['col1', 'col2'],
columns: {
...testState.layers.myLayer.columns,
col2: expect.objectContaining({
operationType: 'terms',
params: expect.objectContaining({ size: 3 }),
}),
},
},
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe('IndexPattern Data Source suggestions', () => {
id2: expect.objectContaining({
operationType: 'terms',
sourceField: 'source',
params: expect.objectContaining({ size: 5 }),
}),
id3: expect.objectContaining({
operationType: 'count',
Expand Down Expand Up @@ -388,6 +389,7 @@ describe('IndexPattern Data Source suggestions', () => {
id1: expect.objectContaining({
operationType: 'terms',
sourceField: 'source',
params: expect.objectContaining({ size: 5 }),
}),
id2: expect.objectContaining({
operationType: 'count',
Expand Down Expand Up @@ -779,7 +781,7 @@ describe('IndexPattern Data Source suggestions', () => {
expect(suggestions[0].table.columns[0].operation.isBucketed).toBeFalsy();
});

it('appends a terms column on string field', () => {
it('appends a terms column with default size on string field', () => {
const initialState = stateWithNonEmptyTables();
const suggestions = getDatasourceSuggestionsForField(initialState, '1', {
name: 'dest',
Expand All @@ -800,6 +802,7 @@ describe('IndexPattern Data Source suggestions', () => {
id1: expect.objectContaining({
operationType: 'terms',
sourceField: 'dest',
params: expect.objectContaining({ size: 3 }),
}),
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
OperationType,
} from './operations';
import { operationDefinitions } from './operations/definitions';
import { TermsIndexPatternColumn } from './operations/definitions/terms';
import { hasField } from './utils';
import {
IndexPattern,
Expand Down Expand Up @@ -232,6 +233,10 @@ function addFieldAsBucketOperation(
[newColumnId]: newColumn,
};

if (buckets.length === 0 && operation === 'terms') {
(newColumn as TermsIndexPatternColumn).params.size = 5;
}

const oldDateHistogramIndex = layer.columnOrder.findIndex(
columnId => layer.columns[columnId].operationType === 'date_histogram'
);
Expand Down Expand Up @@ -327,6 +332,9 @@ function createNewLayerWithBucketAggregation(
field,
suggestedPriority: undefined,
});
if (operation === 'terms') {
(column as TermsIndexPatternColumn).params.size = 5;
}

return {
indexPatternId: indexPattern.id,
Expand Down

0 comments on commit 4e58d7a

Please sign in to comment.