mirror of
https://github.com/apache/superset.git
synced 2026-07-10 16:55:30 +00:00
feat: Dynamic currency (#36416)
This commit is contained in:
committed by
GitHub
parent
896947c787
commit
f4474b2e3e
@@ -33,6 +33,8 @@ import DateWithFormatter from './DateWithFormatter';
|
||||
function formatValue(
|
||||
formatter: DataColumnMeta['formatter'],
|
||||
value: DataRecordValue,
|
||||
rowData?: Record<string, DataRecordValue>,
|
||||
currencyColumn?: string,
|
||||
): [boolean, string] {
|
||||
// render undefined as empty string
|
||||
if (value === undefined) {
|
||||
@@ -48,6 +50,10 @@ function formatValue(
|
||||
return [false, 'N/A'];
|
||||
}
|
||||
if (formatter) {
|
||||
// If formatter is a CurrencyFormatter, pass row context for AUTO mode
|
||||
if (formatter instanceof CurrencyFormatter) {
|
||||
return [false, formatter(value as number, rowData, currencyColumn)];
|
||||
}
|
||||
return [false, formatter(value as number)];
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
@@ -59,8 +65,9 @@ function formatValue(
|
||||
export function formatColumnValue(
|
||||
column: DataColumnMeta,
|
||||
value: DataRecordValue,
|
||||
rowData?: Record<string, DataRecordValue>,
|
||||
) {
|
||||
const { dataType, formatter, config = {} } = column;
|
||||
const { dataType, formatter, config = {}, currencyCodeColumn } = column;
|
||||
const isNumber = dataType === GenericDataType.Numeric;
|
||||
const smallNumberFormatter =
|
||||
config.d3SmallNumberFormat === undefined
|
||||
@@ -76,5 +83,7 @@ export function formatColumnValue(
|
||||
? smallNumberFormatter
|
||||
: formatter,
|
||||
value,
|
||||
rowData,
|
||||
currencyCodeColumn,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user