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 duplicate suggestions on single-bucket charts #86996

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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