Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix(plugin-chart-table): Invalid d3Formatter on String column (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Apr 5, 2023
1 parent ebc9f5e commit 2450d9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const processColumns = memoizeOne(function processColumns(
const isMetric = metricsSet.has(key) && isNumeric(key, records);
const isPercentMetric = percentMetricsSet.has(key);
const isTime = dataType === GenericDataType.TEMPORAL;
const isNumber = dataType === GenericDataType.NUMERIC;
const savedFormat = columnFormats?.[key];
const numberFormat = config.d3NumberFormat || savedFormat;

Expand Down Expand Up @@ -151,7 +152,7 @@ const processColumns = memoizeOne(function processColumns(
} else if (isPercentMetric) {
// percent metrics have a default format
formatter = getNumberFormatter(numberFormat || PERCENT_3_POINT);
} else if (isMetric || numberFormat) {
} else if (isMetric || (isNumber && numberFormat)) {
formatter = getNumberFormatter(numberFormat);
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('plugin-chart-table', () => {
// should successful rerender with new props
const cells = tree.find('td');
expect(tree.find('th').eq(1).text()).toEqual('Sum of Num');
expect(cells.eq(0).text()).toEqual('Michael');
expect(cells.eq(2).text()).toEqual('12.346%');
expect(cells.eq(4).text()).toEqual('2.47k');
});
Expand Down
14 changes: 14 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ const advanced: TableChartProps = {
...basicFormData,
metrics: ['sum__num'],
percent_metrics: ['pct_nice'],
column_config: {
name: {
d3NumberFormat: '.3s',
},
sum__num: {
d3NumberFormat: '.3s',
},
pct_nice: {
d3NumberFormat: '.3s',
},
'abc.com': {
d3NumberFormat: '.3s',
},
},
},
queriesData: [
{
Expand Down

0 comments on commit 2450d9b

Please sign in to comment.