mirror of
https://github.com/apache/superset.git
synced 2024-09-19 20:19:37 -04:00
feat(query): remove redundant metric label truncation (#492)
* feat: remove redundant metric label truncation * fix lint
This commit is contained in:
parent
aefd587ee5
commit
dfb5ac42dd
@ -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,
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user