mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
🐛 fix duplicate suggestion issue + missing over time (#113449)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
1e7d4e1adf
commit
35e9f6ad6b
4 changed files with 104 additions and 3 deletions
|
@ -115,6 +115,7 @@ export function getSuggestions({
|
|||
} else {
|
||||
dataSourceSuggestions = datasource.getDatasourceSuggestionsFromCurrentState(
|
||||
datasourceState,
|
||||
(layerId) => isLayerSupportedByVisualization(layerId, [layerTypes.DATA]),
|
||||
activeData
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1704,6 +1704,103 @@ describe('IndexPattern Data Source suggestions', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('adds date histogram over default time field for tables without time dimension and a threshold', async () => {
|
||||
const initialState = testInitialState();
|
||||
const state: IndexPatternPrivateState = {
|
||||
...initialState,
|
||||
layers: {
|
||||
first: {
|
||||
indexPatternId: '1',
|
||||
columnOrder: ['cola', 'colb'],
|
||||
columns: {
|
||||
cola: {
|
||||
label: 'My Terms',
|
||||
customLabel: true,
|
||||
dataType: 'string',
|
||||
isBucketed: true,
|
||||
operationType: 'terms',
|
||||
sourceField: 'source',
|
||||
scale: 'ordinal',
|
||||
params: {
|
||||
orderBy: { type: 'alphabetical' },
|
||||
orderDirection: 'asc',
|
||||
size: 5,
|
||||
},
|
||||
},
|
||||
colb: {
|
||||
label: 'My Op',
|
||||
customLabel: true,
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
operationType: 'average',
|
||||
sourceField: 'bytes',
|
||||
scale: 'ratio',
|
||||
},
|
||||
},
|
||||
},
|
||||
threshold: {
|
||||
indexPatternId: '2',
|
||||
columnOrder: ['thresholda'],
|
||||
columns: {
|
||||
thresholda: {
|
||||
label: 'My Op',
|
||||
customLabel: true,
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
operationType: 'average',
|
||||
sourceField: 'bytes',
|
||||
scale: 'ratio',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
getSuggestionSubset(
|
||||
getDatasourceSuggestionsFromCurrentState(state, (layerId) => layerId !== 'threshold')
|
||||
)
|
||||
).toContainEqual(
|
||||
expect.objectContaining({
|
||||
table: {
|
||||
isMultiRow: true,
|
||||
changeType: 'extended',
|
||||
label: 'Over time',
|
||||
columns: [
|
||||
{
|
||||
columnId: 'cola',
|
||||
operation: {
|
||||
label: 'My Terms',
|
||||
dataType: 'string',
|
||||
isBucketed: true,
|
||||
scale: 'ordinal',
|
||||
},
|
||||
},
|
||||
{
|
||||
columnId: 'id1',
|
||||
operation: {
|
||||
label: 'timestampLabel',
|
||||
dataType: 'date',
|
||||
isBucketed: true,
|
||||
scale: 'interval',
|
||||
},
|
||||
},
|
||||
{
|
||||
columnId: 'colb',
|
||||
operation: {
|
||||
label: 'My Op',
|
||||
dataType: 'number',
|
||||
isBucketed: false,
|
||||
scale: 'ratio',
|
||||
},
|
||||
},
|
||||
],
|
||||
layerId: 'first',
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('does not create an over time suggestion if tables with numeric buckets with time dimension', async () => {
|
||||
const initialState = testInitialState();
|
||||
const state: IndexPatternPrivateState = {
|
||||
|
|
|
@ -350,9 +350,11 @@ function createNewLayerWithMetricAggregation(
|
|||
}
|
||||
|
||||
export function getDatasourceSuggestionsFromCurrentState(
|
||||
state: IndexPatternPrivateState
|
||||
state: IndexPatternPrivateState,
|
||||
filterLayers: (layerId: string) => boolean = () => true
|
||||
): Array<DatasourceSuggestion<IndexPatternPrivateState>> {
|
||||
const layers = Object.entries(state.layers || {});
|
||||
const layers = Object.entries(state.layers || {}).filter(([layerId]) => filterLayers(layerId));
|
||||
|
||||
if (layers.length > 1) {
|
||||
// Return suggestions that reduce the data to each layer individually
|
||||
return layers
|
||||
|
@ -394,7 +396,7 @@ export function getDatasourceSuggestionsFromCurrentState(
|
|||
}
|
||||
|
||||
return flatten(
|
||||
Object.entries(state.layers || {})
|
||||
layers
|
||||
.filter(([_id, layer]) => layer.columnOrder.length && layer.indexPatternId)
|
||||
.map(([layerId, layer]) => {
|
||||
const indexPattern = state.indexPatterns[layer.indexPatternId];
|
||||
|
|
|
@ -246,6 +246,7 @@ export interface Datasource<T = unknown, P = unknown> {
|
|||
) => Array<DatasourceSuggestion<T>>;
|
||||
getDatasourceSuggestionsFromCurrentState: (
|
||||
state: T,
|
||||
filterFn?: (layerId: string) => boolean,
|
||||
activeData?: Record<string, Datatable>
|
||||
) => Array<DatasourceSuggestion<T>>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue