Skip to content

Commit

Permalink
[Lens] dont use legacy metric in the suggestions (#197101)
Browse files Browse the repository at this point in the history
## Summary

Fixes #197078
  • Loading branch information
mbondyra authored Oct 22, 2024
1 parent cb56679 commit 6f44bf5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('metric_suggestions', () => {
expect(rest).toHaveLength(0);
expect(suggestion).toMatchInlineSnapshot(`
Object {
"hide": false,
"hide": true,
"previewIcon": [Function],
"score": 0.1,
"state": Object {
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('metric_suggestions', () => {
expect(rest).toHaveLength(0);
expect(suggestion).toMatchInlineSnapshot(`
Object {
"hide": false,
"hide": true,
"previewIcon": [Function],
"score": 0.1,
"state": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function getSuggestion(

return {
title,
hide: datasourceId === 'textBased',
hide: true,
score: 0.1,
previewIcon: IconChartMetric,
state: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('metric suggestions', () => {
// should ignore bucketed column for initial drag
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.51,
},
Expand Down Expand Up @@ -189,7 +189,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.51,
},
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.51,
},
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.52,
},
Expand Down Expand Up @@ -326,7 +326,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.52,
},
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('metric suggestions', () => {
breakdownByAccessor: bucketColumn.columnId,
},
title: 'Metric',
hide: true,
hide: false,
previewIcon: IconChartMetric,
score: 0.52,
},
Expand Down
13 changes: 9 additions & 4 deletions x-pack/plugins/lens/public/visualizations/metric/suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const getSuggestions: Visualization<MetricVisualizationState>['getSuggest

const bucketedColumns = table.columns.filter(({ operation }) => operation.isBucketed);

const hasInterval = bucketedColumns.some(({ operation }) => operation.scale === 'interval');

const unsupportedColumns = table.columns.filter(
({ operation }) => !supportedDataTypes.has(operation.dataType) && !operation.isBucketed
);
Expand Down Expand Up @@ -59,11 +61,10 @@ export const getSuggestions: Visualization<MetricVisualizationState>['getSuggest
layerId: table.layerId,
layerType: LayerTypes.DATA,
},
title: metricLabel,
title: metricColumns[0]?.operation.label || metricLabel,
previewIcon: IconChartMetric,
score: 0.5,
// don't show suggestions since we're in tech preview
hide: true,
hide: hasInterval,
};

const accessorMappings: Pick<MetricVisualizationState, 'metricAccessor' | 'breakdownByAccessor'> =
Expand All @@ -72,7 +73,11 @@ export const getSuggestions: Visualization<MetricVisualizationState>['getSuggest
breakdownByAccessor: bucketedColumns[0]?.columnId,
};

baseSuggestion.score += 0.01 * Object.values(accessorMappings).filter(Boolean).length;
baseSuggestion.score = Number(
(baseSuggestion.score + 0.01 * Object.values(accessorMappings).filter(Boolean).length).toFixed(
2
)
);

const suggestion = {
...baseSuggestion,
Expand Down

0 comments on commit 6f44bf5

Please sign in to comment.