Skip to content

Commit

Permalink
includes -> includes_any for new filter syntax for array values
Browse files Browse the repository at this point in the history
  • Loading branch information
bcamper committed May 30, 2019
1 parent 12954a5 commit ef88117
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/styles/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,18 @@ function rangeMatch(key, value, options) {
function includesMatch(key, value) {
let expressions = [];

// the array includes ONE OE MORE of the provided values
if (value.includes) {
if (Array.isArray(value.includes)) {
let arr = '['+ value.includes.map(maybeQuote).join(',') + ']';
expressions.push(`${arr}.some(function(v) { return ${lookUp(key)}.indexOf(v) > -1 })`);
}
else {
expressions.push(`${lookUp(key)}.indexOf(${maybeQuote(value.includes)}) > -1`);
}
// the array includes ONE OE MORE of the provided values (a single value is converted to an array)
if (value.includes_any) {
const vals = Array.isArray(value.includes_any) ? value.includes_any : [value.includes_any];
const arr = '['+ vals.map(maybeQuote).join(',') + ']';
expressions.push(`${arr}.some(function(v) { return ${lookUp(key)}.indexOf(v) > -1 })`);
}

// the array includes ALL of the provided values
// the array includes ALL of the provided values (a single value is converted to an array)
if (value.includes_all) {
if (Array.isArray(value.includes_all)) {
let arr = '[' + value.includes_all.map(maybeQuote).join(',') + ']';
expressions.push(`${arr}.every(function(v) { return ${lookUp(key)}.indexOf(v) > -1 })`);
}
else {
expressions.push(`${lookUp(key)}.indexOf(${maybeQuote(value.includes_all)}) > -1`);
}
const vals = Array.isArray(value.includes_all) ? value.includes_all : [value.includes_all];
const arr = '[' + vals.map(maybeQuote).join(',') + ']';
expressions.push(`${arr}.every(function(v) { return ${lookUp(key)}.indexOf(v) > -1 })`);
}

return wrap(expressions.join(' && '));
Expand Down Expand Up @@ -157,7 +149,7 @@ function parseFilter(filter, options) {
if (value.max || value.min) {
filterAST.push(rangeMatch(key, value, options));
}
else if (value.includes || value.includes_all) {
else if (value.includes_any || value.includes_all) {
filterAST.push(includesMatch(key, value, options));
}
} else if (value == null) {
Expand Down

0 comments on commit ef88117

Please sign in to comment.