Skip to content

Commit

Permalink
feat: Add filter starts with in data browser for fields of type Poi…
Browse files Browse the repository at this point in the history
…nter (#2553)

Co-authored-by: Manuel <5673677+mtrezza@users.noreply.github.com>
  • Loading branch information
devbymak and mtrezza authored May 15, 2024
1 parent 80d411d commit 0b94ab6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const Constraints = {
};

export const FieldConstraints = {
Pointer: ['exists', 'dne', 'eq', 'neq', 'unique'],
Pointer: ['exists', 'dne', 'eq', 'neq', 'starts', 'unique'],
Boolean: ['exists', 'dne', 'eq', 'unique'],
Number: ['exists', 'dne', 'eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'unique'],
String: ['exists', 'dne', 'eq', 'neq', 'starts', 'ends', 'stringContainsString', 'unique'],
Expand Down
16 changes: 15 additions & 1 deletion src/lib/queryFromFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function addQueryConstraintFromObject(query, filter, constraintType) {
}
}

function isPointer(value) {
return (
typeof value === 'object' && value.hasOwnProperty('__type') && value['__type'] === 'Pointer'
);
}

function addConstraint(query, filter) {
switch (filter.get('constraint')) {
case 'exists':
Expand Down Expand Up @@ -55,7 +61,15 @@ function addConstraint(query, filter) {
query.greaterThanOrEqualTo(filter.get('field'), filter.get('compareTo'));
break;
case 'starts':
query.startsWith(filter.get('field'), filter.get('compareTo'));
const field = filter.get('field');
const compareTo = filter.get('compareTo');
if (isPointer(compareTo)) {
const porinterQuery = new Parse.Query(compareTo.className);
porinterQuery.startsWith('objectId', compareTo.objectId);
query.matchesQuery(field, porinterQuery);
} else {
query.startsWith(field, compareTo);
}
break;
case 'ends':
query.endsWith(filter.get('field'), filter.get('compareTo'));
Expand Down

0 comments on commit 0b94ab6

Please sign in to comment.