mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(filters): Stop breaking if translateToSql returns an object (#23715)
This commit is contained in:
@@ -247,4 +247,36 @@ describe('AdhocFilter', () => {
|
||||
});
|
||||
expect(adhocFilter2.comparator).toBe(null);
|
||||
});
|
||||
it('sets the label properly if subject is a string', () => {
|
||||
const adhocFilter2 = new AdhocFilter({
|
||||
expressionType: EXPRESSION_TYPES.SIMPLE,
|
||||
subject: 'order_date',
|
||||
});
|
||||
expect(adhocFilter2.getDefaultLabel()).toBe('order_date');
|
||||
});
|
||||
it('sets the label properly if subject is an object with the column_date property', () => {
|
||||
const adhocFilter2 = new AdhocFilter({
|
||||
expressionType: EXPRESSION_TYPES.SIMPLE,
|
||||
subject: {
|
||||
column_name: 'year',
|
||||
},
|
||||
});
|
||||
expect(adhocFilter2.getDefaultLabel()).toBe('year');
|
||||
});
|
||||
it('sets the label to empty is there is no column_name in the object', () => {
|
||||
const adhocFilter2 = new AdhocFilter({
|
||||
expressionType: EXPRESSION_TYPES.SIMPLE,
|
||||
subject: {
|
||||
unknown: 'year',
|
||||
},
|
||||
});
|
||||
expect(adhocFilter2.getDefaultLabel()).toBe('');
|
||||
});
|
||||
it('sets the label to empty is there is no subject', () => {
|
||||
const adhocFilter2 = new AdhocFilter({
|
||||
expressionType: EXPRESSION_TYPES.SIMPLE,
|
||||
subject: undefined,
|
||||
});
|
||||
expect(adhocFilter2.getDefaultLabel()).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -295,7 +295,9 @@ export const getSimpleSQLExpression = (subject, operator, comparator) => {
|
||||
[...MULTI_OPERATORS]
|
||||
.map(op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation)
|
||||
.indexOf(operator) >= 0;
|
||||
let expression = subject ?? '';
|
||||
// If returned value is an object after changing dataset
|
||||
let expression =
|
||||
typeof subject === 'object' ? subject?.column_name ?? '' : subject ?? '';
|
||||
if (subject && operator) {
|
||||
expression += ` ${operator}`;
|
||||
const firstValue =
|
||||
|
||||
Reference in New Issue
Block a user