Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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