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] dont use legacy metric in the suggestions #197101

Merged
merged 2 commits into from
Oct 22, 2024
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 @@ -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
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