mirror of
https://github.com/apache/superset.git
synced 2026-06-04 07:09:22 +00:00
fix(table): keep d3-format semantics when applying currency formatting (#37039)
This commit is contained in:
committed by
GitHub
parent
5f58241795
commit
ad3812edd7
@@ -60,7 +60,11 @@ class CurrencyFormatter extends ExtensibleFunction {
|
||||
}
|
||||
|
||||
getNormalizedD3Format() {
|
||||
return this.d3Format.replace(/\$|%/g, '');
|
||||
return this.d3Format.replace(/\$/g, '');
|
||||
}
|
||||
|
||||
normalizeForCurrency(value: string) {
|
||||
return value.replace(/%/g, '');
|
||||
}
|
||||
|
||||
format(value: number) {
|
||||
@@ -71,10 +75,11 @@ class CurrencyFormatter extends ExtensibleFunction {
|
||||
return formattedValue as string;
|
||||
}
|
||||
|
||||
const normalizedValue = this.normalizeForCurrency(formattedValue);
|
||||
if (this.currency.symbolPosition === 'prefix') {
|
||||
return `${getCurrencySymbol(this.currency)} ${formattedValue}`;
|
||||
return `${getCurrencySymbol(this.currency)} ${normalizedValue}`;
|
||||
}
|
||||
return `${formattedValue} ${getCurrencySymbol(this.currency)}`;
|
||||
return `${normalizedValue} ${getCurrencySymbol(this.currency)}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ test('CurrencyFormatter:getNormalizedD3Format', () => {
|
||||
currency: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||
d3Format: ',.1%',
|
||||
});
|
||||
expect(currencyFormatter4.getNormalizedD3Format()).toEqual(',.1');
|
||||
expect(currencyFormatter4.getNormalizedD3Format()).toEqual(',.1%');
|
||||
});
|
||||
|
||||
test('CurrencyFormatter:format', () => {
|
||||
@@ -146,9 +146,9 @@ test('CurrencyFormatter:format', () => {
|
||||
|
||||
const currencyFormatterWithPercentD3 = new CurrencyFormatter({
|
||||
currency: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||
d3Format: ',.1f%',
|
||||
d3Format: ',.1%',
|
||||
});
|
||||
expect(currencyFormatterWithPercentD3(VALUE)).toEqual('$ 56,100,057.0');
|
||||
expect(currencyFormatterWithPercentD3(VALUE)).toEqual('$ 5,610,005,700.0');
|
||||
|
||||
const currencyFormatterWithCurrencyD3 = new CurrencyFormatter({
|
||||
currency: { symbol: 'PLN', symbolPosition: 'suffix' },
|
||||
|
||||
Reference in New Issue
Block a user