feat(query): remove redundant metric label truncation (#492)

* feat: remove redundant metric label truncation

* fix lint
This commit is contained in:
Ville Brofeldt 2020-05-15 19:51:17 +03:00 committed by Yongjie Zhao
parent aefd587ee5
commit dfb5ac42dd
2 changed files with 2 additions and 23 deletions

View File

@ -2,19 +2,11 @@ import { QueryFormDataMetric } from './types/QueryFormData';
import { QueryObjectMetric } from './types/Query';
import { AdhocMetric } from './types/Metric';
export const LABEL_MAX_LENGTH = 43;
function getDefaultLabel(metric: AdhocMetric) {
let label: string;
if (metric.expressionType === 'SIMPLE') {
label = `${metric.aggregate}(${metric.column.columnName})`;
} else {
label = metric.sqlExpression;
return `${metric.aggregate}(${metric.column.columnName})`;
}
return label.length <= LABEL_MAX_LENGTH
? label
: `${label.slice(0, Math.max(0, LABEL_MAX_LENGTH - 3))}...`;
return metric.sqlExpression;
}
export default function convertMetric(metric: QueryFormDataMetric): QueryObjectMetric {
@ -24,9 +16,6 @@ export default function convertMetric(metric: QueryFormDataMetric): QueryObjectM
label: metric,
};
} else {
// Note we further sanitize the metric label for BigQuery datasources
// TODO: move this logic to the client once client has more info on the
// the datasource
const label = metric.label ?? getDefaultLabel(metric);
formattedMetric = {
...metric,

View File

@ -1,5 +1,4 @@
import { ColumnType, convertMetric } from '../src';
import { LABEL_MAX_LENGTH } from '../src/convertMetric';
describe('convertMetric', () => {
it('should handle string metric name', () => {
@ -55,13 +54,4 @@ describe('convertMetric', () => {
sqlExpression: 'COUNT(sum_girls)',
});
});
it('should truncate labels if they are too long', () => {
expect(
convertMetric({
expressionType: 'SQL',
sqlExpression: 'COUNT(verrrrrrrrry_loooooooooooooooooooooong_string)',
}).label.length,
).toBeLessThanOrEqual(LABEL_MAX_LENGTH);
});
});