mirror of
https://github.com/apache/superset.git
synced 2026-04-24 02:25:13 +00:00
Co-authored-by: Fardin Mustaque <fardinmustaque@Fardins-Mac-mini.local>
This commit is contained in:
@@ -22,6 +22,10 @@ import utc from 'dayjs/plugin/utc';
|
||||
import {
|
||||
getTimeFormatter,
|
||||
getTimeFormatterForGranularity,
|
||||
isAdhocMetricSimple,
|
||||
isSavedMetric,
|
||||
Metric,
|
||||
QueryFormMetric,
|
||||
SMART_DATE_ID,
|
||||
TimeGranularity,
|
||||
} from '@superset-ui/core';
|
||||
@@ -47,3 +51,43 @@ export const getDateFormatter = (
|
||||
timeFormat === SMART_DATE_ID
|
||||
? getTimeFormatterForGranularity(granularity)
|
||||
: getTimeFormatter(timeFormat ?? fallbackFormat);
|
||||
|
||||
export function getOriginalLabel(
|
||||
metric: QueryFormMetric,
|
||||
metrics: Metric[] = [],
|
||||
): string {
|
||||
const metricLabel = typeof metric === 'string' ? metric : metric.label || '';
|
||||
|
||||
if (isSavedMetric(metric)) {
|
||||
const metricEntry = metrics.find(m => m.metric_name === metric);
|
||||
return (
|
||||
metricEntry?.verbose_name ||
|
||||
metricEntry?.metric_name ||
|
||||
metric ||
|
||||
'Unknown Metric'
|
||||
);
|
||||
}
|
||||
|
||||
if (isAdhocMetricSimple(metric)) {
|
||||
const column = metric.column || {};
|
||||
const columnName = column.column_name || 'unknown_column';
|
||||
const verboseName = column.verbose_name || columnName;
|
||||
const aggregate = metric.aggregate || 'UNKNOWN';
|
||||
return metric.hasCustomLabel && metric.label
|
||||
? metric.label
|
||||
: `${aggregate}(${verboseName})`;
|
||||
}
|
||||
|
||||
if (
|
||||
typeof metric === 'object' &&
|
||||
'expressionType' in metric &&
|
||||
metric.expressionType === 'SQL' &&
|
||||
'sqlExpression' in metric
|
||||
) {
|
||||
return metric.hasCustomLabel && metric.label
|
||||
? metric.label
|
||||
: metricLabel || 'Custom Metric';
|
||||
}
|
||||
|
||||
return metricLabel || 'Unknown Metric';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user