Skip to content

Commit

Permalink
[Lens] Fix duplicate suggestions on single-bucket charts (#86996)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wylie Conlon authored Dec 30, 2020
1 parent 5dd9c7d commit 83d9ef0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ describe('IndexPattern Data Source suggestions', () => {
expect(suggestions.length).toBe(6);
});

it('returns an only metric version of a given table', () => {
it('returns an only metric version of a given table, but does not include current state as reduced', () => {
const initialState = testInitialState();
const state: IndexPatternPrivateState = {
indexPatternRefs: [],
Expand Down Expand Up @@ -1953,6 +1953,21 @@ describe('IndexPattern Data Source suggestions', () => {
};

const suggestions = getSuggestionSubset(getDatasourceSuggestionsFromCurrentState(state));
expect(suggestions).not.toContainEqual(
expect.objectContaining({
table: expect.objectContaining({
changeType: 'reduced',
columns: [
expect.objectContaining({
operation: expect.objectContaining({ label: 'field2' }),
}),
expect.objectContaining({
operation: expect.objectContaining({ label: 'Average of field1' }),
}),
],
}),
})
);
expect(suggestions).toContainEqual(
expect.objectContaining({
table: expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,9 @@ function createSimplifiedTableSuggestions(state: IndexPatternPrivateState, layer
columnOrder: [...bucketedColumns, ...availableMetricColumns],
};

if (availableReferenceColumns.length) {
// Don't remove buckets when dealing with any refs. This can break refs.
if (availableBucketedColumns.length <= 1 || availableReferenceColumns.length) {
// Don't simplify when dealing with single-bucket table. Also don't break
// reference-based columns by removing buckets.
return [];
} else if (availableMetricColumns.length > 1) {
return [{ ...layer, columnOrder: [...bucketedColumns, availableMetricColumns[0]] }];
Expand All @@ -597,7 +598,6 @@ function createSimplifiedTableSuggestions(state: IndexPatternPrivateState, layer
availableReferenceColumns.length
? []
: availableMetricColumns.map((columnId) => {
// build suggestions with only metrics
return { ...layer, columnOrder: [columnId] };
})
)
Expand All @@ -606,8 +606,7 @@ function createSimplifiedTableSuggestions(state: IndexPatternPrivateState, layer
state,
layerId,
updatedLayer,
changeType:
layer.columnOrder.length === updatedLayer.columnOrder.length ? 'unchanged' : 'reduced',
changeType: 'reduced',
label:
updatedLayer.columnOrder.length === 1
? getMetricSuggestionTitle(updatedLayer, availableMetricColumns.length === 1)
Expand Down

0 comments on commit 83d9ef0

Please sign in to comment.