mirror of
https://github.com/apache/superset.git
synced 2026-04-25 11:04:48 +00:00
feat: Add currencies controls in control panels (#24718)
This commit is contained in:
committed by
GitHub
parent
1a9c559a8f
commit
f7e76d02b7
@@ -481,6 +481,8 @@ const config: ControlPanelConfig = {
|
||||
type: 'ColumnConfigControl',
|
||||
label: t('Customize columns'),
|
||||
description: t('Further customize how to display each column'),
|
||||
width: 400,
|
||||
height: 320,
|
||||
renderTrigger: true,
|
||||
shouldMapStateToProps() {
|
||||
return true;
|
||||
|
||||
@@ -124,8 +124,11 @@ const processColumns = memoizeOne(function processColumns(
|
||||
const isTime = dataType === GenericDataType.TEMPORAL;
|
||||
const isNumber = dataType === GenericDataType.NUMERIC;
|
||||
const savedFormat = columnFormats?.[key];
|
||||
const currency = currencyFormats?.[key];
|
||||
const savedCurrency = currencyFormats?.[key];
|
||||
const numberFormat = config.d3NumberFormat || savedFormat;
|
||||
const currency = config.currencyFormat?.symbol
|
||||
? config.currencyFormat
|
||||
: savedCurrency;
|
||||
|
||||
let formatter;
|
||||
|
||||
@@ -158,7 +161,10 @@ const processColumns = memoizeOne(function processColumns(
|
||||
formatter = getNumberFormatter(numberFormat || PERCENT_3_POINT);
|
||||
} else if (isMetric || (isNumber && numberFormat)) {
|
||||
formatter = currency
|
||||
? new CurrencyFormatter({ d3Format: numberFormat, currency })
|
||||
? new CurrencyFormatter({
|
||||
d3Format: numberFormat,
|
||||
currency,
|
||||
})
|
||||
: getNumberFormatter(numberFormat);
|
||||
}
|
||||
return {
|
||||
|
||||
@@ -32,11 +32,25 @@ import {
|
||||
SetDataMaskHook,
|
||||
ContextMenuFilters,
|
||||
CurrencyFormatter,
|
||||
Currency,
|
||||
} from '@superset-ui/core';
|
||||
import { ColorFormatters, ColumnConfig } from '@superset-ui/chart-controls';
|
||||
import { ColorFormatters } from '@superset-ui/chart-controls';
|
||||
|
||||
export type CustomFormatter = (value: DataRecordValue) => string;
|
||||
|
||||
export type TableColumnConfig = {
|
||||
d3NumberFormat?: string;
|
||||
d3SmallNumberFormat?: string;
|
||||
d3TimeFormat?: string;
|
||||
columnWidth?: number;
|
||||
horizontalAlign?: 'left' | 'right' | 'center';
|
||||
showCellBars?: boolean;
|
||||
alignPositiveNegative?: boolean;
|
||||
colorPositiveNegative?: boolean;
|
||||
truncateLongCells?: boolean;
|
||||
currencyFormat?: Currency;
|
||||
};
|
||||
|
||||
export interface DataColumnMeta {
|
||||
// `key` is what is called `label` in the input props
|
||||
key: string;
|
||||
@@ -51,7 +65,7 @@ export interface DataColumnMeta {
|
||||
isMetric?: boolean;
|
||||
isPercentMetric?: boolean;
|
||||
isNumeric?: boolean;
|
||||
config?: ColumnConfig;
|
||||
config?: TableColumnConfig;
|
||||
}
|
||||
|
||||
export interface TableChartData {
|
||||
@@ -75,7 +89,7 @@ export type TableChartFormData = QueryFormData & {
|
||||
show_cell_bars?: boolean;
|
||||
table_timestamp_format?: string;
|
||||
time_grain_sqla?: TimeGranularity;
|
||||
column_config?: Record<string, ColumnConfig>;
|
||||
column_config?: Record<string, TableColumnConfig>;
|
||||
allow_rearrange_columns?: boolean;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user