@teselagen/ui 0.7.33-beta.5 → 0.7.33-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DataTable/utils/queryParams.d.ts +5 -3
- package/index.cjs.js +27 -18
- package/index.es.js +27 -18
- package/package.json +1 -1
- package/src/DataTable/index.js +1 -1
- package/src/DataTable/utils/filterLocalEntitiesToHasura.js +14 -0
- package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +49 -0
- package/src/DataTable/utils/queryParams.js +12 -9
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +146 -143
|
@@ -31,9 +31,11 @@ export function getQueryParams({ currentParams, defaults, schema, isInfinite, en
|
|
|
31
31
|
noOrderError: any;
|
|
32
32
|
ownProps: any;
|
|
33
33
|
}): {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
page: any;
|
|
35
|
+
pageSize: any;
|
|
36
|
+
order: any[];
|
|
37
|
+
filters: any;
|
|
38
|
+
searchTerm: any;
|
|
37
39
|
} | {
|
|
38
40
|
variables: {
|
|
39
41
|
where: {};
|
package/index.cjs.js
CHANGED
|
@@ -19414,9 +19414,8 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19414
19414
|
if (searchDisabled || field.filterDisabled || type2 === "color") return;
|
|
19415
19415
|
const filterValue = searchTerm;
|
|
19416
19416
|
if (type2 === "string" || type2 === "lookup") {
|
|
19417
|
-
|
|
19418
|
-
|
|
19419
|
-
});
|
|
19417
|
+
const o2 = set$1({}, path2, { _ilike: `%${filterValue}%` });
|
|
19418
|
+
searchTermFilters.push(o2);
|
|
19420
19419
|
} else if (type2 === "boolean") {
|
|
19421
19420
|
let regex;
|
|
19422
19421
|
try {
|
|
@@ -19425,19 +19424,16 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19425
19424
|
}
|
|
19426
19425
|
if (regex) {
|
|
19427
19426
|
if ("true".replace(regex, "") !== "true") {
|
|
19428
|
-
|
|
19429
|
-
|
|
19430
|
-
});
|
|
19427
|
+
const o2 = set$1({}, path2, { _eq: true });
|
|
19428
|
+
searchTermFilters.push(o2);
|
|
19431
19429
|
} else if ("false".replace(regex, "") !== "false") {
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
});
|
|
19430
|
+
const o2 = set$1({}, path2, { _eq: false });
|
|
19431
|
+
searchTermFilters.push(o2);
|
|
19435
19432
|
}
|
|
19436
19433
|
}
|
|
19437
19434
|
} else if ((type2 === "number" || type2 === "integer") && !isNaN(filterValue)) {
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
});
|
|
19435
|
+
const o2 = set$1({}, path2, { _eq: parseFloat(filterValue) });
|
|
19436
|
+
searchTermFilters.push(o2);
|
|
19441
19437
|
}
|
|
19442
19438
|
});
|
|
19443
19439
|
if (searchTermFilters.length > 0) {
|
|
@@ -19522,7 +19518,9 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19522
19518
|
},
|
|
19523
19519
|
{
|
|
19524
19520
|
[filterOn]: {
|
|
19525
|
-
_gt: new Date(
|
|
19521
|
+
_gt: new Date(
|
|
19522
|
+
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
19523
|
+
)
|
|
19526
19524
|
}
|
|
19527
19525
|
}
|
|
19528
19526
|
]
|
|
@@ -19572,6 +19570,10 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19572
19570
|
console.warn(`Unsupported filter type: ${selectedFilter}`);
|
|
19573
19571
|
return {};
|
|
19574
19572
|
}
|
|
19573
|
+
}).map((filter2) => {
|
|
19574
|
+
const o2 = {};
|
|
19575
|
+
set$1(o2, Object.keys(filter2)[0], filter2[Object.keys(filter2)[0]]);
|
|
19576
|
+
return o2;
|
|
19575
19577
|
});
|
|
19576
19578
|
if (filterClauses.length > 0) {
|
|
19577
19579
|
if (Object.keys(where).length > 0) {
|
|
@@ -19658,6 +19660,9 @@ function applyWhereClause(records, where) {
|
|
|
19658
19660
|
} else {
|
|
19659
19661
|
const value = record[key];
|
|
19660
19662
|
const conditions = filter2[key];
|
|
19663
|
+
if (isObject$2(value) && isObject$2(conditions) && !hasOperator(conditions)) {
|
|
19664
|
+
return applyFilter(value, conditions);
|
|
19665
|
+
}
|
|
19661
19666
|
for (const operator in conditions) {
|
|
19662
19667
|
const conditionValue = conditions[operator];
|
|
19663
19668
|
if (operator === "_gt" && conditions._lt) {
|
|
@@ -19755,6 +19760,10 @@ function applyWhereClause(records, where) {
|
|
|
19755
19760
|
return true;
|
|
19756
19761
|
}
|
|
19757
19762
|
__name(applyFilter, "applyFilter");
|
|
19763
|
+
function hasOperator(obj) {
|
|
19764
|
+
return Object.keys(obj).some((key) => key.startsWith("_"));
|
|
19765
|
+
}
|
|
19766
|
+
__name(hasOperator, "hasOperator");
|
|
19758
19767
|
return records.filter((record) => applyFilter(record, where));
|
|
19759
19768
|
}
|
|
19760
19769
|
__name(applyWhereClause, "applyWhereClause");
|
|
@@ -20015,7 +20024,7 @@ function getQueryParams({
|
|
|
20015
20024
|
}
|
|
20016
20025
|
});
|
|
20017
20026
|
}
|
|
20018
|
-
|
|
20027
|
+
let toRet = {
|
|
20019
20028
|
//these are values that might be generally useful for the wrapped component
|
|
20020
20029
|
page,
|
|
20021
20030
|
pageSize: ownProps.controlled_pageSize || pageSize,
|
|
@@ -20034,16 +20043,16 @@ function getQueryParams({
|
|
|
20034
20043
|
initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
|
|
20035
20044
|
addCustomColumnFilters(where, schema.fields, currentParams);
|
|
20036
20045
|
if (isLocalCall) {
|
|
20037
|
-
|
|
20046
|
+
toRet = __spreadValues(__spreadValues({}, toRet), filterLocalEntitiesToHasura(entities, {
|
|
20038
20047
|
where,
|
|
20039
20048
|
order_by,
|
|
20040
20049
|
limit,
|
|
20041
20050
|
offset: offset3,
|
|
20042
20051
|
isInfinite
|
|
20043
|
-
});
|
|
20052
|
+
}));
|
|
20044
20053
|
return toRet;
|
|
20045
20054
|
} else {
|
|
20046
|
-
return __spreadProps(__spreadValues({},
|
|
20055
|
+
return __spreadProps(__spreadValues({}, toRet), {
|
|
20047
20056
|
variables: {
|
|
20048
20057
|
where,
|
|
20049
20058
|
order_by,
|
|
@@ -56498,7 +56507,7 @@ const DataTable = /* @__PURE__ */ __name((_I) => {
|
|
|
56498
56507
|
}) : !val;
|
|
56499
56508
|
});
|
|
56500
56509
|
}
|
|
56501
|
-
if (noValsForField) {
|
|
56510
|
+
if (noValsForField && entities.length) {
|
|
56502
56511
|
return __spreadProps(__spreadValues({}, field), {
|
|
56503
56512
|
isHidden: true,
|
|
56504
56513
|
isForcedHidden: true
|
package/index.es.js
CHANGED
|
@@ -19396,9 +19396,8 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19396
19396
|
if (searchDisabled || field.filterDisabled || type2 === "color") return;
|
|
19397
19397
|
const filterValue = searchTerm;
|
|
19398
19398
|
if (type2 === "string" || type2 === "lookup") {
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
});
|
|
19399
|
+
const o2 = set$1({}, path2, { _ilike: `%${filterValue}%` });
|
|
19400
|
+
searchTermFilters.push(o2);
|
|
19402
19401
|
} else if (type2 === "boolean") {
|
|
19403
19402
|
let regex;
|
|
19404
19403
|
try {
|
|
@@ -19407,19 +19406,16 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19407
19406
|
}
|
|
19408
19407
|
if (regex) {
|
|
19409
19408
|
if ("true".replace(regex, "") !== "true") {
|
|
19410
|
-
|
|
19411
|
-
|
|
19412
|
-
});
|
|
19409
|
+
const o2 = set$1({}, path2, { _eq: true });
|
|
19410
|
+
searchTermFilters.push(o2);
|
|
19413
19411
|
} else if ("false".replace(regex, "") !== "false") {
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
});
|
|
19412
|
+
const o2 = set$1({}, path2, { _eq: false });
|
|
19413
|
+
searchTermFilters.push(o2);
|
|
19417
19414
|
}
|
|
19418
19415
|
}
|
|
19419
19416
|
} else if ((type2 === "number" || type2 === "integer") && !isNaN(filterValue)) {
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
});
|
|
19417
|
+
const o2 = set$1({}, path2, { _eq: parseFloat(filterValue) });
|
|
19418
|
+
searchTermFilters.push(o2);
|
|
19423
19419
|
}
|
|
19424
19420
|
});
|
|
19425
19421
|
if (searchTermFilters.length > 0) {
|
|
@@ -19504,7 +19500,9 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19504
19500
|
},
|
|
19505
19501
|
{
|
|
19506
19502
|
[filterOn]: {
|
|
19507
|
-
_gt: new Date(
|
|
19503
|
+
_gt: new Date(
|
|
19504
|
+
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
19505
|
+
)
|
|
19508
19506
|
}
|
|
19509
19507
|
}
|
|
19510
19508
|
]
|
|
@@ -19554,6 +19552,10 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19554
19552
|
console.warn(`Unsupported filter type: ${selectedFilter}`);
|
|
19555
19553
|
return {};
|
|
19556
19554
|
}
|
|
19555
|
+
}).map((filter2) => {
|
|
19556
|
+
const o2 = {};
|
|
19557
|
+
set$1(o2, Object.keys(filter2)[0], filter2[Object.keys(filter2)[0]]);
|
|
19558
|
+
return o2;
|
|
19557
19559
|
});
|
|
19558
19560
|
if (filterClauses.length > 0) {
|
|
19559
19561
|
if (Object.keys(where).length > 0) {
|
|
@@ -19640,6 +19642,9 @@ function applyWhereClause(records, where) {
|
|
|
19640
19642
|
} else {
|
|
19641
19643
|
const value = record[key];
|
|
19642
19644
|
const conditions = filter2[key];
|
|
19645
|
+
if (isObject$2(value) && isObject$2(conditions) && !hasOperator(conditions)) {
|
|
19646
|
+
return applyFilter(value, conditions);
|
|
19647
|
+
}
|
|
19643
19648
|
for (const operator in conditions) {
|
|
19644
19649
|
const conditionValue = conditions[operator];
|
|
19645
19650
|
if (operator === "_gt" && conditions._lt) {
|
|
@@ -19737,6 +19742,10 @@ function applyWhereClause(records, where) {
|
|
|
19737
19742
|
return true;
|
|
19738
19743
|
}
|
|
19739
19744
|
__name(applyFilter, "applyFilter");
|
|
19745
|
+
function hasOperator(obj) {
|
|
19746
|
+
return Object.keys(obj).some((key) => key.startsWith("_"));
|
|
19747
|
+
}
|
|
19748
|
+
__name(hasOperator, "hasOperator");
|
|
19740
19749
|
return records.filter((record) => applyFilter(record, where));
|
|
19741
19750
|
}
|
|
19742
19751
|
__name(applyWhereClause, "applyWhereClause");
|
|
@@ -19997,7 +20006,7 @@ function getQueryParams({
|
|
|
19997
20006
|
}
|
|
19998
20007
|
});
|
|
19999
20008
|
}
|
|
20000
|
-
|
|
20009
|
+
let toRet = {
|
|
20001
20010
|
//these are values that might be generally useful for the wrapped component
|
|
20002
20011
|
page,
|
|
20003
20012
|
pageSize: ownProps.controlled_pageSize || pageSize,
|
|
@@ -20016,16 +20025,16 @@ function getQueryParams({
|
|
|
20016
20025
|
initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
|
|
20017
20026
|
addCustomColumnFilters(where, schema.fields, currentParams);
|
|
20018
20027
|
if (isLocalCall) {
|
|
20019
|
-
|
|
20028
|
+
toRet = __spreadValues(__spreadValues({}, toRet), filterLocalEntitiesToHasura(entities, {
|
|
20020
20029
|
where,
|
|
20021
20030
|
order_by,
|
|
20022
20031
|
limit,
|
|
20023
20032
|
offset: offset3,
|
|
20024
20033
|
isInfinite
|
|
20025
|
-
});
|
|
20034
|
+
}));
|
|
20026
20035
|
return toRet;
|
|
20027
20036
|
} else {
|
|
20028
|
-
return __spreadProps(__spreadValues({},
|
|
20037
|
+
return __spreadProps(__spreadValues({}, toRet), {
|
|
20029
20038
|
variables: {
|
|
20030
20039
|
where,
|
|
20031
20040
|
order_by,
|
|
@@ -56480,7 +56489,7 @@ const DataTable = /* @__PURE__ */ __name((_I) => {
|
|
|
56480
56489
|
}) : !val;
|
|
56481
56490
|
});
|
|
56482
56491
|
}
|
|
56483
|
-
if (noValsForField) {
|
|
56492
|
+
if (noValsForField && entities.length) {
|
|
56484
56493
|
return __spreadProps(__spreadValues({}, field), {
|
|
56485
56494
|
isHidden: true,
|
|
56486
56495
|
isForcedHidden: true
|
package/package.json
CHANGED
package/src/DataTable/index.js
CHANGED
|
@@ -77,6 +77,15 @@ function applyWhereClause(records, where) {
|
|
|
77
77
|
const value = record[key];
|
|
78
78
|
const conditions = filter[key];
|
|
79
79
|
|
|
80
|
+
// Handle nested object properties
|
|
81
|
+
if (
|
|
82
|
+
isObject(value) &&
|
|
83
|
+
isObject(conditions) &&
|
|
84
|
+
!hasOperator(conditions)
|
|
85
|
+
) {
|
|
86
|
+
return applyFilter(value, conditions);
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
for (const operator in conditions) {
|
|
81
90
|
const conditionValue = conditions[operator];
|
|
82
91
|
|
|
@@ -208,6 +217,11 @@ function applyWhereClause(records, where) {
|
|
|
208
217
|
return true;
|
|
209
218
|
}
|
|
210
219
|
|
|
220
|
+
// Helper to check if an object contains any Hasura operators
|
|
221
|
+
function hasOperator(obj) {
|
|
222
|
+
return Object.keys(obj).some(key => key.startsWith("_"));
|
|
223
|
+
}
|
|
224
|
+
|
|
211
225
|
return records.filter(record => applyFilter(record, where));
|
|
212
226
|
}
|
|
213
227
|
|
|
@@ -297,6 +297,55 @@ describe("filterLocalEntitiesToHasura", () => {
|
|
|
297
297
|
expect(result.entitiesAcrossPages).toEqual([records[0]]);
|
|
298
298
|
expect(result.entityCount).toBe(1);
|
|
299
299
|
});
|
|
300
|
+
it("should filter with nested filters in _and and _or properly ", () => {
|
|
301
|
+
const result = filterLocalEntitiesToHasura(
|
|
302
|
+
[
|
|
303
|
+
{
|
|
304
|
+
id: 1,
|
|
305
|
+
type: {
|
|
306
|
+
special: "01"
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
id: 2,
|
|
311
|
+
type: {
|
|
312
|
+
special: "02"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
{
|
|
317
|
+
where: {
|
|
318
|
+
_and: [
|
|
319
|
+
{
|
|
320
|
+
type: {
|
|
321
|
+
special: {
|
|
322
|
+
_ilike: "%01%"
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
_or: []
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
expect(result.entities).toEqual([
|
|
332
|
+
{
|
|
333
|
+
id: 1,
|
|
334
|
+
type: {
|
|
335
|
+
special: "01"
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
]);
|
|
339
|
+
expect(result.entitiesAcrossPages).toEqual([
|
|
340
|
+
{
|
|
341
|
+
id: 1,
|
|
342
|
+
type: {
|
|
343
|
+
special: "01"
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
]);
|
|
347
|
+
expect(result.entityCount).toBe(1);
|
|
348
|
+
});
|
|
300
349
|
|
|
301
350
|
it("should handle empty where clause", () => {
|
|
302
351
|
const result = filterLocalEntitiesToHasura(records, {});
|
|
@@ -303,7 +303,7 @@ export function getQueryParams({
|
|
|
303
303
|
});
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
|
|
306
|
+
let toRet = {
|
|
307
307
|
//these are values that might be generally useful for the wrapped component
|
|
308
308
|
page,
|
|
309
309
|
pageSize: ownProps.controlled_pageSize || pageSize,
|
|
@@ -325,17 +325,20 @@ export function getQueryParams({
|
|
|
325
325
|
if (isLocalCall) {
|
|
326
326
|
//if the table is local (aka not directly connected to a db) then we need to
|
|
327
327
|
//handle filtering/paging/sorting all on the front end
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
328
|
+
toRet = {
|
|
329
|
+
...toRet,
|
|
330
|
+
...filterLocalEntitiesToHasura(entities, {
|
|
331
|
+
where,
|
|
332
|
+
order_by,
|
|
333
|
+
limit,
|
|
334
|
+
offset,
|
|
335
|
+
isInfinite
|
|
336
|
+
})
|
|
337
|
+
};
|
|
335
338
|
return toRet;
|
|
336
339
|
} else {
|
|
337
340
|
return {
|
|
338
|
-
...
|
|
341
|
+
...toRet,
|
|
339
342
|
variables: {
|
|
340
343
|
where,
|
|
341
344
|
order_by,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { camelCase } from "lodash-es";
|
|
1
|
+
import { camelCase, set } from "lodash-es";
|
|
2
2
|
|
|
3
3
|
export function tableQueryParamsToHasuraClauses({
|
|
4
4
|
page,
|
|
@@ -23,9 +23,8 @@ export function tableQueryParamsToHasuraClauses({
|
|
|
23
23
|
const filterValue = searchTerm; // No cleaning needed here, we're using _ilike
|
|
24
24
|
|
|
25
25
|
if (type === "string" || type === "lookup") {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
26
|
+
const o = set({}, path, { _ilike: `%${filterValue}%` });
|
|
27
|
+
searchTermFilters.push(o);
|
|
29
28
|
} else if (type === "boolean") {
|
|
30
29
|
let regex;
|
|
31
30
|
try {
|
|
@@ -35,22 +34,19 @@ export function tableQueryParamsToHasuraClauses({
|
|
|
35
34
|
}
|
|
36
35
|
if (regex) {
|
|
37
36
|
if ("true".replace(regex, "") !== "true") {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
37
|
+
const o = set({}, path, { _eq: true });
|
|
38
|
+
searchTermFilters.push(o);
|
|
41
39
|
} else if ("false".replace(regex, "") !== "false") {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
40
|
+
const o = set({}, path, { _eq: false });
|
|
41
|
+
searchTermFilters.push(o);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
} else if (
|
|
48
45
|
(type === "number" || type === "integer") &&
|
|
49
46
|
!isNaN(filterValue)
|
|
50
47
|
) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
48
|
+
const o = set({}, path, { _eq: parseFloat(filterValue) });
|
|
49
|
+
searchTermFilters.push(o);
|
|
54
50
|
}
|
|
55
51
|
});
|
|
56
52
|
if (searchTermFilters.length > 0) {
|
|
@@ -63,143 +59,150 @@ export function tableQueryParamsToHasuraClauses({
|
|
|
63
59
|
}
|
|
64
60
|
|
|
65
61
|
if (filters && filters.length > 0) {
|
|
66
|
-
const filterClauses = filters
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const filterClauses = filters
|
|
63
|
+
.map(filter => {
|
|
64
|
+
let { selectedFilter, filterOn, filterValue } = filter;
|
|
65
|
+
const fieldSchema = ccFields[filterOn] || {};
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (type === "number" || type === "integer") {
|
|
86
|
-
filterValue = Array.isArray(filterValue)
|
|
87
|
-
? filterValue.map(val => Number(val))
|
|
88
|
-
: Number(filterValue);
|
|
89
|
-
}
|
|
67
|
+
const { path, reference, type } = fieldSchema;
|
|
68
|
+
let stringFilterValue =
|
|
69
|
+
filterValue && filterValue.toString
|
|
70
|
+
? filterValue.toString()
|
|
71
|
+
: filterValue;
|
|
72
|
+
if (stringFilterValue === false) {
|
|
73
|
+
// we still want to be able to search for the string "false" which will get parsed to false
|
|
74
|
+
stringFilterValue = "false";
|
|
75
|
+
} else {
|
|
76
|
+
stringFilterValue = stringFilterValue || "";
|
|
77
|
+
}
|
|
78
|
+
const arrayFilterValue = Array.isArray(filterValue)
|
|
79
|
+
? filterValue
|
|
80
|
+
: stringFilterValue.split(";");
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
);
|
|
97
|
-
}
|
|
82
|
+
if (type === "number" || type === "integer") {
|
|
83
|
+
filterValue = Array.isArray(filterValue)
|
|
84
|
+
? filterValue.map(val => Number(val))
|
|
85
|
+
: Number(filterValue);
|
|
86
|
+
}
|
|
98
87
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
if (fieldSchema.normalizeFilter) {
|
|
89
|
+
filterValue = fieldSchema.normalizeFilter(
|
|
90
|
+
filterValue,
|
|
91
|
+
selectedFilter,
|
|
92
|
+
filterOn
|
|
93
|
+
);
|
|
94
|
+
}
|
|
104
95
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
96
|
+
if (reference) {
|
|
97
|
+
filterOn = reference.sourceField;
|
|
98
|
+
} else {
|
|
99
|
+
filterOn = path || filterOn;
|
|
100
|
+
}
|
|
101
|
+
switch (selectedFilter) {
|
|
102
|
+
case "none":
|
|
103
|
+
return {};
|
|
104
|
+
case "startsWith":
|
|
105
|
+
return { [filterOn]: { _ilike: `${filterValue}%` } };
|
|
106
|
+
case "endsWith":
|
|
107
|
+
return { [filterOn]: { _ilike: `%${filterValue}` } };
|
|
108
|
+
case "contains":
|
|
109
|
+
return { [filterOn]: { _ilike: `%${filterValue}%` } };
|
|
110
|
+
case "notContains":
|
|
111
|
+
return { [filterOn]: { _not_ilike: `%${filterValue}%` } };
|
|
112
|
+
case "isExactly":
|
|
113
|
+
return { [filterOn]: { _eq: filterValue } };
|
|
114
|
+
case "isEmpty":
|
|
115
|
+
return {
|
|
116
|
+
_or: [
|
|
117
|
+
{ [filterOn]: { _eq: "" } },
|
|
118
|
+
{ [filterOn]: { _is_null: true } }
|
|
119
|
+
]
|
|
120
|
+
};
|
|
121
|
+
case "notEmpty":
|
|
122
|
+
return {
|
|
123
|
+
_and: [
|
|
124
|
+
{ [filterOn]: { _neq: "" } },
|
|
125
|
+
{ [filterOn]: { _is_null: false } }
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
case "inList":
|
|
129
|
+
return { [filterOn]: { _in: filterValue } };
|
|
130
|
+
case "notInList":
|
|
131
|
+
return { [filterOn]: { _nin: filterValue } };
|
|
132
|
+
case "true":
|
|
133
|
+
return { [filterOn]: { _eq: true } };
|
|
134
|
+
case "false":
|
|
135
|
+
return { [filterOn]: { _eq: false } };
|
|
136
|
+
case "dateIs":
|
|
137
|
+
return { [filterOn]: { _eq: filterValue } };
|
|
138
|
+
case "notBetween":
|
|
139
|
+
return {
|
|
140
|
+
_or: [
|
|
141
|
+
{
|
|
142
|
+
[filterOn]: {
|
|
143
|
+
_lt: new Date(arrayFilterValue[0])
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
[filterOn]: {
|
|
148
|
+
_gt: new Date(
|
|
149
|
+
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
150
|
+
)
|
|
151
|
+
}
|
|
153
152
|
}
|
|
153
|
+
]
|
|
154
|
+
};
|
|
155
|
+
case "isBetween":
|
|
156
|
+
return {
|
|
157
|
+
[filterOn]: {
|
|
158
|
+
_gte: new Date(arrayFilterValue[0]),
|
|
159
|
+
_lte: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
154
160
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
[filterOn]: {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return { [filterOn]: { _gt: parseFloat(filterValue) } };
|
|
170
|
-
case "lessThan":
|
|
171
|
-
return { [filterOn]: { _lt: parseFloat(filterValue) } };
|
|
172
|
-
case "inRange":
|
|
173
|
-
return {
|
|
174
|
-
[filterOn]: {
|
|
175
|
-
_gte: parseFloat(arrayFilterValue[0]),
|
|
176
|
-
_lte: parseFloat(arrayFilterValue[1])
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
case "outsideRange":
|
|
180
|
-
return {
|
|
181
|
-
_or: [
|
|
182
|
-
{
|
|
183
|
-
[filterOn]: {
|
|
184
|
-
_lt: parseFloat(arrayFilterValue[0])
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
[filterOn]: {
|
|
189
|
-
_gt: parseFloat(arrayFilterValue[1])
|
|
190
|
-
}
|
|
161
|
+
};
|
|
162
|
+
case "isBefore":
|
|
163
|
+
return { [filterOn]: { _lt: new Date(filterValue) } };
|
|
164
|
+
case "isAfter":
|
|
165
|
+
return { [filterOn]: { _gt: new Date(filterValue) } };
|
|
166
|
+
case "greaterThan":
|
|
167
|
+
return { [filterOn]: { _gt: parseFloat(filterValue) } };
|
|
168
|
+
case "lessThan":
|
|
169
|
+
return { [filterOn]: { _lt: parseFloat(filterValue) } };
|
|
170
|
+
case "inRange":
|
|
171
|
+
return {
|
|
172
|
+
[filterOn]: {
|
|
173
|
+
_gte: parseFloat(arrayFilterValue[0]),
|
|
174
|
+
_lte: parseFloat(arrayFilterValue[1])
|
|
191
175
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
176
|
+
};
|
|
177
|
+
case "outsideRange":
|
|
178
|
+
return {
|
|
179
|
+
_or: [
|
|
180
|
+
{
|
|
181
|
+
[filterOn]: {
|
|
182
|
+
_lt: parseFloat(arrayFilterValue[0])
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
[filterOn]: {
|
|
187
|
+
_gt: parseFloat(arrayFilterValue[1])
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
};
|
|
192
|
+
case "equalTo":
|
|
193
|
+
return { [filterOn]: { _eq: parseFloat(filterValue) } };
|
|
194
|
+
case "regex":
|
|
195
|
+
return { [filterOn]: { _regex: filterValue } };
|
|
196
|
+
default:
|
|
197
|
+
console.warn(`Unsupported filter type: ${selectedFilter}`);
|
|
198
|
+
return {};
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
.map(filter => {
|
|
202
|
+
const o = {};
|
|
203
|
+
set(o, Object.keys(filter)[0], filter[Object.keys(filter)[0]]);
|
|
204
|
+
return o;
|
|
205
|
+
});
|
|
203
206
|
|
|
204
207
|
if (filterClauses.length > 0) {
|
|
205
208
|
if (Object.keys(where).length > 0) {
|