[Lens] Remove Over time suggestions for numeric intervals (#78442)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
3d4f748d87
commit
7b1b36e38d
|
@ -1381,6 +1381,126 @@ describe('IndexPattern Data Source suggestions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('does not create an over time suggestion if tables with numeric buckets with time dimension', async () => {
|
||||
const initialState = testInitialState();
|
||||
const state: IndexPatternPrivateState = {
|
||||
...initialState,
|
||||
layers: {
|
||||
first: {
|
||||
indexPatternId: '1',
|
||||
columnOrder: ['colb', 'cola'],
|
||||
columns: {
|
||||
cola: {
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
sourceField: 'dest',
|
||||
label: 'Unique count of dest',
|
||||
operationType: 'cardinality',
|
||||
},
|
||||
colb: {
|
||||
label: 'My Op',
|
||||
dataType: 'number',
|
||||
isBucketed: true,
|
||||
operationType: 'range',
|
||||
sourceField: 'bytes',
|
||||
scale: 'interval',
|
||||
params: {
|
||||
type: 'histogram',
|
||||
maxBars: 100,
|
||||
ranges: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(getDatasourceSuggestionsFromCurrentState(state)).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
table: {
|
||||
isMultiRow: true,
|
||||
label: 'Over time',
|
||||
layerId: 'first',
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('adds date histogram over default time field for custom range intervals', async () => {
|
||||
const initialState = testInitialState();
|
||||
const state: IndexPatternPrivateState = {
|
||||
...initialState,
|
||||
layers: {
|
||||
first: {
|
||||
indexPatternId: '1',
|
||||
columnOrder: ['colb', 'cola'],
|
||||
columns: {
|
||||
cola: {
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
sourceField: 'dest',
|
||||
label: 'Unique count of dest',
|
||||
operationType: 'cardinality',
|
||||
},
|
||||
colb: {
|
||||
label: 'My Custom Range',
|
||||
dataType: 'string',
|
||||
isBucketed: true,
|
||||
operationType: 'range',
|
||||
sourceField: 'bytes',
|
||||
scale: 'ordinal',
|
||||
params: {
|
||||
type: 'range',
|
||||
maxBars: 100,
|
||||
ranges: [{ from: 1, to: 2, label: '' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(getDatasourceSuggestionsFromCurrentState(state)).toContainEqual(
|
||||
expect.objectContaining({
|
||||
table: {
|
||||
changeType: 'extended',
|
||||
columns: [
|
||||
{
|
||||
columnId: 'colb',
|
||||
operation: {
|
||||
dataType: 'string',
|
||||
isBucketed: true,
|
||||
label: 'My Custom Range',
|
||||
scale: 'ordinal',
|
||||
},
|
||||
},
|
||||
{
|
||||
columnId: 'id1',
|
||||
operation: {
|
||||
dataType: 'date',
|
||||
isBucketed: true,
|
||||
label: 'timestampLabel',
|
||||
scale: 'interval',
|
||||
},
|
||||
},
|
||||
{
|
||||
columnId: 'cola',
|
||||
operation: {
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
label: 'Unique count of dest',
|
||||
scale: undefined,
|
||||
},
|
||||
},
|
||||
],
|
||||
isMultiRow: true,
|
||||
label: 'Over time',
|
||||
layerId: 'first',
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('does not create an over time suggestion if there is no default time field', async () => {
|
||||
const initialState = testInitialState();
|
||||
const state: IndexPatternPrivateState = {
|
||||
|
|
|
@ -455,6 +455,10 @@ export function getDatasourceSuggestionsFromCurrentState(
|
|||
({ name }) => name === indexPattern.timeFieldName
|
||||
);
|
||||
|
||||
const hasNumericDimension =
|
||||
buckets.length === 1 &&
|
||||
buckets.some((columnId) => layer.columns[columnId].dataType === 'number');
|
||||
|
||||
const suggestions: Array<DatasourceSuggestion<IndexPatternPrivateState>> = [];
|
||||
if (metrics.length === 0) {
|
||||
// intermediary chart without metric, don't try to suggest reduced versions
|
||||
|
@ -482,7 +486,9 @@ export function getDatasourceSuggestionsFromCurrentState(
|
|||
} else {
|
||||
suggestions.push(...createSimplifiedTableSuggestions(state, layerId));
|
||||
|
||||
if (!timeDimension && timeField) {
|
||||
// base range intervals are of number dataType.
|
||||
// Custom range/intervals have a different dataType so they still receive the Over Time suggestion
|
||||
if (!timeDimension && timeField && !hasNumericDimension) {
|
||||
// suggest current configuration over time if there is a default time field
|
||||
// and no time dimension yet
|
||||
suggestions.push(createSuggestionWithDefaultDateHistogram(state, layerId, timeField));
|
||||
|
@ -653,9 +659,13 @@ function createSuggestionWithDefaultDateHistogram(
|
|||
field: timeField,
|
||||
suggestedPriority: undefined,
|
||||
});
|
||||
|
||||
const updatedLayer = {
|
||||
indexPatternId: layer.indexPatternId,
|
||||
columns: { ...layer.columns, [newId]: timeColumn },
|
||||
columns: {
|
||||
...layer.columns,
|
||||
[newId]: timeColumn,
|
||||
},
|
||||
columnOrder: [...buckets, newId, ...metrics],
|
||||
};
|
||||
return buildSuggestion({
|
||||
|
|
|
@ -126,8 +126,6 @@ function flipSeriesType(seriesType: SeriesType) {
|
|||
return 'bar_stacked';
|
||||
case 'bar':
|
||||
return 'bar_horizontal';
|
||||
case 'bar_horizontal_stacked':
|
||||
return 'bar_stacked';
|
||||
case 'bar_horizontal_percentage_stacked':
|
||||
return 'bar_percentage_stacked';
|
||||
case 'bar_percentage_stacked':
|
||||
|
|
Loading…
Reference in a new issue