@teselagen/ui 0.8.6-beta.10 → 0.8.6-beta.12
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/index.cjs.js +25 -26
- package/index.es.js +25 -26
- package/package.json +1 -2
- package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +1 -1
- package/src/DataTable/utils/queryParams.js +1 -3
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +178 -176
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +19 -0
package/index.cjs.js
CHANGED
|
@@ -19422,34 +19422,37 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19422
19422
|
if (searchTerm) {
|
|
19423
19423
|
const searchTermFilters = [];
|
|
19424
19424
|
const uniqueFieldsByPath = {};
|
|
19425
|
+
const searchTerms = searchTerm.split(",");
|
|
19425
19426
|
schema.fields.forEach((field) => {
|
|
19426
19427
|
const { type: type2, path: path2, searchDisabled } = field;
|
|
19427
19428
|
if (uniqueFieldsByPath[path2]) return;
|
|
19428
19429
|
uniqueFieldsByPath[path2] = true;
|
|
19429
19430
|
if (searchDisabled || field.filterDisabled || type2 === "color") return;
|
|
19430
|
-
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
if (regex) {
|
|
19441
|
-
if ("true".replace(regex, "") !== "true") {
|
|
19442
|
-
const o2 = set$1({}, path2, { _eq: true });
|
|
19443
|
-
searchTermFilters.push(o2);
|
|
19444
|
-
} else if ("false".replace(regex, "") !== "false") {
|
|
19445
|
-
const o2 = set$1({}, path2, { _eq: false });
|
|
19446
|
-
searchTermFilters.push(o2);
|
|
19431
|
+
searchTerms.forEach((term) => {
|
|
19432
|
+
const filterValue = term.trim();
|
|
19433
|
+
if (type2 === "string" || type2 === "lookup") {
|
|
19434
|
+
const o2 = set$1({}, path2, { _ilike: `%${filterValue}%` });
|
|
19435
|
+
searchTermFilters.push(o2);
|
|
19436
|
+
} else if (type2 === "boolean") {
|
|
19437
|
+
let regex;
|
|
19438
|
+
try {
|
|
19439
|
+
regex = new RegExp("^" + filterValue, "ig");
|
|
19440
|
+
} catch (error) {
|
|
19447
19441
|
}
|
|
19442
|
+
if (regex) {
|
|
19443
|
+
if ("true".replace(regex, "") !== "true") {
|
|
19444
|
+
const o2 = set$1({}, path2, { _eq: true });
|
|
19445
|
+
searchTermFilters.push(o2);
|
|
19446
|
+
} else if ("false".replace(regex, "") !== "false") {
|
|
19447
|
+
const o2 = set$1({}, path2, { _eq: false });
|
|
19448
|
+
searchTermFilters.push(o2);
|
|
19449
|
+
}
|
|
19450
|
+
}
|
|
19451
|
+
} else if ((type2 === "number" || type2 === "integer") && !isNaN(filterValue)) {
|
|
19452
|
+
const o2 = set$1({}, path2, { _eq: parseFloat(filterValue) });
|
|
19453
|
+
searchTermFilters.push(o2);
|
|
19448
19454
|
}
|
|
19449
|
-
}
|
|
19450
|
-
const o2 = set$1({}, path2, { _eq: parseFloat(filterValue) });
|
|
19451
|
-
searchTermFilters.push(o2);
|
|
19452
|
-
}
|
|
19455
|
+
});
|
|
19453
19456
|
});
|
|
19454
19457
|
if (searchTermFilters.length > 0) {
|
|
19455
19458
|
if (Object.keys(where).length > 0) {
|
|
@@ -19462,10 +19465,8 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19462
19465
|
if (filters && filters.length > 0) {
|
|
19463
19466
|
const filterClauses = filters.map((filter2) => {
|
|
19464
19467
|
let { selectedFilter, filterOn, filterValue } = filter2;
|
|
19465
|
-
console.log("filterOn:", filterOn);
|
|
19466
19468
|
const fieldSchema = ccFields[filterOn] || {};
|
|
19467
19469
|
const { path: path2, reference: reference2, type: type2, customColumnFilter } = fieldSchema;
|
|
19468
|
-
console.log("customColumnFilter:", customColumnFilter);
|
|
19469
19470
|
if (customColumnFilter) {
|
|
19470
19471
|
return customColumnFilter(filterValue);
|
|
19471
19472
|
}
|
|
@@ -19545,9 +19546,7 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19545
19546
|
},
|
|
19546
19547
|
{
|
|
19547
19548
|
[filterOn]: {
|
|
19548
|
-
_gt: new Date(
|
|
19549
|
-
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
19550
|
-
)
|
|
19549
|
+
_gt: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
19551
19550
|
}
|
|
19552
19551
|
}
|
|
19553
19552
|
]
|
package/index.es.js
CHANGED
|
@@ -19404,34 +19404,37 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19404
19404
|
if (searchTerm) {
|
|
19405
19405
|
const searchTermFilters = [];
|
|
19406
19406
|
const uniqueFieldsByPath = {};
|
|
19407
|
+
const searchTerms = searchTerm.split(",");
|
|
19407
19408
|
schema.fields.forEach((field) => {
|
|
19408
19409
|
const { type: type2, path: path2, searchDisabled } = field;
|
|
19409
19410
|
if (uniqueFieldsByPath[path2]) return;
|
|
19410
19411
|
uniqueFieldsByPath[path2] = true;
|
|
19411
19412
|
if (searchDisabled || field.filterDisabled || type2 === "color") return;
|
|
19412
|
-
|
|
19413
|
-
|
|
19414
|
-
|
|
19415
|
-
|
|
19416
|
-
|
|
19417
|
-
|
|
19418
|
-
|
|
19419
|
-
|
|
19420
|
-
|
|
19421
|
-
|
|
19422
|
-
if (regex) {
|
|
19423
|
-
if ("true".replace(regex, "") !== "true") {
|
|
19424
|
-
const o2 = set$1({}, path2, { _eq: true });
|
|
19425
|
-
searchTermFilters.push(o2);
|
|
19426
|
-
} else if ("false".replace(regex, "") !== "false") {
|
|
19427
|
-
const o2 = set$1({}, path2, { _eq: false });
|
|
19428
|
-
searchTermFilters.push(o2);
|
|
19413
|
+
searchTerms.forEach((term) => {
|
|
19414
|
+
const filterValue = term.trim();
|
|
19415
|
+
if (type2 === "string" || type2 === "lookup") {
|
|
19416
|
+
const o2 = set$1({}, path2, { _ilike: `%${filterValue}%` });
|
|
19417
|
+
searchTermFilters.push(o2);
|
|
19418
|
+
} else if (type2 === "boolean") {
|
|
19419
|
+
let regex;
|
|
19420
|
+
try {
|
|
19421
|
+
regex = new RegExp("^" + filterValue, "ig");
|
|
19422
|
+
} catch (error) {
|
|
19429
19423
|
}
|
|
19424
|
+
if (regex) {
|
|
19425
|
+
if ("true".replace(regex, "") !== "true") {
|
|
19426
|
+
const o2 = set$1({}, path2, { _eq: true });
|
|
19427
|
+
searchTermFilters.push(o2);
|
|
19428
|
+
} else if ("false".replace(regex, "") !== "false") {
|
|
19429
|
+
const o2 = set$1({}, path2, { _eq: false });
|
|
19430
|
+
searchTermFilters.push(o2);
|
|
19431
|
+
}
|
|
19432
|
+
}
|
|
19433
|
+
} else if ((type2 === "number" || type2 === "integer") && !isNaN(filterValue)) {
|
|
19434
|
+
const o2 = set$1({}, path2, { _eq: parseFloat(filterValue) });
|
|
19435
|
+
searchTermFilters.push(o2);
|
|
19430
19436
|
}
|
|
19431
|
-
}
|
|
19432
|
-
const o2 = set$1({}, path2, { _eq: parseFloat(filterValue) });
|
|
19433
|
-
searchTermFilters.push(o2);
|
|
19434
|
-
}
|
|
19437
|
+
});
|
|
19435
19438
|
});
|
|
19436
19439
|
if (searchTermFilters.length > 0) {
|
|
19437
19440
|
if (Object.keys(where).length > 0) {
|
|
@@ -19444,10 +19447,8 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19444
19447
|
if (filters && filters.length > 0) {
|
|
19445
19448
|
const filterClauses = filters.map((filter2) => {
|
|
19446
19449
|
let { selectedFilter, filterOn, filterValue } = filter2;
|
|
19447
|
-
console.log("filterOn:", filterOn);
|
|
19448
19450
|
const fieldSchema = ccFields[filterOn] || {};
|
|
19449
19451
|
const { path: path2, reference: reference2, type: type2, customColumnFilter } = fieldSchema;
|
|
19450
|
-
console.log("customColumnFilter:", customColumnFilter);
|
|
19451
19452
|
if (customColumnFilter) {
|
|
19452
19453
|
return customColumnFilter(filterValue);
|
|
19453
19454
|
}
|
|
@@ -19527,9 +19528,7 @@ function tableQueryParamsToHasuraClauses({
|
|
|
19527
19528
|
},
|
|
19528
19529
|
{
|
|
19529
19530
|
[filterOn]: {
|
|
19530
|
-
_gt: new Date(
|
|
19531
|
-
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
19532
|
-
)
|
|
19531
|
+
_gt: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
19533
19532
|
}
|
|
19534
19533
|
}
|
|
19535
19534
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teselagen/ui",
|
|
3
|
-
"version": "0.8.6-beta.
|
|
3
|
+
"version": "0.8.6-beta.12",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"@dnd-kit/core": "^6.1.0",
|
|
18
18
|
"@dnd-kit/modifiers": "^7.0.0",
|
|
19
19
|
"@dnd-kit/sortable": "^8.0.0",
|
|
20
|
-
"@teselagen/react-table": "6.10.16",
|
|
21
20
|
"classnames": "^2.3.2",
|
|
22
21
|
"color": "^3.2.1",
|
|
23
22
|
"copy-to-clipboard": "^3.3.1",
|
|
@@ -5,9 +5,7 @@ import {
|
|
|
5
5
|
tableQueryParamsToHasuraClauses
|
|
6
6
|
} from "./tableQueryParamsToHasuraClauses";
|
|
7
7
|
import { filterLocalEntitiesToHasura } from "./filterLocalEntitiesToHasura";
|
|
8
|
-
import {
|
|
9
|
-
initializeHasuraWhereAndFilter
|
|
10
|
-
} from "./initializeHasuraWhereAndFilter";
|
|
8
|
+
import { initializeHasuraWhereAndFilter } from "./initializeHasuraWhereAndFilter";
|
|
11
9
|
|
|
12
10
|
const defaultPageSizes = [5, 10, 15, 25, 50, 100, 200, 400];
|
|
13
11
|
|
|
@@ -20,39 +20,46 @@ export function tableQueryParamsToHasuraClauses({
|
|
|
20
20
|
// Create a map to deduplicate fields by path
|
|
21
21
|
const uniqueFieldsByPath = {};
|
|
22
22
|
|
|
23
|
+
// Split the search term by comma to support multi-term searching
|
|
24
|
+
const searchTerms = searchTerm.split(',');
|
|
25
|
+
|
|
23
26
|
schema.fields.forEach(field => {
|
|
24
27
|
const { type, path, searchDisabled } = field;
|
|
25
28
|
if (uniqueFieldsByPath[path]) return; // Skip if already added
|
|
26
29
|
uniqueFieldsByPath[path] = true;
|
|
27
30
|
if (searchDisabled || field.filterDisabled || type === "color") return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const o = set({}, path, { _eq: true });
|
|
43
|
-
searchTermFilters.push(o);
|
|
44
|
-
} else if ("false".replace(regex, "") !== "false") {
|
|
45
|
-
const o = set({}, path, { _eq: false });
|
|
46
|
-
searchTermFilters.push(o);
|
|
31
|
+
|
|
32
|
+
// Process each search term
|
|
33
|
+
searchTerms.forEach(term => {
|
|
34
|
+
const filterValue = term.trim(); // Trim the term to handle spaces after commas
|
|
35
|
+
|
|
36
|
+
if (type === "string" || type === "lookup") {
|
|
37
|
+
const o = set({}, path, { _ilike: `%${filterValue}%` });
|
|
38
|
+
searchTermFilters.push(o);
|
|
39
|
+
} else if (type === "boolean") {
|
|
40
|
+
let regex;
|
|
41
|
+
try {
|
|
42
|
+
regex = new RegExp("^" + filterValue, "ig");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
//ignore
|
|
47
45
|
}
|
|
46
|
+
if (regex) {
|
|
47
|
+
if ("true".replace(regex, "") !== "true") {
|
|
48
|
+
const o = set({}, path, { _eq: true });
|
|
49
|
+
searchTermFilters.push(o);
|
|
50
|
+
} else if ("false".replace(regex, "") !== "false") {
|
|
51
|
+
const o = set({}, path, { _eq: false });
|
|
52
|
+
searchTermFilters.push(o);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} else if (
|
|
56
|
+
(type === "number" || type === "integer") &&
|
|
57
|
+
!isNaN(filterValue)
|
|
58
|
+
) {
|
|
59
|
+
const o = set({}, path, { _eq: parseFloat(filterValue) });
|
|
60
|
+
searchTermFilters.push(o);
|
|
48
61
|
}
|
|
49
|
-
}
|
|
50
|
-
(type === "number" || type === "integer") &&
|
|
51
|
-
!isNaN(filterValue)
|
|
52
|
-
) {
|
|
53
|
-
const o = set({}, path, { _eq: parseFloat(filterValue) });
|
|
54
|
-
searchTermFilters.push(o);
|
|
55
|
-
}
|
|
62
|
+
});
|
|
56
63
|
});
|
|
57
64
|
|
|
58
65
|
if (searchTermFilters.length > 0) {
|
|
@@ -65,166 +72,161 @@ export function tableQueryParamsToHasuraClauses({
|
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
if (filters && filters.length > 0) {
|
|
68
|
-
const filterClauses = filters
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
console.log('filterOn:', filterOn)
|
|
72
|
-
const fieldSchema = ccFields[filterOn] || {};
|
|
75
|
+
const filterClauses = filters.map(filter => {
|
|
76
|
+
let { selectedFilter, filterOn, filterValue } = filter;
|
|
77
|
+
const fieldSchema = ccFields[filterOn] || {};
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
: stringFilterValue.split(";");
|
|
79
|
+
const { path, reference, type, customColumnFilter } = fieldSchema;
|
|
80
|
+
if (customColumnFilter) {
|
|
81
|
+
return customColumnFilter(filterValue);
|
|
82
|
+
}
|
|
83
|
+
let stringFilterValue =
|
|
84
|
+
filterValue && filterValue.toString
|
|
85
|
+
? filterValue.toString()
|
|
86
|
+
: filterValue;
|
|
87
|
+
if (stringFilterValue === false) {
|
|
88
|
+
// we still want to be able to search for the string "false" which will get parsed to false
|
|
89
|
+
stringFilterValue = "false";
|
|
90
|
+
} else {
|
|
91
|
+
stringFilterValue = stringFilterValue || "";
|
|
92
|
+
}
|
|
93
|
+
const arrayFilterValue = Array.isArray(filterValue)
|
|
94
|
+
? filterValue
|
|
95
|
+
: stringFilterValue.split(";");
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
if (type === "number" || type === "integer") {
|
|
98
|
+
filterValue = Array.isArray(filterValue)
|
|
99
|
+
? filterValue.map(val => Number(val))
|
|
100
|
+
: Number(filterValue);
|
|
101
|
+
}
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
if (fieldSchema.normalizeFilter) {
|
|
104
|
+
filterValue = fieldSchema.normalizeFilter(
|
|
105
|
+
filterValue,
|
|
106
|
+
selectedFilter,
|
|
107
|
+
filterOn
|
|
108
|
+
);
|
|
109
|
+
}
|
|
106
110
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
_not: {
|
|
131
|
-
[filterOn.split(".")[0]]: {}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
_or: [
|
|
137
|
-
{ [filterOn]: { _eq: "" } },
|
|
138
|
-
{ [filterOn]: { _is_null: true } }
|
|
139
|
-
]
|
|
140
|
-
};
|
|
141
|
-
case "notEmpty":
|
|
142
|
-
return {
|
|
143
|
-
_and: [
|
|
144
|
-
{ [filterOn]: { _neq: "" } },
|
|
145
|
-
{ [filterOn]: { _is_null: false } }
|
|
146
|
-
]
|
|
147
|
-
};
|
|
148
|
-
case "inList":
|
|
149
|
-
return { [filterOn]: { _in: filterValue } };
|
|
150
|
-
case "notInList":
|
|
151
|
-
return { [filterOn]: { _nin: filterValue } };
|
|
152
|
-
case "true":
|
|
153
|
-
return { [filterOn]: { _eq: true } };
|
|
154
|
-
case "false":
|
|
155
|
-
return { [filterOn]: { _eq: false } };
|
|
156
|
-
case "dateIs":
|
|
157
|
-
return { [filterOn]: { _eq: filterValue } };
|
|
158
|
-
case "notBetween":
|
|
159
|
-
return {
|
|
160
|
-
_or: [
|
|
161
|
-
{
|
|
162
|
-
[filterOn]: {
|
|
163
|
-
_lt: new Date(arrayFilterValue[0])
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
[filterOn]: {
|
|
168
|
-
_gt: new Date(
|
|
169
|
-
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
]
|
|
174
|
-
};
|
|
175
|
-
case "isBetween":
|
|
111
|
+
if (reference) {
|
|
112
|
+
filterOn = reference.sourceField;
|
|
113
|
+
} else {
|
|
114
|
+
filterOn = path || filterOn;
|
|
115
|
+
}
|
|
116
|
+
switch (selectedFilter) {
|
|
117
|
+
case "none":
|
|
118
|
+
return {};
|
|
119
|
+
case "startsWith":
|
|
120
|
+
return { [filterOn]: { _ilike: `${filterValue}%` } };
|
|
121
|
+
case "endsWith":
|
|
122
|
+
return { [filterOn]: { _ilike: `%${filterValue}` } };
|
|
123
|
+
case "contains":
|
|
124
|
+
return { [filterOn]: { _ilike: `%${filterValue}%` } };
|
|
125
|
+
case "notContains":
|
|
126
|
+
return { [filterOn]: { _nilike: `%${filterValue}%` } };
|
|
127
|
+
case "isExactly":
|
|
128
|
+
return { [filterOn]: { _eq: filterValue } };
|
|
129
|
+
case "isEmpty":
|
|
130
|
+
if (filterOn.includes(".")) {
|
|
131
|
+
// if we're filtering on a nested field, like a sequence table with parts.name
|
|
132
|
+
// we really want to just query on the top level field's existence
|
|
176
133
|
return {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
_lte: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
134
|
+
_not: {
|
|
135
|
+
[filterOn.split(".")[0]]: {}
|
|
180
136
|
}
|
|
181
137
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
[filterOn]: {
|
|
193
|
-
|
|
194
|
-
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
_or: [
|
|
141
|
+
{ [filterOn]: { _eq: "" } },
|
|
142
|
+
{ [filterOn]: { _is_null: true } }
|
|
143
|
+
]
|
|
144
|
+
};
|
|
145
|
+
case "notEmpty":
|
|
146
|
+
return {
|
|
147
|
+
_and: [
|
|
148
|
+
{ [filterOn]: { _neq: "" } },
|
|
149
|
+
{ [filterOn]: { _is_null: false } }
|
|
150
|
+
]
|
|
151
|
+
};
|
|
152
|
+
case "inList":
|
|
153
|
+
return { [filterOn]: { _in: filterValue } };
|
|
154
|
+
case "notInList":
|
|
155
|
+
return { [filterOn]: { _nin: filterValue } };
|
|
156
|
+
case "true":
|
|
157
|
+
return { [filterOn]: { _eq: true } };
|
|
158
|
+
case "false":
|
|
159
|
+
return { [filterOn]: { _eq: false } };
|
|
160
|
+
case "dateIs":
|
|
161
|
+
return { [filterOn]: { _eq: filterValue } };
|
|
162
|
+
case "notBetween":
|
|
163
|
+
return {
|
|
164
|
+
_or: [
|
|
165
|
+
{
|
|
166
|
+
[filterOn]: {
|
|
167
|
+
_lt: new Date(arrayFilterValue[0])
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
[filterOn]: {
|
|
172
|
+
_gt: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
173
|
+
}
|
|
195
174
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
175
|
+
]
|
|
176
|
+
};
|
|
177
|
+
case "isBetween":
|
|
178
|
+
return {
|
|
179
|
+
[filterOn]: {
|
|
180
|
+
_gte: new Date(arrayFilterValue[0]),
|
|
181
|
+
_lte: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
case "isBefore":
|
|
185
|
+
return { [filterOn]: { _lt: new Date(filterValue) } };
|
|
186
|
+
case "isAfter":
|
|
187
|
+
return { [filterOn]: { _gt: new Date(filterValue) } };
|
|
188
|
+
case "greaterThan":
|
|
189
|
+
return { [filterOn]: { _gt: parseFloat(filterValue) } };
|
|
190
|
+
case "lessThan":
|
|
191
|
+
return { [filterOn]: { _lt: parseFloat(filterValue) } };
|
|
192
|
+
case "inRange":
|
|
193
|
+
return {
|
|
194
|
+
[filterOn]: {
|
|
195
|
+
_gte: parseFloat(arrayFilterValue[0]),
|
|
196
|
+
_lte: parseFloat(arrayFilterValue[1])
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
case "outsideRange":
|
|
200
|
+
return {
|
|
201
|
+
_or: [
|
|
202
|
+
{
|
|
203
|
+
[filterOn]: {
|
|
204
|
+
_lt: parseFloat(arrayFilterValue[0])
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
[filterOn]: {
|
|
209
|
+
_gt: parseFloat(arrayFilterValue[1])
|
|
209
210
|
}
|
|
210
|
-
]
|
|
211
|
-
};
|
|
212
|
-
case "equalTo":
|
|
213
|
-
return {
|
|
214
|
-
[filterOn]: {
|
|
215
|
-
_eq:
|
|
216
|
-
type === "number" || type === "integer"
|
|
217
|
-
? parseFloat(filterValue)
|
|
218
|
-
: filterValue
|
|
219
211
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
212
|
+
]
|
|
213
|
+
};
|
|
214
|
+
case "equalTo":
|
|
215
|
+
return {
|
|
216
|
+
[filterOn]: {
|
|
217
|
+
_eq:
|
|
218
|
+
type === "number" || type === "integer"
|
|
219
|
+
? parseFloat(filterValue)
|
|
220
|
+
: filterValue
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
case "regex":
|
|
224
|
+
return { [filterOn]: { _regex: filterValue } };
|
|
225
|
+
default:
|
|
226
|
+
console.warn(`Unsupported filter type: ${selectedFilter}`);
|
|
227
|
+
return {};
|
|
228
|
+
}
|
|
229
|
+
});
|
|
228
230
|
|
|
229
231
|
if (filterClauses.length > 0) {
|
|
230
232
|
if (Object.keys(where).length > 0) {
|
|
@@ -44,6 +44,25 @@ describe("tableQueryParamsToHasuraClauses", () => {
|
|
|
44
44
|
offset: 0
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
|
+
it("should handle searchTerm with string fields with a comma in them", () => {
|
|
48
|
+
const result = tableQueryParamsToHasuraClauses({
|
|
49
|
+
searchTerm: "test,test2",
|
|
50
|
+
schema
|
|
51
|
+
});
|
|
52
|
+
expect(result).toEqual({
|
|
53
|
+
where: {
|
|
54
|
+
_or: [
|
|
55
|
+
{ name: { _ilike: "%test%" } },
|
|
56
|
+
{ name: { _ilike: "%test2%" } },
|
|
57
|
+
{ email: { _ilike: "%test%" } },
|
|
58
|
+
{ email: { _ilike: "%test2%" } }
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
order_by: [],
|
|
62
|
+
limit: 25,
|
|
63
|
+
offset: 0
|
|
64
|
+
});
|
|
65
|
+
});
|
|
47
66
|
it("should flatten queries with dup paths", () => {
|
|
48
67
|
const result = tableQueryParamsToHasuraClauses({
|
|
49
68
|
searchTerm: "test",
|