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

feat: Add filter starts with in data browser for fields of type Pointer #2553

Merged
merged 4 commits into from
May 15, 2024
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
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
Loading