Skip to content

Commit

Permalink
empty lists are invalid comparators (#5160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Lyons authored and john-bodley committed Jun 7, 2018
1 parent 57e1256 commit 5b35f75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions superset/assets/spec/javascripts/explore/AdhocFilter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ describe('AdhocFilter', () => {
});
// eslint-disable-next-line no-unused-expressions
expect(adhocFilter3.isValid()).to.be.false;

const adhocFilter4 = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operator: 'in',
comparator: [],
clause: CLAUSES.WHERE,
});
// eslint-disable-next-line no-unused-expressions
expect(adhocFilter4.isValid()).to.be.false;

const adhocFilter5 = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operator: 'in',
comparator: ['val1'],
clause: CLAUSES.WHERE,
});
// eslint-disable-next-line no-unused-expressions
expect(adhocFilter5.isValid()).to.be.true;
});

it('can translate from simple expressions to sql expressions', () => {
Expand Down
8 changes: 7 additions & 1 deletion superset/assets/src/explore/AdhocFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ export default class AdhocFilter {

isValid() {
if (this.expressionType === EXPRESSION_TYPES.SIMPLE) {
return !!(this.operator && this.subject && this.comparator && this.clause);
return !!(
this.operator &&
this.subject &&
this.comparator &&
this.comparator.length > 0 &&
this.clause
);
} else if (this.expressionType === EXPRESSION_TYPES.SQL) {
return !!(this.sqlExpression && this.clause);
}
Expand Down

0 comments on commit 5b35f75

Please sign in to comment.