Skip to content

Added/fixed a filtering option "contains string" for String fields. #724

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

Merged
merged 2 commits into from
Jun 13, 2017
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### NEXT RELEASE

* _Contributing to this repo? Add info about your change here to be included in next release_
* Improvement: Added/fixed a filtering option "contains string" for String fields. Case insensitive for now.

### 1.0.27
* Improvement: Show notifications upon success or failure of save and delete objects (#718), thanks to [Natan Rolnik](https://github.com/natanrolnik)
Expand Down
7 changes: 6 additions & 1 deletion src/lib/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export const Constraints = {
ends: {
name: 'ends with',
},
stringContainsString: {
name: 'string contains string',
field: 'String',
composable: true,
},
before: {
name: 'is before',
field: 'Date',
Expand Down Expand Up @@ -92,7 +97,7 @@ export const FieldConstraints = {
'Pointer': [ 'exists', 'dne', 'eq', 'neq'],
'Boolean': [ 'exists', 'dne', 'eq' ],
'Number': [ 'exists', 'dne', 'eq', 'neq', 'lt', 'lte', 'gt', 'gte' ],
'String': [ 'exists', 'dne', 'eq', 'neq', 'starts', 'ends' ],
'String': [ 'exists', 'dne', 'eq', 'neq', 'starts', 'ends', 'stringContainsString' ],
'Date': [ 'exists', 'dne', 'before', 'after' ],
'Array': [
'exists',
Expand Down
3 changes: 3 additions & 0 deletions src/lib/queryFromFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ function addConstraint(query, filter) {
case 'containedIn':
query.containedIn(filter.get('field'), filter.get('array'));
break;
case 'stringContainsString':
query.matches(filter.get('field'), filter.get('compareTo'), 'i');
break;
}
return query;
}