fix(filters): Stop breaking if translateToSql returns an object (#23715)

This commit is contained in:
Antonio Rivero
2023-05-08 16:03:53 -04:00
committed by GitHub
parent cf3410ad63
commit 724fd82919
2 changed files with 35 additions and 1 deletions

View File

@@ -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('');
});
});

View File

@@ -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 =