Skip to content

Commit

Permalink
fix(filters): Stop breaking if translateToSql returns an object (#23715)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio-RiveroMartnez committed May 8, 2023
1 parent cf3410a commit 724fd82
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
});
});
4 changes: 3 additions & 1 deletion superset-frontend/src/explore/exploreUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 724fd82

Please sign in to comment.