@teselagen/ui 0.8.5 → 0.8.6-beta.3
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/filterLocalEntitiesToHasura.d.ts +5 -0
- package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +2 -0
- package/DataTable/utils/queryParams.d.ts +7 -14
- package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +26 -0
- package/index.cjs.js +847 -973
- package/index.d.ts +1 -0
- package/index.es.js +847 -973
- package/package.json +1 -1
- package/src/DataTable/Columns.js +2 -2
- package/src/DataTable/DisplayOptions.js +1 -1
- package/src/DataTable/FilterAndSortMenu.js +27 -30
- package/src/DataTable/index.js +3 -14
- package/src/DataTable/style.css +1 -1
- package/src/DataTable/utils/filterLocalEntitiesToHasura.js +236 -0
- package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +587 -0
- package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +26 -0
- package/src/DataTable/utils/queryParams.js +64 -772
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +260 -0
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +206 -0
- package/src/DataTable/utils/withTableParams.js +3 -16
- package/src/FormComponents/Uploader.js +5 -1
- package/src/FormComponents/index.js +2 -2
- package/src/autoTooltip.js +1 -0
- package/src/index.js +1 -0
- package/ui.css +1 -1
package/package.json
CHANGED
package/src/DataTable/Columns.js
CHANGED
|
@@ -33,10 +33,10 @@ import getTextFromEl from "../utils/getTextFromEl";
|
|
|
33
33
|
import rowClick, { finalizeSelection } from "./utils/rowClick";
|
|
34
34
|
import { editCellHelper } from "./editCellHelper";
|
|
35
35
|
import { getCellVal } from "./getCellVal";
|
|
36
|
-
import { getCCDisplayName } from "./utils/queryParams";
|
|
37
36
|
import { useDispatch } from "react-redux";
|
|
38
37
|
import { change as _change } from "redux-form";
|
|
39
38
|
import { RenderCell } from "./RenderCell";
|
|
39
|
+
import { getCCDisplayName } from "./utils/tableQueryParamsToHasuraClauses";
|
|
40
40
|
|
|
41
41
|
dayjs.extend(localizedFormat);
|
|
42
42
|
|
|
@@ -104,7 +104,7 @@ const RenderColumnHeader = ({
|
|
|
104
104
|
if (order && order.length) {
|
|
105
105
|
order.forEach(order => {
|
|
106
106
|
const orderField = order.replace("-", "");
|
|
107
|
-
if (orderField ===
|
|
107
|
+
if (orderField === path) {
|
|
108
108
|
if (orderField === order) {
|
|
109
109
|
ordering = "asc";
|
|
110
110
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
2
|
import { DateInput, DateRangeInput } from "@blueprintjs/datetime";
|
|
3
|
-
import { camelCase } from "lodash-es";
|
|
3
|
+
import { camelCase, startCase } from "lodash-es";
|
|
4
4
|
import classNames from "classnames";
|
|
5
5
|
import {
|
|
6
6
|
Menu,
|
|
@@ -349,43 +349,40 @@ function getFilterMenuItems(dataType) {
|
|
|
349
349
|
let filterMenuItems = [];
|
|
350
350
|
if (dataType === "string") {
|
|
351
351
|
filterMenuItems = [
|
|
352
|
-
"
|
|
353
|
-
"
|
|
354
|
-
"
|
|
355
|
-
"
|
|
356
|
-
"
|
|
357
|
-
"
|
|
358
|
-
"
|
|
359
|
-
"
|
|
360
|
-
"
|
|
361
|
-
"
|
|
352
|
+
"contains",
|
|
353
|
+
"notContains",
|
|
354
|
+
"startsWith",
|
|
355
|
+
"endsWith",
|
|
356
|
+
"isExactly",
|
|
357
|
+
"regex",
|
|
358
|
+
"inList",
|
|
359
|
+
"notInList",
|
|
360
|
+
"isEmpty",
|
|
361
|
+
"notEmpty"
|
|
362
362
|
];
|
|
363
363
|
} else if (dataType === "lookup") {
|
|
364
364
|
filterMenuItems = [
|
|
365
|
-
"
|
|
366
|
-
"
|
|
367
|
-
"
|
|
368
|
-
"
|
|
369
|
-
"
|
|
370
|
-
"
|
|
365
|
+
"contains",
|
|
366
|
+
"notContains",
|
|
367
|
+
"startsWith",
|
|
368
|
+
"endsWith",
|
|
369
|
+
"isExactly",
|
|
370
|
+
"regex"
|
|
371
371
|
];
|
|
372
372
|
} else if (dataType === "boolean") {
|
|
373
|
-
filterMenuItems = ["
|
|
373
|
+
filterMenuItems = ["true", "false"];
|
|
374
374
|
} else if (dataType === "number" || dataType === "integer") {
|
|
375
|
-
// else if (dataType === "lookup") {
|
|
376
|
-
// filterMenuItems = ["None"];
|
|
377
|
-
// }
|
|
378
375
|
filterMenuItems = [
|
|
379
|
-
"
|
|
380
|
-
"
|
|
381
|
-
"
|
|
382
|
-
"
|
|
383
|
-
"
|
|
384
|
-
"
|
|
385
|
-
"
|
|
376
|
+
"greaterThan",
|
|
377
|
+
"lessThan",
|
|
378
|
+
"inRange",
|
|
379
|
+
"outsideRange",
|
|
380
|
+
"equalTo",
|
|
381
|
+
"inList",
|
|
382
|
+
"notInList"
|
|
386
383
|
];
|
|
387
384
|
} else if (dataType === "timestamp") {
|
|
388
|
-
filterMenuItems = ["
|
|
385
|
+
filterMenuItems = ["isBetween", "notBetween", "isBefore", "isAfter"];
|
|
389
386
|
}
|
|
390
|
-
return filterMenuItems;
|
|
387
|
+
return filterMenuItems.map(item => startCase(item));
|
|
391
388
|
}
|
package/src/DataTable/index.js
CHANGED
|
@@ -92,7 +92,6 @@ import { viewColumn, openColumn, multiViewColumn } from "./viewColumn";
|
|
|
92
92
|
import convertSchema from "./utils/convertSchema";
|
|
93
93
|
import TableFormTrackerContext from "./TableFormTrackerContext";
|
|
94
94
|
import {
|
|
95
|
-
getCCDisplayName,
|
|
96
95
|
getCurrentParamsFromUrl,
|
|
97
96
|
getQueryParams,
|
|
98
97
|
makeDataTableHandlers,
|
|
@@ -103,6 +102,7 @@ import { formValueSelector, change as _change } from "redux-form";
|
|
|
103
102
|
import { throwFormError } from "../throwFormError";
|
|
104
103
|
import { isObservableArray, toJS } from "mobx";
|
|
105
104
|
import { isBeingCalledExcessively } from "../utils/isBeingCalledExcessively";
|
|
105
|
+
import { getCCDisplayName } from "./utils/tableQueryParamsToHasuraClauses";
|
|
106
106
|
|
|
107
107
|
enablePatches();
|
|
108
108
|
const IS_LINUX = window.navigator.platform.toLowerCase().search("linux") > -1;
|
|
@@ -337,16 +337,6 @@ const DataTable = ({
|
|
|
337
337
|
|
|
338
338
|
const queryParams = useMemo(() => {
|
|
339
339
|
if (!isTableParamsConnected) {
|
|
340
|
-
const additionalFilterToUse =
|
|
341
|
-
typeof props.additionalFilter === "function"
|
|
342
|
-
? props.additionalFilter
|
|
343
|
-
: () => props.additionalFilter;
|
|
344
|
-
|
|
345
|
-
const additionalOrFilterToUse =
|
|
346
|
-
typeof props.additionalOrFilter === "function"
|
|
347
|
-
? props.additionalOrFilter
|
|
348
|
-
: () => props.additionalOrFilter;
|
|
349
|
-
|
|
350
340
|
return getQueryParams({
|
|
351
341
|
doNotCoercePageSize,
|
|
352
342
|
currentParams,
|
|
@@ -356,8 +346,7 @@ const DataTable = ({
|
|
|
356
346
|
schema: convertedSchema,
|
|
357
347
|
isInfinite,
|
|
358
348
|
isLocalCall,
|
|
359
|
-
additionalFilter:
|
|
360
|
-
additionalOrFilter: additionalOrFilterToUse,
|
|
349
|
+
additionalFilter: props.additionalFilter,
|
|
361
350
|
noOrderError: props.noOrderError,
|
|
362
351
|
isCodeModel: props.isCodeModel,
|
|
363
352
|
ownProps: props
|
|
@@ -614,7 +603,7 @@ const DataTable = ({
|
|
|
614
603
|
: !val;
|
|
615
604
|
});
|
|
616
605
|
}
|
|
617
|
-
if (noValsForField) {
|
|
606
|
+
if (noValsForField && entities.length) {
|
|
618
607
|
return {
|
|
619
608
|
...field,
|
|
620
609
|
isHidden: true,
|
package/src/DataTable/style.css
CHANGED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEmpty,
|
|
3
|
+
every,
|
|
4
|
+
some,
|
|
5
|
+
isEqual,
|
|
6
|
+
isString,
|
|
7
|
+
isNull,
|
|
8
|
+
isArray,
|
|
9
|
+
includes,
|
|
10
|
+
isObject,
|
|
11
|
+
has,
|
|
12
|
+
orderBy
|
|
13
|
+
} from "lodash-es";
|
|
14
|
+
|
|
15
|
+
export function filterLocalEntitiesToHasura(
|
|
16
|
+
records,
|
|
17
|
+
{ where, order_by, limit, offset, isInfinite } = {}
|
|
18
|
+
) {
|
|
19
|
+
let filteredRecords = [...records];
|
|
20
|
+
|
|
21
|
+
// Apply where clause if it exists
|
|
22
|
+
if (where) {
|
|
23
|
+
filteredRecords = applyWhereClause(filteredRecords, where);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Apply order_by if it exists
|
|
27
|
+
if (order_by) {
|
|
28
|
+
filteredRecords = applyOrderBy(filteredRecords, order_by);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Store the complete filtered and ordered records for pagination info
|
|
32
|
+
const allFilteredRecords = [...filteredRecords];
|
|
33
|
+
|
|
34
|
+
// Apply limit and offset
|
|
35
|
+
if (!isInfinite && offset !== undefined) {
|
|
36
|
+
filteredRecords = filteredRecords.slice(offset);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!isInfinite && limit !== undefined) {
|
|
40
|
+
filteredRecords = filteredRecords.slice(0, limit);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// For consistency, always return an object with entities, entitiesAcrossPages, and entityCount
|
|
44
|
+
return {
|
|
45
|
+
entities: filteredRecords,
|
|
46
|
+
entitiesAcrossPages: allFilteredRecords,
|
|
47
|
+
entityCount: allFilteredRecords.length
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function applyWhereClause(records, where) {
|
|
52
|
+
function applyFilter(record, filter) {
|
|
53
|
+
if (isEmpty(filter)) {
|
|
54
|
+
return true; // No filter, all records pass
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const key in filter) {
|
|
58
|
+
if (key === "_and") {
|
|
59
|
+
if (isEmpty(filter[key])) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (!every(filter[key], subFilter => applyFilter(record, subFilter))) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
} else if (key === "_or") {
|
|
66
|
+
if (isEmpty(filter[key])) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!some(filter[key], subFilter => applyFilter(record, subFilter))) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
} else if (key === "_not") {
|
|
73
|
+
if (applyFilter(record, filter[key])) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
const value = record[key];
|
|
78
|
+
const conditions = filter[key];
|
|
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
|
+
|
|
89
|
+
for (const operator in conditions) {
|
|
90
|
+
const conditionValue = conditions[operator];
|
|
91
|
+
|
|
92
|
+
// Handle range conditions (_gt/_lt or _gte/_lte combinations)
|
|
93
|
+
if (operator === "_gt" && conditions._lt) {
|
|
94
|
+
if (!(value > conditionValue && value < conditions._lt))
|
|
95
|
+
return false;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (operator === "_gte" && conditions._lte) {
|
|
99
|
+
if (!(value >= conditionValue && value <= conditions._lte))
|
|
100
|
+
return false;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
switch (operator) {
|
|
105
|
+
case "_eq":
|
|
106
|
+
if (!isEqual(value, conditionValue)) return false;
|
|
107
|
+
break;
|
|
108
|
+
case "_neq":
|
|
109
|
+
if (isEqual(value, conditionValue)) return false;
|
|
110
|
+
break;
|
|
111
|
+
case "_gt":
|
|
112
|
+
if (!(value > conditionValue)) return false;
|
|
113
|
+
break;
|
|
114
|
+
case "_gte":
|
|
115
|
+
if (!(value >= conditionValue)) return false;
|
|
116
|
+
break;
|
|
117
|
+
case "_lt":
|
|
118
|
+
if (!(value < conditionValue)) return false;
|
|
119
|
+
break;
|
|
120
|
+
case "_lte":
|
|
121
|
+
if (!(value <= conditionValue)) return false;
|
|
122
|
+
break;
|
|
123
|
+
case "_like":
|
|
124
|
+
if (
|
|
125
|
+
!isString(value) ||
|
|
126
|
+
!new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
|
|
127
|
+
)
|
|
128
|
+
return false;
|
|
129
|
+
break;
|
|
130
|
+
case "_ilike":
|
|
131
|
+
if (
|
|
132
|
+
!isString(value) ||
|
|
133
|
+
!new RegExp(conditionValue.replace(/%/g, ".*"), "i").test(value)
|
|
134
|
+
)
|
|
135
|
+
return false;
|
|
136
|
+
break;
|
|
137
|
+
case "_nlike":
|
|
138
|
+
if (
|
|
139
|
+
!isString(value) ||
|
|
140
|
+
new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
|
|
141
|
+
)
|
|
142
|
+
return false;
|
|
143
|
+
break;
|
|
144
|
+
case "_nilike":
|
|
145
|
+
if (
|
|
146
|
+
!isString(value) ||
|
|
147
|
+
new RegExp(conditionValue.replace(/%/g, ".*"), "i").test(value)
|
|
148
|
+
)
|
|
149
|
+
return false;
|
|
150
|
+
break;
|
|
151
|
+
case "_starts_with":
|
|
152
|
+
if (!isString(value) || !value.startsWith(conditionValue))
|
|
153
|
+
return false;
|
|
154
|
+
break;
|
|
155
|
+
case "_ends_with":
|
|
156
|
+
if (!isString(value) || !value.endsWith(conditionValue))
|
|
157
|
+
return false;
|
|
158
|
+
break;
|
|
159
|
+
case "_is_null":
|
|
160
|
+
if (
|
|
161
|
+
(conditionValue && !isNull(value)) ||
|
|
162
|
+
(!conditionValue && isNull(value))
|
|
163
|
+
)
|
|
164
|
+
return false;
|
|
165
|
+
break;
|
|
166
|
+
case "_contains":
|
|
167
|
+
if (
|
|
168
|
+
!isArray(value) ||
|
|
169
|
+
!every(conditionValue, item => includes(value, item))
|
|
170
|
+
)
|
|
171
|
+
return false;
|
|
172
|
+
break;
|
|
173
|
+
case "_contained_in":
|
|
174
|
+
if (
|
|
175
|
+
!isArray(value) ||
|
|
176
|
+
!every(value, item => includes(conditionValue, item))
|
|
177
|
+
)
|
|
178
|
+
return false;
|
|
179
|
+
break;
|
|
180
|
+
case "_has_key":
|
|
181
|
+
if (!isObject(value) || !has(value, conditionValue)) return false;
|
|
182
|
+
break;
|
|
183
|
+
case "_has_keys_any":
|
|
184
|
+
if (
|
|
185
|
+
!isObject(value) ||
|
|
186
|
+
!some(conditionValue, item => has(value, item))
|
|
187
|
+
)
|
|
188
|
+
return false;
|
|
189
|
+
break;
|
|
190
|
+
case "_has_keys_all":
|
|
191
|
+
if (
|
|
192
|
+
!isObject(value) ||
|
|
193
|
+
!every(conditionValue, item => has(value, item))
|
|
194
|
+
)
|
|
195
|
+
return false;
|
|
196
|
+
break;
|
|
197
|
+
case "_similar":
|
|
198
|
+
if (
|
|
199
|
+
!isString(value) ||
|
|
200
|
+
!new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
|
|
201
|
+
)
|
|
202
|
+
return false;
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
if (operator.startsWith("_")) {
|
|
206
|
+
console.warn(`Unsupported operator: ${operator}`);
|
|
207
|
+
return false;
|
|
208
|
+
} else {
|
|
209
|
+
console.warn(`Unsupported operator: ${operator}`);
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
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
|
+
|
|
225
|
+
return records.filter(record => applyFilter(record, where));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function applyOrderBy(records, order_by) {
|
|
229
|
+
const keys = Object.keys(order_by);
|
|
230
|
+
if (keys.length > 0) {
|
|
231
|
+
const field = keys[0];
|
|
232
|
+
const direction = order_by[field] === "asc" ? "asc" : "desc";
|
|
233
|
+
return orderBy(records, [field], [direction]);
|
|
234
|
+
}
|
|
235
|
+
return records;
|
|
236
|
+
}
|