Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -167,6 +167,29 @@ 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,
],
},
Expand Down Expand Up @@ -196,10 +219,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(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(amountOption).toBeUndefined();
expect(numericOptions).toHaveLength(0);
}, 60000);
Loading