@teselagen/ui 0.8.6-beta.15 → 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);
@@ -19693,7 +19694,7 @@ function applyWhereClause(records, where) {
19693
19694
  return false;
19694
19695
  }
19695
19696
  } else {
19696
- const value = record[key];
19697
+ const value = get$3(record, key);
19697
19698
  const conditions = filter2[key];
19698
19699
  if (isObject$2(value) && isObject$2(conditions) && !hasOperator(conditions)) {
19699
19700
  return applyFilter(value, conditions);
@@ -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(entities, {
20159
- where,
20160
- order_by: (Array.isArray(order_by) ? order_by : [order_by]).map((obj) => {
20161
- const path2 = Object.keys(obj)[0];
20162
- return __spreadValues({
20163
- path: path2,
20164
- direction: obj[path2],
20165
- ownProps
20166
- }, ccFields[path2]);
20167
- }),
20168
- limit,
20169
- offset: offset3,
20170
- isInfinite
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);
@@ -19675,7 +19676,7 @@ function applyWhereClause(records, where) {
19675
19676
  return false;
19676
19677
  }
19677
19678
  } else {
19678
- const value = record[key];
19679
+ const value = get$3(record, key);
19679
19680
  const conditions = filter2[key];
19680
19681
  if (isObject$2(value) && isObject$2(conditions) && !hasOperator(conditions)) {
19681
19682
  return applyFilter(value, conditions);
@@ -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(entities, {
20141
- where,
20142
- order_by: (Array.isArray(order_by) ? order_by : [order_by]).map((obj) => {
20143
- const path2 = Object.keys(obj)[0];
20144
- return __spreadValues({
20145
- path: path2,
20146
- direction: obj[path2],
20147
- ownProps
20148
- }, ccFields[path2]);
20149
- }),
20150
- limit,
20151
- offset: offset3,
20152
- isInfinite
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.8.6-beta.15",
3
+ "version": "0.8.6-beta.17",
4
4
  "main": "./src/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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];
@@ -76,7 +78,7 @@ function applyWhereClause(records, where) {
76
78
  return false;
77
79
  }
78
80
  } else {
79
- const value = record[key];
81
+ const value = get(record, key);
80
82
  const conditions = filter[key];
81
83
 
82
84
  // Handle nested object properties
@@ -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
+ }
@@ -57,6 +57,14 @@ describe("filterLocalEntitiesToHasura", () => {
57
57
  expect(result.entitiesAcrossPages).toEqual([records[0]]);
58
58
  expect(result.entityCount).toBe(1);
59
59
  });
60
+ it("should filter num fields by _eq", () => {
61
+ const result = filterLocalEntitiesToHasura(records, {
62
+ where: { age: { _eq: 30 } }
63
+ });
64
+ expect(result.entities).toEqual([records[0]]);
65
+ expect(result.entitiesAcrossPages).toEqual([records[0]]);
66
+ expect(result.entityCount).toBe(1);
67
+ });
60
68
 
61
69
  it("should filter by _neq", () => {
62
70
  const result = filterLocalEntitiesToHasura(records, {
@@ -1208,139 +1216,5 @@ describe("filterLocalEntitiesToHasura", () => {
1208
1216
  ]);
1209
1217
  expect(result.entityCount).toBe(5);
1210
1218
  });
1211
- it("should order using getValueToFilterOn", () => {
1212
- // Create a function that returns a value to sort by
1213
- const getCustomSortValue = record => {
1214
- // Sort by the first letter of the name
1215
- return record.name.charAt(0);
1216
- };
1217
-
1218
- const result = filterLocalEntitiesToHasura(records, {
1219
- order_by: { getValueToFilterOn: getCustomSortValue, direction: "asc" }
1220
- });
1221
-
1222
- // Expected order based on first letter: A, B, J, J
1223
- // Since J appears twice, their original order should be preserved
1224
- expect(result.entities).toEqual([
1225
- records[2], // Alice
1226
- records[3], // Bob
1227
- records[0], // John
1228
- records[1] // Jane
1229
- ]);
1230
- expect(result.entityCount).toBe(4);
1231
- });
1232
-
1233
- it("should order using getValueToFilterOn with ownProps", () => {
1234
- // Create a function that uses ownProps for customized sorting
1235
- const getWeightedValue = (record, ownProps) => {
1236
- // Create a weighted value based on age and a multiplier from ownProps
1237
- return record.age * (ownProps.multiplier || 1);
1238
- };
1239
-
1240
- const result = filterLocalEntitiesToHasura(records, {
1241
- order_by: {
1242
- getValueToFilterOn: getWeightedValue,
1243
- direction: "desc",
1244
- ownProps: { multiplier: 2 }
1245
- }
1246
- });
1247
-
1248
- // Expected order based on age * 2: 35*2, 30*2, 25*2, 20*2
1249
- expect(result.entities).toEqual([
1250
- records[2], // Alice Johnson (age: 35 * 2 = 70)
1251
- records[0], // John Doe (age: 30 * 2 = 60)
1252
- records[1], // Jane Smith (age: 25 * 2 = 50)
1253
- records[3] // Bob Williams (age: 20 * 2 = 40)
1254
- ]);
1255
- expect(result.entityCount).toBe(4);
1256
- });
1257
-
1258
- it("should handle null/undefined values in getValueToFilterOn", () => {
1259
- const recordsWithMissingProps = [
1260
- { id: 1, name: "Alice", customProp: 100 },
1261
- { id: 2, name: "Bob", customProp: null },
1262
- { id: 3, name: "Charlie" }, // customProp is undefined
1263
- { id: 4, name: "Dave", customProp: 200 }
1264
- ];
1265
-
1266
- // Function that uses a property that might be missing
1267
- const getCustomPropValue = record => {
1268
- return record.customProp;
1269
- };
1270
-
1271
- const result = filterLocalEntitiesToHasura(recordsWithMissingProps, {
1272
- order_by: { getValueToFilterOn: getCustomPropValue, direction: "desc" }
1273
- });
1274
-
1275
- // Should order with valid values first, then nulls/undefined at the end
1276
- expect(result.entities).toEqual([
1277
- recordsWithMissingProps[3], // customProp: 200
1278
- recordsWithMissingProps[0], // customProp: 100
1279
- recordsWithMissingProps[2], // customProp: undefined
1280
- recordsWithMissingProps[1] // customProp: null
1281
- ]);
1282
- expect(result.entityCount).toBe(4);
1283
- });
1284
-
1285
- it("should combine getValueToFilterOn with multiple sort criteria", () => {
1286
- // Additional records with same category but different priority
1287
- const extendedRecords = [
1288
- ...records,
1289
- {
1290
- id: 111,
1291
- name: "Tom Jones",
1292
- age: 40,
1293
- is_active: true,
1294
- city: "London",
1295
- tags: ["sql", "management"],
1296
- email: "tom@example.com",
1297
- data: { category: "A", type: "X", priority: 2 },
1298
- username: "tom111"
1299
- },
1300
- {
1301
- id: 222,
1302
- name: "Emma Brown",
1303
- age: 28,
1304
- is_active: true,
1305
- city: "London",
1306
- tags: ["design", "javascript"],
1307
- email: "emma@example.com",
1308
- data: { category: "A", type: "X", priority: 1 },
1309
- username: "emma222"
1310
- }
1311
- ];
1312
-
1313
- // First sort by category
1314
- const getCategoryValue = record => {
1315
- return record.data.category;
1316
- };
1317
-
1318
- // Then sort by priority if available, putting records without priority at the end
1319
- const getPriorityValue = record => {
1320
- return record.data.priority !== undefined
1321
- ? record.data.priority
1322
- : Number.MAX_SAFE_INTEGER;
1323
- };
1324
-
1325
- const result = filterLocalEntitiesToHasura(extendedRecords, {
1326
- order_by: [
1327
- { getValueToFilterOn: getCategoryValue, direction: "asc" },
1328
- { getValueToFilterOn: getPriorityValue, direction: "asc" }
1329
- ]
1330
- });
1331
-
1332
- // All category A records, ordered by priority if available
1333
- const categoryARecords = [
1334
- extendedRecords[5], // Emma (category A, priority 1)
1335
- extendedRecords[4], // Tom (category A, priority 2)
1336
- extendedRecords[0], // John (category A, no priority)
1337
- extendedRecords[2] // Alice (category A, no priority)
1338
- ];
1339
-
1340
- // Then category B, then category C
1341
- expect(result.entities.slice(0, 4)).toEqual(categoryARecords);
1342
- expect(result.entities[4]).toBe(extendedRecords[1]); // Jane (category B)
1343
- expect(result.entities[5]).toBe(extendedRecords[3]); // Bob (category C)
1344
- expect(result.entityCount).toBe(6);
1345
- });
1219
+
1346
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(entities, {
350
- where,
351
- order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(obj => {
352
- const path = Object.keys(obj)[0];
353
- return {
354
- path,
355
- direction: obj[path],
356
- ownProps,
357
- ...ccFields[path]
358
- };
359
- }),
360
- limit,
361
- offset,
362
- isInfinite
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
+ }