mirror of
https://github.com/apache/superset.git
synced 2026-04-25 11:04:48 +00:00
fix: Currency formatting in Table raw mode (#25248)
This commit is contained in:
committed by
GitHub
parent
894f250229
commit
ea21e800a7
@@ -159,7 +159,7 @@ const processColumns = memoizeOne(function processColumns(
|
|||||||
} else if (isPercentMetric) {
|
} else if (isPercentMetric) {
|
||||||
// percent metrics have a default format
|
// percent metrics have a default format
|
||||||
formatter = getNumberFormatter(numberFormat || PERCENT_3_POINT);
|
formatter = getNumberFormatter(numberFormat || PERCENT_3_POINT);
|
||||||
} else if (isMetric || (isNumber && numberFormat)) {
|
} else if (isMetric || (isNumber && (numberFormat || currency))) {
|
||||||
formatter = currency
|
formatter = currency
|
||||||
? new CurrencyFormatter({
|
? new CurrencyFormatter({
|
||||||
d3Format: numberFormat,
|
d3Format: numberFormat,
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ export default function isEqualColumns(
|
|||||||
JSON.stringify(a.formData.extraFilters || null) ===
|
JSON.stringify(a.formData.extraFilters || null) ===
|
||||||
JSON.stringify(b.formData.extraFilters || null) &&
|
JSON.stringify(b.formData.extraFilters || null) &&
|
||||||
JSON.stringify(a.formData.extraFormData || null) ===
|
JSON.stringify(a.formData.extraFormData || null) ===
|
||||||
JSON.stringify(b.formData.extraFormData || null)
|
JSON.stringify(b.formData.extraFormData || null) &&
|
||||||
|
JSON.stringify(a.rawFormData.column_config || null) ===
|
||||||
|
JSON.stringify(b.rawFormData.column_config || null)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,47 @@ describe('plugin-chart-table', () => {
|
|||||||
expect(cells[4]).toHaveTextContent('$ 2.47k');
|
expect(cells[4]).toHaveTextContent('$ 2.47k');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('render raw data', () => {
|
||||||
|
const props = transformProps({
|
||||||
|
...testData.raw,
|
||||||
|
rawFormData: { ...testData.raw.rawFormData },
|
||||||
|
});
|
||||||
|
render(
|
||||||
|
ProviderWrapper({
|
||||||
|
children: <TableChart {...props} sticky={false} />,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const cells = document.querySelectorAll('td');
|
||||||
|
expect(document.querySelectorAll('th')[0]).toHaveTextContent('num');
|
||||||
|
expect(cells[0]).toHaveTextContent('1234');
|
||||||
|
expect(cells[1]).toHaveTextContent('10000');
|
||||||
|
expect(cells[1]).toHaveTextContent('0');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('render raw data with currencies', () => {
|
||||||
|
const props = transformProps({
|
||||||
|
...testData.raw,
|
||||||
|
rawFormData: {
|
||||||
|
...testData.raw.rawFormData,
|
||||||
|
column_config: {
|
||||||
|
num: {
|
||||||
|
currencyFormat: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
render(
|
||||||
|
ProviderWrapper({
|
||||||
|
children: <TableChart {...props} sticky={false} />,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const cells = document.querySelectorAll('td');
|
||||||
|
expect(document.querySelectorAll('th')[0]).toHaveTextContent('num');
|
||||||
|
expect(cells[0]).toHaveTextContent('$ 1.23k');
|
||||||
|
expect(cells[1]).toHaveTextContent('$ 10k');
|
||||||
|
expect(cells[2]).toHaveTextContent('$ 0');
|
||||||
|
});
|
||||||
|
|
||||||
it('render empty data', () => {
|
it('render empty data', () => {
|
||||||
wrap.setProps({ ...transformProps(testData.empty), sticky: false });
|
wrap.setProps({ ...transformProps(testData.empty), sticky: false });
|
||||||
tree = wrap.render();
|
tree = wrap.render();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
ChartProps,
|
ChartProps,
|
||||||
DatasourceType,
|
DatasourceType,
|
||||||
GenericDataType,
|
GenericDataType,
|
||||||
|
QueryMode,
|
||||||
supersetTheme,
|
supersetTheme,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { TableChartProps, TableChartFormData } from '../src/types';
|
import { TableChartProps, TableChartFormData } from '../src/types';
|
||||||
@@ -173,6 +174,33 @@ const advanced: TableChartProps = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const raw = {
|
||||||
|
...advanced,
|
||||||
|
rawFormData: {
|
||||||
|
...advanced.rawFormData,
|
||||||
|
query_mode: QueryMode.raw,
|
||||||
|
columns: ['num'],
|
||||||
|
},
|
||||||
|
queriesData: [
|
||||||
|
{
|
||||||
|
...basicQueryResult,
|
||||||
|
colnames: ['num'],
|
||||||
|
coltypes: [GenericDataType.NUMERIC],
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
num: 1234,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
num: 10000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
num: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
const advancedWithCurrency = {
|
const advancedWithCurrency = {
|
||||||
...advanced,
|
...advanced,
|
||||||
datasource: {
|
datasource: {
|
||||||
@@ -198,4 +226,5 @@ export default {
|
|||||||
advanced,
|
advanced,
|
||||||
advancedWithCurrency,
|
advancedWithCurrency,
|
||||||
empty,
|
empty,
|
||||||
|
raw,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user