mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
fix(dataset-editor): include calculated columns in currency code dropdown (#37621)
This commit is contained in:
committed by
GitHub
parent
2dfc770b0f
commit
89a98ab9a4
@@ -1122,9 +1122,13 @@ class DatasourceEditor extends PureComponent {
|
||||
label: col.verbose_name || col.column_name,
|
||||
}));
|
||||
|
||||
// Get string-type columns for the currency code dropdown
|
||||
// String columns + untyped calculated columns for the currency code dropdown
|
||||
const stringColumns = allColumns
|
||||
.filter(col => col.type_generic === GenericDataType.String)
|
||||
.filter(
|
||||
col =>
|
||||
col.type_generic === GenericDataType.String ||
|
||||
(col.expression && col.type_generic == null),
|
||||
)
|
||||
.map(col => ({
|
||||
value: col.column_name,
|
||||
label: col.verbose_name || col.column_name,
|
||||
|
||||
@@ -138,7 +138,7 @@ test('changes currency symbol from USD to GBP', async () => {
|
||||
expect(updatedMetric?.currency?.symbolPosition).toBe('prefix');
|
||||
}, 60000);
|
||||
|
||||
test('currency code column dropdown shows only string columns', async () => {
|
||||
test('currency code column dropdown shows string and untyped calculated columns but excludes numeric and typed non-string calculated columns', async () => {
|
||||
const baseProps = createProps();
|
||||
const testProps = {
|
||||
...baseProps,
|
||||
@@ -167,6 +167,28 @@ test('currency code column dropdown shows only string columns', async () => {
|
||||
groupby: false,
|
||||
column_name: 'amount',
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
type: '',
|
||||
type_generic: null,
|
||||
filterable: true,
|
||||
is_dttm: false,
|
||||
is_active: true,
|
||||
expression: "CASE WHEN country = 'US' THEN 'USD' ELSE 'EUR' END",
|
||||
groupby: true,
|
||||
column_name: 'derived_currency',
|
||||
},
|
||||
{
|
||||
id: 103,
|
||||
type: 'NUMERIC',
|
||||
type_generic: GenericDataType.Numeric,
|
||||
filterable: true,
|
||||
is_dttm: false,
|
||||
is_active: true,
|
||||
expression: 'price * quantity',
|
||||
groupby: false,
|
||||
column_name: 'total_amount',
|
||||
},
|
||||
...baseProps.datasource.columns,
|
||||
],
|
||||
},
|
||||
@@ -196,10 +218,16 @@ test('currency code column dropdown shows only string columns', async () => {
|
||||
expect(currencyCodeOption).toBeDefined();
|
||||
});
|
||||
|
||||
// Verify NUMERIC column is NOT available
|
||||
// Verify CALCULATED column is available despite null type_generic
|
||||
const options = document.querySelectorAll('.ant-select-item-option');
|
||||
const amountOption = Array.from(options).find(o =>
|
||||
o.textContent?.includes('amount'),
|
||||
const derivedCurrencyOption = Array.from(options).find(o =>
|
||||
o.textContent?.includes('derived_currency'),
|
||||
);
|
||||
expect(amountOption).toBeUndefined();
|
||||
expect(derivedCurrencyOption).toBeDefined();
|
||||
|
||||
// Verify NUMERIC columns (physical and calculated) are NOT available
|
||||
const numericOptions = Array.from(options).filter(o =>
|
||||
['amount', 'total_amount'].includes(o.textContent?.trim() ?? ''),
|
||||
);
|
||||
expect(numericOptions).toHaveLength(0);
|
||||
}, 60000);
|
||||
|
||||
Reference in New Issue
Block a user