@teselagen/ui 0.8.6-beta.16 → 0.8.6-beta.18
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,19 @@ 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
|
+
const newEnt = __spreadValues({}, entity);
|
|
19888
|
+
forEach(entity, (val, key) => {
|
|
19889
|
+
if (key.startsWith("___original___")) {
|
|
19890
|
+
newEnt[key.slice("___original___".length)] = val;
|
|
19891
|
+
delete newEnt[key];
|
|
19892
|
+
}
|
|
19893
|
+
});
|
|
19894
|
+
return newEnt;
|
|
19895
|
+
});
|
|
19896
|
+
}
|
|
19897
|
+
__name(restoreEntitiesFromLocalFilter, "restoreEntitiesFromLocalFilter");
|
|
19884
19898
|
function initializeHasuraWhereAndFilter(additionalFilter, where = {}, currentParams) {
|
|
19885
19899
|
where._and = where._and || [];
|
|
19886
19900
|
where._or = where._or || [];
|
|
@@ -20155,20 +20169,25 @@ function getQueryParams({
|
|
|
20155
20169
|
});
|
|
20156
20170
|
initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
|
|
20157
20171
|
if (isLocalCall) {
|
|
20158
|
-
const newEnts = filterLocalEntitiesToHasura(
|
|
20159
|
-
|
|
20160
|
-
|
|
20161
|
-
|
|
20162
|
-
|
|
20163
|
-
|
|
20164
|
-
|
|
20165
|
-
|
|
20166
|
-
|
|
20167
|
-
|
|
20168
|
-
|
|
20169
|
-
|
|
20170
|
-
|
|
20171
|
-
|
|
20172
|
+
const newEnts = filterLocalEntitiesToHasura(
|
|
20173
|
+
prepEntitiesForLocalFilter({ entities, ccFields }),
|
|
20174
|
+
{
|
|
20175
|
+
where,
|
|
20176
|
+
order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(
|
|
20177
|
+
(obj) => {
|
|
20178
|
+
const path2 = Object.keys(obj)[0];
|
|
20179
|
+
return __spreadValues({
|
|
20180
|
+
path: path2,
|
|
20181
|
+
direction: obj[path2],
|
|
20182
|
+
ownProps
|
|
20183
|
+
}, ccFields[path2]);
|
|
20184
|
+
}
|
|
20185
|
+
),
|
|
20186
|
+
limit,
|
|
20187
|
+
offset: offset3,
|
|
20188
|
+
isInfinite
|
|
20189
|
+
}
|
|
20190
|
+
);
|
|
20172
20191
|
toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
|
|
20173
20192
|
return toRet;
|
|
20174
20193
|
} else {
|
|
@@ -20210,6 +20229,20 @@ function getQueryParams({
|
|
|
20210
20229
|
}
|
|
20211
20230
|
}
|
|
20212
20231
|
__name(getQueryParams, "getQueryParams");
|
|
20232
|
+
function prepEntitiesForLocalFilter({ entities, ccFields }) {
|
|
20233
|
+
const r2 = entities.map((entity) => {
|
|
20234
|
+
forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
|
|
20235
|
+
if (getValueToFilterOn) {
|
|
20236
|
+
entity["___original___" + path2] = entity[path2];
|
|
20237
|
+
const value = getValueToFilterOn(entity);
|
|
20238
|
+
entity[path2] = value;
|
|
20239
|
+
}
|
|
20240
|
+
});
|
|
20241
|
+
return entity;
|
|
20242
|
+
});
|
|
20243
|
+
return r2;
|
|
20244
|
+
}
|
|
20245
|
+
__name(prepEntitiesForLocalFilter, "prepEntitiesForLocalFilter");
|
|
20213
20246
|
function PagingInput({ disabled, onBlur, defaultPage }) {
|
|
20214
20247
|
const [page, setPage] = React.useState(defaultPage);
|
|
20215
20248
|
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,19 @@ 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
|
+
const newEnt = __spreadValues({}, entity);
|
|
19870
|
+
forEach(entity, (val, key) => {
|
|
19871
|
+
if (key.startsWith("___original___")) {
|
|
19872
|
+
newEnt[key.slice("___original___".length)] = val;
|
|
19873
|
+
delete newEnt[key];
|
|
19874
|
+
}
|
|
19875
|
+
});
|
|
19876
|
+
return newEnt;
|
|
19877
|
+
});
|
|
19878
|
+
}
|
|
19879
|
+
__name(restoreEntitiesFromLocalFilter, "restoreEntitiesFromLocalFilter");
|
|
19866
19880
|
function initializeHasuraWhereAndFilter(additionalFilter, where = {}, currentParams) {
|
|
19867
19881
|
where._and = where._and || [];
|
|
19868
19882
|
where._or = where._or || [];
|
|
@@ -20137,20 +20151,25 @@ function getQueryParams({
|
|
|
20137
20151
|
});
|
|
20138
20152
|
initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
|
|
20139
20153
|
if (isLocalCall) {
|
|
20140
|
-
const newEnts = filterLocalEntitiesToHasura(
|
|
20141
|
-
|
|
20142
|
-
|
|
20143
|
-
|
|
20144
|
-
|
|
20145
|
-
|
|
20146
|
-
|
|
20147
|
-
|
|
20148
|
-
|
|
20149
|
-
|
|
20150
|
-
|
|
20151
|
-
|
|
20152
|
-
|
|
20153
|
-
|
|
20154
|
+
const newEnts = filterLocalEntitiesToHasura(
|
|
20155
|
+
prepEntitiesForLocalFilter({ entities, ccFields }),
|
|
20156
|
+
{
|
|
20157
|
+
where,
|
|
20158
|
+
order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(
|
|
20159
|
+
(obj) => {
|
|
20160
|
+
const path2 = Object.keys(obj)[0];
|
|
20161
|
+
return __spreadValues({
|
|
20162
|
+
path: path2,
|
|
20163
|
+
direction: obj[path2],
|
|
20164
|
+
ownProps
|
|
20165
|
+
}, ccFields[path2]);
|
|
20166
|
+
}
|
|
20167
|
+
),
|
|
20168
|
+
limit,
|
|
20169
|
+
offset: offset3,
|
|
20170
|
+
isInfinite
|
|
20171
|
+
}
|
|
20172
|
+
);
|
|
20154
20173
|
toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
|
|
20155
20174
|
return toRet;
|
|
20156
20175
|
} else {
|
|
@@ -20192,6 +20211,20 @@ function getQueryParams({
|
|
|
20192
20211
|
}
|
|
20193
20212
|
}
|
|
20194
20213
|
__name(getQueryParams, "getQueryParams");
|
|
20214
|
+
function prepEntitiesForLocalFilter({ entities, ccFields }) {
|
|
20215
|
+
const r2 = entities.map((entity) => {
|
|
20216
|
+
forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
|
|
20217
|
+
if (getValueToFilterOn) {
|
|
20218
|
+
entity["___original___" + path2] = entity[path2];
|
|
20219
|
+
const value = getValueToFilterOn(entity);
|
|
20220
|
+
entity[path2] = value;
|
|
20221
|
+
}
|
|
20222
|
+
});
|
|
20223
|
+
return entity;
|
|
20224
|
+
});
|
|
20225
|
+
return r2;
|
|
20226
|
+
}
|
|
20227
|
+
__name(prepEntitiesForLocalFilter, "prepEntitiesForLocalFilter");
|
|
20195
20228
|
function PagingInput({ disabled, onBlur, defaultPage }) {
|
|
20196
20229
|
const [page, setPage] = useState(defaultPage);
|
|
20197
20230
|
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,16 @@ function applyOrderBy(records, _order_by) {
|
|
|
339
341
|
}
|
|
340
342
|
return records;
|
|
341
343
|
}
|
|
344
|
+
|
|
345
|
+
function restoreEntitiesFromLocalFilter(ents) {
|
|
346
|
+
return ents.map(entity => {
|
|
347
|
+
const newEnt = { ...entity };
|
|
348
|
+
forEach(entity, (val, key) => {
|
|
349
|
+
if (key.startsWith("___original___")) {
|
|
350
|
+
newEnt[key.slice("___original___".length)] = val;
|
|
351
|
+
delete newEnt[key];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
return newEnt;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
@@ -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
|
+
}
|