@teselagen/ui 0.8.6-beta.16 → 0.8.6-beta.17
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
CHANGED
|
@@ -19654,6 +19654,7 @@ function filterLocalEntitiesToHasura(records, { where, order_by, limit, offset:
|
|
|
19654
19654
|
if (order_by) {
|
|
19655
19655
|
filteredRecords = applyOrderBy(filteredRecords, order_by);
|
|
19656
19656
|
}
|
|
19657
|
+
filteredRecords = restoreEntitiesFromLocalFilter(filteredRecords);
|
|
19657
19658
|
const allFilteredRecords = [...filteredRecords];
|
|
19658
19659
|
if (!isInfinite && offset3 !== void 0) {
|
|
19659
19660
|
filteredRecords = filteredRecords.slice(offset3);
|
|
@@ -19881,6 +19882,18 @@ function applyOrderBy(records, _order_by) {
|
|
|
19881
19882
|
return records;
|
|
19882
19883
|
}
|
|
19883
19884
|
__name(applyOrderBy, "applyOrderBy");
|
|
19885
|
+
function restoreEntitiesFromLocalFilter(ents) {
|
|
19886
|
+
return ents.map((entity) => {
|
|
19887
|
+
forEach(entity, (val, key) => {
|
|
19888
|
+
if (key.startsWith("___original___")) {
|
|
19889
|
+
entity[key.slice("___original___".length)] = val;
|
|
19890
|
+
delete entity[key];
|
|
19891
|
+
}
|
|
19892
|
+
});
|
|
19893
|
+
return entity;
|
|
19894
|
+
});
|
|
19895
|
+
}
|
|
19896
|
+
__name(restoreEntitiesFromLocalFilter, "restoreEntitiesFromLocalFilter");
|
|
19884
19897
|
function initializeHasuraWhereAndFilter(additionalFilter, where = {}, currentParams) {
|
|
19885
19898
|
where._and = where._and || [];
|
|
19886
19899
|
where._or = where._or || [];
|
|
@@ -20155,20 +20168,25 @@ function getQueryParams({
|
|
|
20155
20168
|
});
|
|
20156
20169
|
initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
|
|
20157
20170
|
if (isLocalCall) {
|
|
20158
|
-
const newEnts = filterLocalEntitiesToHasura(
|
|
20159
|
-
|
|
20160
|
-
|
|
20161
|
-
|
|
20162
|
-
|
|
20163
|
-
|
|
20164
|
-
|
|
20165
|
-
|
|
20166
|
-
|
|
20167
|
-
|
|
20168
|
-
|
|
20169
|
-
|
|
20170
|
-
|
|
20171
|
-
|
|
20171
|
+
const newEnts = filterLocalEntitiesToHasura(
|
|
20172
|
+
prepEntitiesForLocalFilter({ entities, ccFields }),
|
|
20173
|
+
{
|
|
20174
|
+
where,
|
|
20175
|
+
order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(
|
|
20176
|
+
(obj) => {
|
|
20177
|
+
const path2 = Object.keys(obj)[0];
|
|
20178
|
+
return __spreadValues({
|
|
20179
|
+
path: path2,
|
|
20180
|
+
direction: obj[path2],
|
|
20181
|
+
ownProps
|
|
20182
|
+
}, ccFields[path2]);
|
|
20183
|
+
}
|
|
20184
|
+
),
|
|
20185
|
+
limit,
|
|
20186
|
+
offset: offset3,
|
|
20187
|
+
isInfinite
|
|
20188
|
+
}
|
|
20189
|
+
);
|
|
20172
20190
|
toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
|
|
20173
20191
|
return toRet;
|
|
20174
20192
|
} else {
|
|
@@ -20210,6 +20228,20 @@ function getQueryParams({
|
|
|
20210
20228
|
}
|
|
20211
20229
|
}
|
|
20212
20230
|
__name(getQueryParams, "getQueryParams");
|
|
20231
|
+
function prepEntitiesForLocalFilter({ entities, ccFields }) {
|
|
20232
|
+
const r2 = entities.map((entity) => {
|
|
20233
|
+
forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
|
|
20234
|
+
if (getValueToFilterOn) {
|
|
20235
|
+
entity["___original___" + path2] = entity[path2];
|
|
20236
|
+
const value = getValueToFilterOn(entity);
|
|
20237
|
+
entity[path2] = value;
|
|
20238
|
+
}
|
|
20239
|
+
});
|
|
20240
|
+
return entity;
|
|
20241
|
+
});
|
|
20242
|
+
return r2;
|
|
20243
|
+
}
|
|
20244
|
+
__name(prepEntitiesForLocalFilter, "prepEntitiesForLocalFilter");
|
|
20213
20245
|
function PagingInput({ disabled, onBlur, defaultPage }) {
|
|
20214
20246
|
const [page, setPage] = React.useState(defaultPage);
|
|
20215
20247
|
const defaultValue2 = React.useRef(defaultPage);
|
package/index.es.js
CHANGED
|
@@ -19636,6 +19636,7 @@ function filterLocalEntitiesToHasura(records, { where, order_by, limit, offset:
|
|
|
19636
19636
|
if (order_by) {
|
|
19637
19637
|
filteredRecords = applyOrderBy(filteredRecords, order_by);
|
|
19638
19638
|
}
|
|
19639
|
+
filteredRecords = restoreEntitiesFromLocalFilter(filteredRecords);
|
|
19639
19640
|
const allFilteredRecords = [...filteredRecords];
|
|
19640
19641
|
if (!isInfinite && offset3 !== void 0) {
|
|
19641
19642
|
filteredRecords = filteredRecords.slice(offset3);
|
|
@@ -19863,6 +19864,18 @@ function applyOrderBy(records, _order_by) {
|
|
|
19863
19864
|
return records;
|
|
19864
19865
|
}
|
|
19865
19866
|
__name(applyOrderBy, "applyOrderBy");
|
|
19867
|
+
function restoreEntitiesFromLocalFilter(ents) {
|
|
19868
|
+
return ents.map((entity) => {
|
|
19869
|
+
forEach(entity, (val, key) => {
|
|
19870
|
+
if (key.startsWith("___original___")) {
|
|
19871
|
+
entity[key.slice("___original___".length)] = val;
|
|
19872
|
+
delete entity[key];
|
|
19873
|
+
}
|
|
19874
|
+
});
|
|
19875
|
+
return entity;
|
|
19876
|
+
});
|
|
19877
|
+
}
|
|
19878
|
+
__name(restoreEntitiesFromLocalFilter, "restoreEntitiesFromLocalFilter");
|
|
19866
19879
|
function initializeHasuraWhereAndFilter(additionalFilter, where = {}, currentParams) {
|
|
19867
19880
|
where._and = where._and || [];
|
|
19868
19881
|
where._or = where._or || [];
|
|
@@ -20137,20 +20150,25 @@ function getQueryParams({
|
|
|
20137
20150
|
});
|
|
20138
20151
|
initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
|
|
20139
20152
|
if (isLocalCall) {
|
|
20140
|
-
const newEnts = filterLocalEntitiesToHasura(
|
|
20141
|
-
|
|
20142
|
-
|
|
20143
|
-
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
|
|
20148
|
-
|
|
20149
|
-
|
|
20150
|
-
|
|
20151
|
-
|
|
20152
|
-
|
|
20153
|
-
|
|
20153
|
+
const newEnts = filterLocalEntitiesToHasura(
|
|
20154
|
+
prepEntitiesForLocalFilter({ entities, ccFields }),
|
|
20155
|
+
{
|
|
20156
|
+
where,
|
|
20157
|
+
order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(
|
|
20158
|
+
(obj) => {
|
|
20159
|
+
const path2 = Object.keys(obj)[0];
|
|
20160
|
+
return __spreadValues({
|
|
20161
|
+
path: path2,
|
|
20162
|
+
direction: obj[path2],
|
|
20163
|
+
ownProps
|
|
20164
|
+
}, ccFields[path2]);
|
|
20165
|
+
}
|
|
20166
|
+
),
|
|
20167
|
+
limit,
|
|
20168
|
+
offset: offset3,
|
|
20169
|
+
isInfinite
|
|
20170
|
+
}
|
|
20171
|
+
);
|
|
20154
20172
|
toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
|
|
20155
20173
|
return toRet;
|
|
20156
20174
|
} else {
|
|
@@ -20192,6 +20210,20 @@ function getQueryParams({
|
|
|
20192
20210
|
}
|
|
20193
20211
|
}
|
|
20194
20212
|
__name(getQueryParams, "getQueryParams");
|
|
20213
|
+
function prepEntitiesForLocalFilter({ entities, ccFields }) {
|
|
20214
|
+
const r2 = entities.map((entity) => {
|
|
20215
|
+
forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
|
|
20216
|
+
if (getValueToFilterOn) {
|
|
20217
|
+
entity["___original___" + path2] = entity[path2];
|
|
20218
|
+
const value = getValueToFilterOn(entity);
|
|
20219
|
+
entity[path2] = value;
|
|
20220
|
+
}
|
|
20221
|
+
});
|
|
20222
|
+
return entity;
|
|
20223
|
+
});
|
|
20224
|
+
return r2;
|
|
20225
|
+
}
|
|
20226
|
+
__name(prepEntitiesForLocalFilter, "prepEntitiesForLocalFilter");
|
|
20195
20227
|
function PagingInput({ disabled, onBlur, defaultPage }) {
|
|
20196
20228
|
const [page, setPage] = useState(defaultPage);
|
|
20197
20229
|
const defaultValue2 = useRef(defaultPage);
|
package/package.json
CHANGED
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
has,
|
|
12
12
|
orderBy,
|
|
13
13
|
endsWith,
|
|
14
|
-
get
|
|
14
|
+
get,
|
|
15
|
+
forEach
|
|
15
16
|
} from "lodash-es";
|
|
16
17
|
|
|
17
18
|
export function filterLocalEntitiesToHasura(
|
|
@@ -29,6 +30,7 @@ export function filterLocalEntitiesToHasura(
|
|
|
29
30
|
if (order_by) {
|
|
30
31
|
filteredRecords = applyOrderBy(filteredRecords, order_by);
|
|
31
32
|
}
|
|
33
|
+
filteredRecords = restoreEntitiesFromLocalFilter(filteredRecords);
|
|
32
34
|
|
|
33
35
|
// Store the complete filtered and ordered records for pagination info
|
|
34
36
|
const allFilteredRecords = [...filteredRecords];
|
|
@@ -339,3 +341,15 @@ function applyOrderBy(records, _order_by) {
|
|
|
339
341
|
}
|
|
340
342
|
return records;
|
|
341
343
|
}
|
|
344
|
+
|
|
345
|
+
function restoreEntitiesFromLocalFilter(ents) {
|
|
346
|
+
return ents.map(entity => {
|
|
347
|
+
forEach(entity, (val, key) => {
|
|
348
|
+
if (key.startsWith("___original___")) {
|
|
349
|
+
entity[key.slice("___original___".length)] = val;
|
|
350
|
+
delete entity[key];
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
return entity;
|
|
354
|
+
});
|
|
355
|
+
}
|
|
@@ -1216,139 +1216,5 @@ describe("filterLocalEntitiesToHasura", () => {
|
|
|
1216
1216
|
]);
|
|
1217
1217
|
expect(result.entityCount).toBe(5);
|
|
1218
1218
|
});
|
|
1219
|
-
|
|
1220
|
-
// Create a function that returns a value to sort by
|
|
1221
|
-
const getCustomSortValue = record => {
|
|
1222
|
-
// Sort by the first letter of the name
|
|
1223
|
-
return record.name.charAt(0);
|
|
1224
|
-
};
|
|
1225
|
-
|
|
1226
|
-
const result = filterLocalEntitiesToHasura(records, {
|
|
1227
|
-
order_by: { getValueToFilterOn: getCustomSortValue, direction: "asc" }
|
|
1228
|
-
});
|
|
1229
|
-
|
|
1230
|
-
// Expected order based on first letter: A, B, J, J
|
|
1231
|
-
// Since J appears twice, their original order should be preserved
|
|
1232
|
-
expect(result.entities).toEqual([
|
|
1233
|
-
records[2], // Alice
|
|
1234
|
-
records[3], // Bob
|
|
1235
|
-
records[0], // John
|
|
1236
|
-
records[1] // Jane
|
|
1237
|
-
]);
|
|
1238
|
-
expect(result.entityCount).toBe(4);
|
|
1239
|
-
});
|
|
1240
|
-
|
|
1241
|
-
it("should order using getValueToFilterOn with ownProps", () => {
|
|
1242
|
-
// Create a function that uses ownProps for customized sorting
|
|
1243
|
-
const getWeightedValue = (record, ownProps) => {
|
|
1244
|
-
// Create a weighted value based on age and a multiplier from ownProps
|
|
1245
|
-
return record.age * (ownProps.multiplier || 1);
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
|
-
const result = filterLocalEntitiesToHasura(records, {
|
|
1249
|
-
order_by: {
|
|
1250
|
-
getValueToFilterOn: getWeightedValue,
|
|
1251
|
-
direction: "desc",
|
|
1252
|
-
ownProps: { multiplier: 2 }
|
|
1253
|
-
}
|
|
1254
|
-
});
|
|
1255
|
-
|
|
1256
|
-
// Expected order based on age * 2: 35*2, 30*2, 25*2, 20*2
|
|
1257
|
-
expect(result.entities).toEqual([
|
|
1258
|
-
records[2], // Alice Johnson (age: 35 * 2 = 70)
|
|
1259
|
-
records[0], // John Doe (age: 30 * 2 = 60)
|
|
1260
|
-
records[1], // Jane Smith (age: 25 * 2 = 50)
|
|
1261
|
-
records[3] // Bob Williams (age: 20 * 2 = 40)
|
|
1262
|
-
]);
|
|
1263
|
-
expect(result.entityCount).toBe(4);
|
|
1264
|
-
});
|
|
1265
|
-
|
|
1266
|
-
it("should handle null/undefined values in getValueToFilterOn", () => {
|
|
1267
|
-
const recordsWithMissingProps = [
|
|
1268
|
-
{ id: 1, name: "Alice", customProp: 100 },
|
|
1269
|
-
{ id: 2, name: "Bob", customProp: null },
|
|
1270
|
-
{ id: 3, name: "Charlie" }, // customProp is undefined
|
|
1271
|
-
{ id: 4, name: "Dave", customProp: 200 }
|
|
1272
|
-
];
|
|
1273
|
-
|
|
1274
|
-
// Function that uses a property that might be missing
|
|
1275
|
-
const getCustomPropValue = record => {
|
|
1276
|
-
return record.customProp;
|
|
1277
|
-
};
|
|
1278
|
-
|
|
1279
|
-
const result = filterLocalEntitiesToHasura(recordsWithMissingProps, {
|
|
1280
|
-
order_by: { getValueToFilterOn: getCustomPropValue, direction: "desc" }
|
|
1281
|
-
});
|
|
1282
|
-
|
|
1283
|
-
// Should order with valid values first, then nulls/undefined at the end
|
|
1284
|
-
expect(result.entities).toEqual([
|
|
1285
|
-
recordsWithMissingProps[3], // customProp: 200
|
|
1286
|
-
recordsWithMissingProps[0], // customProp: 100
|
|
1287
|
-
recordsWithMissingProps[2], // customProp: undefined
|
|
1288
|
-
recordsWithMissingProps[1] // customProp: null
|
|
1289
|
-
]);
|
|
1290
|
-
expect(result.entityCount).toBe(4);
|
|
1291
|
-
});
|
|
1292
|
-
|
|
1293
|
-
it("should combine getValueToFilterOn with multiple sort criteria", () => {
|
|
1294
|
-
// Additional records with same category but different priority
|
|
1295
|
-
const extendedRecords = [
|
|
1296
|
-
...records,
|
|
1297
|
-
{
|
|
1298
|
-
id: 111,
|
|
1299
|
-
name: "Tom Jones",
|
|
1300
|
-
age: 40,
|
|
1301
|
-
is_active: true,
|
|
1302
|
-
city: "London",
|
|
1303
|
-
tags: ["sql", "management"],
|
|
1304
|
-
email: "tom@example.com",
|
|
1305
|
-
data: { category: "A", type: "X", priority: 2 },
|
|
1306
|
-
username: "tom111"
|
|
1307
|
-
},
|
|
1308
|
-
{
|
|
1309
|
-
id: 222,
|
|
1310
|
-
name: "Emma Brown",
|
|
1311
|
-
age: 28,
|
|
1312
|
-
is_active: true,
|
|
1313
|
-
city: "London",
|
|
1314
|
-
tags: ["design", "javascript"],
|
|
1315
|
-
email: "emma@example.com",
|
|
1316
|
-
data: { category: "A", type: "X", priority: 1 },
|
|
1317
|
-
username: "emma222"
|
|
1318
|
-
}
|
|
1319
|
-
];
|
|
1320
|
-
|
|
1321
|
-
// First sort by category
|
|
1322
|
-
const getCategoryValue = record => {
|
|
1323
|
-
return record.data.category;
|
|
1324
|
-
};
|
|
1325
|
-
|
|
1326
|
-
// Then sort by priority if available, putting records without priority at the end
|
|
1327
|
-
const getPriorityValue = record => {
|
|
1328
|
-
return record.data.priority !== undefined
|
|
1329
|
-
? record.data.priority
|
|
1330
|
-
: Number.MAX_SAFE_INTEGER;
|
|
1331
|
-
};
|
|
1332
|
-
|
|
1333
|
-
const result = filterLocalEntitiesToHasura(extendedRecords, {
|
|
1334
|
-
order_by: [
|
|
1335
|
-
{ getValueToFilterOn: getCategoryValue, direction: "asc" },
|
|
1336
|
-
{ getValueToFilterOn: getPriorityValue, direction: "asc" }
|
|
1337
|
-
]
|
|
1338
|
-
});
|
|
1339
|
-
|
|
1340
|
-
// All category A records, ordered by priority if available
|
|
1341
|
-
const categoryARecords = [
|
|
1342
|
-
extendedRecords[5], // Emma (category A, priority 1)
|
|
1343
|
-
extendedRecords[4], // Tom (category A, priority 2)
|
|
1344
|
-
extendedRecords[0], // John (category A, no priority)
|
|
1345
|
-
extendedRecords[2] // Alice (category A, no priority)
|
|
1346
|
-
];
|
|
1347
|
-
|
|
1348
|
-
// Then category B, then category C
|
|
1349
|
-
expect(result.entities.slice(0, 4)).toEqual(categoryARecords);
|
|
1350
|
-
expect(result.entities[4]).toBe(extendedRecords[1]); // Jane (category B)
|
|
1351
|
-
expect(result.entities[5]).toBe(extendedRecords[3]); // Bob (category C)
|
|
1352
|
-
expect(result.entityCount).toBe(6);
|
|
1353
|
-
});
|
|
1219
|
+
|
|
1354
1220
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import queryString from "qs";
|
|
2
|
-
import { uniqBy, clone, camelCase } from "lodash-es";
|
|
2
|
+
import { uniqBy, clone, camelCase, forEach } from "lodash-es";
|
|
3
3
|
import {
|
|
4
4
|
getFieldsMappedByCCDisplayName,
|
|
5
5
|
tableQueryParamsToHasuraClauses
|
|
@@ -346,21 +346,26 @@ export function getQueryParams({
|
|
|
346
346
|
if (isLocalCall) {
|
|
347
347
|
//if the table is local (aka not directly connected to a db) then we need to
|
|
348
348
|
//handle filtering/paging/sorting all on the front end
|
|
349
|
-
const newEnts = filterLocalEntitiesToHasura(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
349
|
+
const newEnts = filterLocalEntitiesToHasura(
|
|
350
|
+
prepEntitiesForLocalFilter({ entities, ccFields }),
|
|
351
|
+
{
|
|
352
|
+
where,
|
|
353
|
+
order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(
|
|
354
|
+
obj => {
|
|
355
|
+
const path = Object.keys(obj)[0];
|
|
356
|
+
return {
|
|
357
|
+
path,
|
|
358
|
+
direction: obj[path],
|
|
359
|
+
ownProps,
|
|
360
|
+
...ccFields[path]
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
),
|
|
364
|
+
limit,
|
|
365
|
+
offset,
|
|
366
|
+
isInfinite
|
|
367
|
+
}
|
|
368
|
+
);
|
|
364
369
|
|
|
365
370
|
toRet = {
|
|
366
371
|
...toRet,
|
|
@@ -411,3 +416,19 @@ export function getQueryParams({
|
|
|
411
416
|
}
|
|
412
417
|
}
|
|
413
418
|
}
|
|
419
|
+
|
|
420
|
+
function prepEntitiesForLocalFilter({ entities, ccFields }) {
|
|
421
|
+
// Prepare entities for local filtering by mapping over them and applying necessary transformations
|
|
422
|
+
const r = entities.map(entity => {
|
|
423
|
+
// Apply any necessary transformations using ccFields
|
|
424
|
+
forEach(ccFields, ({ getValueToFilterOn, path }) => {
|
|
425
|
+
if (getValueToFilterOn) {
|
|
426
|
+
entity["___original___" + path] = entity[path]
|
|
427
|
+
const value = getValueToFilterOn(entity);
|
|
428
|
+
entity[path] = value;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return entity;
|
|
432
|
+
});
|
|
433
|
+
return r;
|
|
434
|
+
}
|