Skip to content

Commit 0b94ab6

Browse files
devbymakmtrezza
andauthored
feat: Add filter starts with in data browser for fields of type Pointer (#2553)
Co-authored-by: Manuel <[email protected]>
1 parent 80d411d commit 0b94ab6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/lib/Filters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const Constraints = {
166166
};
167167

168168
export const FieldConstraints = {
169-
Pointer: ['exists', 'dne', 'eq', 'neq', 'unique'],
169+
Pointer: ['exists', 'dne', 'eq', 'neq', 'starts', 'unique'],
170170
Boolean: ['exists', 'dne', 'eq', 'unique'],
171171
Number: ['exists', 'dne', 'eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'unique'],
172172
String: ['exists', 'dne', 'eq', 'neq', 'starts', 'ends', 'stringContainsString', 'unique'],

src/lib/queryFromFilters.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ function addQueryConstraintFromObject(query, filter, constraintType) {
2828
}
2929
}
3030

31+
function isPointer(value) {
32+
return (
33+
typeof value === 'object' && value.hasOwnProperty('__type') && value['__type'] === 'Pointer'
34+
);
35+
}
36+
3137
function addConstraint(query, filter) {
3238
switch (filter.get('constraint')) {
3339
case 'exists':
@@ -55,7 +61,15 @@ function addConstraint(query, filter) {
5561
query.greaterThanOrEqualTo(filter.get('field'), filter.get('compareTo'));
5662
break;
5763
case 'starts':
58-
query.startsWith(filter.get('field'), filter.get('compareTo'));
64+
const field = filter.get('field');
65+
const compareTo = filter.get('compareTo');
66+
if (isPointer(compareTo)) {
67+
const porinterQuery = new Parse.Query(compareTo.className);
68+
porinterQuery.startsWith('objectId', compareTo.objectId);
69+
query.matchesQuery(field, porinterQuery);
70+
} else {
71+
query.startsWith(field, compareTo);
72+
}
5973
break;
6074
case 'ends':
6175
query.endsWith(filter.get('field'), filter.get('compareTo'));

0 commit comments

Comments
 (0)