mirror of
https://github.com/apache/superset.git
synced 2026-08-12 11:11:01 +00:00
feat: Add currencies controls in control panels (#24718)
This commit is contained in:
@@ -140,6 +140,7 @@ export default function PivotTableChart(props: PivotTableProps) {
|
||||
colTotals,
|
||||
rowTotals,
|
||||
valueFormat,
|
||||
currencyFormat,
|
||||
emitCrossFilters,
|
||||
setDataMask,
|
||||
selectedFilters,
|
||||
@@ -155,8 +156,14 @@ export default function PivotTableChart(props: PivotTableProps) {
|
||||
|
||||
const theme = useTheme();
|
||||
const defaultFormatter = useMemo(
|
||||
() => getNumberFormatter(valueFormat),
|
||||
[valueFormat],
|
||||
() =>
|
||||
currencyFormat?.symbol
|
||||
? new CurrencyFormatter({
|
||||
currency: currencyFormat,
|
||||
d3Format: valueFormat,
|
||||
})
|
||||
: getNumberFormatter(valueFormat),
|
||||
[valueFormat, currencyFormat],
|
||||
);
|
||||
const customFormatsArray = useMemo(
|
||||
() =>
|
||||
@@ -168,9 +175,9 @@ export default function PivotTableChart(props: PivotTableProps) {
|
||||
).map(metricName => [
|
||||
metricName,
|
||||
columnFormats[metricName] || valueFormat,
|
||||
currencyFormats[metricName],
|
||||
currencyFormats[metricName] || currencyFormat,
|
||||
]),
|
||||
[columnFormats, currencyFormats, valueFormat],
|
||||
[columnFormats, currencyFormat, currencyFormats, valueFormat],
|
||||
);
|
||||
const hasCustomMetricFormatters = customFormatsArray.length > 0;
|
||||
const metricFormatters = useMemo(
|
||||
|
||||
@@ -272,6 +272,7 @@ const config: ControlPanelConfig = {
|
||||
},
|
||||
},
|
||||
],
|
||||
['currency_format'],
|
||||
[
|
||||
{
|
||||
name: 'date_format',
|
||||
|
||||
@@ -102,6 +102,7 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
|
||||
metricsLayout,
|
||||
conditionalFormatting,
|
||||
timeGrainSqla,
|
||||
currencyFormat,
|
||||
} = formData;
|
||||
const { selectedFilters } = filterState;
|
||||
const granularity = extractTimegrain(rawFormData);
|
||||
@@ -157,6 +158,7 @@ export default function transformProps(chartProps: ChartProps<QueryFormData>) {
|
||||
colTotals,
|
||||
rowTotals,
|
||||
valueFormat,
|
||||
currencyFormat,
|
||||
emitCrossFilters,
|
||||
setDataMask,
|
||||
selectedFilters,
|
||||
|
||||
@@ -65,6 +65,7 @@ interface PivotTableCustomizeProps {
|
||||
colTotals: boolean;
|
||||
rowTotals: boolean;
|
||||
valueFormat: string;
|
||||
currencyFormat: Currency;
|
||||
setDataMask: SetDataMaskHook;
|
||||
emitCrossFilters?: boolean;
|
||||
selectedFilters?: SelectedFiltersType;
|
||||
|
||||
@@ -52,6 +52,7 @@ const formData: PivotTableQueryFormData = {
|
||||
margin: 0,
|
||||
time_grain_sqla: TimeGranularity.MONTH,
|
||||
temporal_columns_lookup: { col1: true },
|
||||
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||
};
|
||||
|
||||
test('should build groupby with series in form data', () => {
|
||||
|
||||
@@ -45,6 +45,7 @@ describe('PivotTableChart transformProps', () => {
|
||||
dateFormat: '',
|
||||
legacy_order_by: 'count',
|
||||
order_desc: true,
|
||||
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||
};
|
||||
const chartProps = new ChartProps<QueryFormData>({
|
||||
formData,
|
||||
@@ -91,6 +92,7 @@ describe('PivotTableChart transformProps', () => {
|
||||
emitCrossFilters: false,
|
||||
columnFormats: {},
|
||||
currencyFormats: {},
|
||||
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user