@teselagen/ui 0.8.6-beta.20 → 0.8.6-beta.22

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
@@ -19814,12 +19814,13 @@ function applyOrderBy(records, _order_by) {
19814
19814
  if (sortFn) {
19815
19815
  const sortFnArray = Array.isArray(sortFn) ? sortFn : [sortFn];
19816
19816
  sortFnArray.forEach((fn4) => {
19817
+ const getter = typeof fn4 === "function" ? fn4 : (r2) => get$3(r2, fn4);
19817
19818
  orderFuncs.push((r2) => {
19818
- const val = fn4(r2);
19819
+ const val = getter(r2);
19819
19820
  return val !== null && val !== void 0 ? 1 : 0;
19820
19821
  });
19821
19822
  ascOrDescArray.push("desc");
19822
- orderFuncs.push(fn4);
19823
+ orderFuncs.push(getter);
19823
19824
  ascOrDescArray.push(direction);
19824
19825
  });
19825
19826
  } else if (getValueToFilterOn) {
@@ -20169,7 +20170,7 @@ function getQueryParams({
20169
20170
  });
20170
20171
  initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
20171
20172
  if (isLocalCall) {
20172
- const newEnts = filterLocalEntitiesToHasura(
20173
+ const r2 = filterLocalEntitiesToHasura(
20173
20174
  prepEntitiesForLocalFilter({ entities, ccFields }),
20174
20175
  {
20175
20176
  where,
@@ -20188,7 +20189,7 @@ function getQueryParams({
20188
20189
  isInfinite
20189
20190
  }
20190
20191
  );
20191
- toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
20192
+ toRet = __spreadValues(__spreadValues({}, toRet), r2);
20192
20193
  return toRet;
20193
20194
  } else {
20194
20195
  if (!order_by.length) {
@@ -20231,15 +20232,20 @@ function getQueryParams({
20231
20232
  __name(getQueryParams, "getQueryParams");
20232
20233
  function prepEntitiesForLocalFilter({ entities, ccFields }) {
20233
20234
  const r2 = entities.map((entity) => {
20234
- const newEnt = __spreadValues({}, entity);
20235
+ const toSpread = {};
20236
+ let hasChanged = false;
20235
20237
  forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
20236
20238
  if (getValueToFilterOn) {
20237
- newEnt["___original___" + path2] = newEnt[path2];
20238
- const value = getValueToFilterOn(newEnt);
20239
- newEnt[path2] = value;
20239
+ hasChanged = true;
20240
+ toSpread["___original___" + path2] = entity[path2];
20241
+ const value = getValueToFilterOn(entity);
20242
+ toSpread[path2] = value;
20240
20243
  }
20241
20244
  });
20242
- return newEnt;
20245
+ if (hasChanged) {
20246
+ return __spreadValues(__spreadValues({}, entity), toSpread);
20247
+ }
20248
+ return entity;
20243
20249
  });
20244
20250
  return r2;
20245
20251
  }
package/index.es.js CHANGED
@@ -19796,12 +19796,13 @@ function applyOrderBy(records, _order_by) {
19796
19796
  if (sortFn) {
19797
19797
  const sortFnArray = Array.isArray(sortFn) ? sortFn : [sortFn];
19798
19798
  sortFnArray.forEach((fn4) => {
19799
+ const getter = typeof fn4 === "function" ? fn4 : (r2) => get$3(r2, fn4);
19799
19800
  orderFuncs.push((r2) => {
19800
- const val = fn4(r2);
19801
+ const val = getter(r2);
19801
19802
  return val !== null && val !== void 0 ? 1 : 0;
19802
19803
  });
19803
19804
  ascOrDescArray.push("desc");
19804
- orderFuncs.push(fn4);
19805
+ orderFuncs.push(getter);
19805
19806
  ascOrDescArray.push(direction);
19806
19807
  });
19807
19808
  } else if (getValueToFilterOn) {
@@ -20151,7 +20152,7 @@ function getQueryParams({
20151
20152
  });
20152
20153
  initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
20153
20154
  if (isLocalCall) {
20154
- const newEnts = filterLocalEntitiesToHasura(
20155
+ const r2 = filterLocalEntitiesToHasura(
20155
20156
  prepEntitiesForLocalFilter({ entities, ccFields }),
20156
20157
  {
20157
20158
  where,
@@ -20170,7 +20171,7 @@ function getQueryParams({
20170
20171
  isInfinite
20171
20172
  }
20172
20173
  );
20173
- toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
20174
+ toRet = __spreadValues(__spreadValues({}, toRet), r2);
20174
20175
  return toRet;
20175
20176
  } else {
20176
20177
  if (!order_by.length) {
@@ -20213,15 +20214,20 @@ function getQueryParams({
20213
20214
  __name(getQueryParams, "getQueryParams");
20214
20215
  function prepEntitiesForLocalFilter({ entities, ccFields }) {
20215
20216
  const r2 = entities.map((entity) => {
20216
- const newEnt = __spreadValues({}, entity);
20217
+ const toSpread = {};
20218
+ let hasChanged = false;
20217
20219
  forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
20218
20220
  if (getValueToFilterOn) {
20219
- newEnt["___original___" + path2] = newEnt[path2];
20220
- const value = getValueToFilterOn(newEnt);
20221
- newEnt[path2] = value;
20221
+ hasChanged = true;
20222
+ toSpread["___original___" + path2] = entity[path2];
20223
+ const value = getValueToFilterOn(entity);
20224
+ toSpread[path2] = value;
20222
20225
  }
20223
20226
  });
20224
- return newEnt;
20227
+ if (hasChanged) {
20228
+ return __spreadValues(__spreadValues({}, entity), toSpread);
20229
+ }
20230
+ return entity;
20225
20231
  });
20226
20232
  return r2;
20227
20233
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.8.6-beta.20",
3
+ "version": "0.8.6-beta.22",
4
4
  "main": "./src/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -249,21 +249,22 @@ function applyOrderBy(records, _order_by) {
249
249
  direction = direction || "desc";
250
250
 
251
251
  if (sortFn) {
252
- // Handle specifically custom sort functions
253
- // First make sure we have an array of sort functions
252
+ // Allow sortFn to be a function, a string, or an array of functions/strings
254
253
  const sortFnArray = Array.isArray(sortFn) ? sortFn : [sortFn];
255
254
 
256
- // For each sort function
257
255
  sortFnArray.forEach(fn => {
258
- // First handle null check for this function's values
256
+ // If fn is a string, treat it as a path to get from the record
257
+ const getter = typeof fn === "function" ? fn : r => get(r, fn);
258
+
259
+ // First handle null check for this function's/string's values
259
260
  orderFuncs.push(r => {
260
- const val = fn(r);
261
+ const val = getter(r);
261
262
  return val !== null && val !== undefined ? 1 : 0;
262
263
  });
263
264
  ascOrDescArray.push("desc"); // Always push nulls to the bottom
264
265
 
265
- // Then the actual sort function
266
- orderFuncs.push(fn);
266
+ // Then the actual sort function or path getter
267
+ orderFuncs.push(getter);
267
268
  ascOrDescArray.push(direction);
268
269
  });
269
270
  } else if (getValueToFilterOn) {
@@ -1216,4 +1216,70 @@ describe("filterLocalEntitiesToHasura", () => {
1216
1216
  ]);
1217
1217
  expect(result.entityCount).toBe(5);
1218
1218
  });
1219
+ it("should order using array of string paths in sortFn", () => {
1220
+ // Records with rowPosition and columnPosition properties
1221
+ const gridRecords = [
1222
+ { id: 1, name: "Item A", rowPosition: 2, columnPosition: 3 },
1223
+ { id: 2, name: "Item B", rowPosition: 1, columnPosition: 2 },
1224
+ { id: 3, name: "Item C", rowPosition: 1, columnPosition: 1 },
1225
+ { id: 4, name: "Item D", rowPosition: 2, columnPosition: 1 },
1226
+ { id: 5, name: "Item E", rowPosition: 0, columnPosition: 0 }
1227
+ ];
1228
+
1229
+ const result = filterLocalEntitiesToHasura(gridRecords, {
1230
+ order_by: [
1231
+ { path: "rowPosition", direction: "asc" },
1232
+ { path: "columnPosition", direction: "asc" }
1233
+ ]
1234
+ });
1235
+
1236
+ // Should sort first by rowPosition ascending, then by columnPosition ascending
1237
+ expect(result.entities).toEqual([
1238
+ gridRecords[4], // rowPos: 0, colPos: 0
1239
+ gridRecords[2], // rowPos: 1, colPos: 1
1240
+ gridRecords[1], // rowPos: 1, colPos: 2
1241
+ gridRecords[3], // rowPos: 2, colPos: 1
1242
+ gridRecords[0] // rowPos: 2, colPos: 3
1243
+ ]);
1244
+ expect(result.entitiesAcrossPages).toEqual([
1245
+ gridRecords[4],
1246
+ gridRecords[2],
1247
+ gridRecords[1],
1248
+ gridRecords[3],
1249
+ gridRecords[0]
1250
+ ]);
1251
+ expect(result.entityCount).toBe(5);
1252
+ });
1253
+ it("should handle nulls and missing properties with array of string paths in sortFn", () => {
1254
+ // Records with some missing or null rowPosition and columnPosition properties
1255
+ const gridRecords = [
1256
+ { id: 1, name: "Item A", rowPosition: 2, columnPosition: 3 },
1257
+ { id: 2, name: "Item B", rowPosition: null, columnPosition: 2 },
1258
+ { id: 3, name: "Item C", rowPosition: 1, columnPosition: null },
1259
+ { id: 4, name: "Item D" }, // Missing both properties
1260
+ { id: 5, name: "Item E", rowPosition: 0, columnPosition: 0 }
1261
+ ];
1262
+
1263
+ const result = filterLocalEntitiesToHasura(gridRecords, {
1264
+ order_by: { sortFn: ["rowPosition", "columnPosition"], direction: "asc" }
1265
+ });
1266
+
1267
+ // Should sort first by rowPosition ascending, then by columnPosition ascending
1268
+ // Null or undefined values should be placed at the end
1269
+ expect(result.entities).toEqual([
1270
+ gridRecords[4], // rowPos: 0, colPos: 0
1271
+ gridRecords[2], // rowPos: 1, colPos: null
1272
+ gridRecords[0], // rowPos: 2, colPos: 3
1273
+ gridRecords[1], // rowPos: null, colPos: 2
1274
+ gridRecords[3] // rowPos: undefined, colPos: undefined
1275
+ ]);
1276
+ expect(result.entitiesAcrossPages).toEqual([
1277
+ gridRecords[4],
1278
+ gridRecords[2],
1279
+ gridRecords[0],
1280
+ gridRecords[1],
1281
+ gridRecords[3]
1282
+ ]);
1283
+ expect(result.entityCount).toBe(5);
1284
+ });
1219
1285
  });
@@ -346,7 +346,7 @@ 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(
349
+ const r = filterLocalEntitiesToHasura(
350
350
  prepEntitiesForLocalFilter({ entities, ccFields }),
351
351
  {
352
352
  where,
@@ -369,7 +369,7 @@ export function getQueryParams({
369
369
 
370
370
  toRet = {
371
371
  ...toRet,
372
- ...newEnts
372
+ ...r
373
373
  };
374
374
  return toRet;
375
375
  } else {
@@ -420,16 +420,22 @@ export function getQueryParams({
420
420
  function prepEntitiesForLocalFilter({ entities, ccFields }) {
421
421
  // Prepare entities for local filtering by mapping over them and applying necessary transformations
422
422
  const r = entities.map(entity => {
423
- const newEnt = { ...entity };
423
+ const toSpread = {};
424
+ let hasChanged = false;
424
425
  // Apply any necessary transformations using ccFields
425
426
  forEach(ccFields, ({ getValueToFilterOn, path }) => {
426
427
  if (getValueToFilterOn) {
427
- newEnt["___original___" + path] = newEnt[path];
428
- const value = getValueToFilterOn(newEnt);
429
- newEnt[path] = value;
428
+ hasChanged = true;
429
+ toSpread["___original___" + path] = entity[path];
430
+ const value = getValueToFilterOn(entity);
431
+ toSpread[path] = value;
430
432
  }
431
433
  });
432
- return newEnt;
434
+ if (hasChanged) {
435
+ // If there are any transformations, spread them into the entity
436
+ return { ...entity, ...toSpread };
437
+ }
438
+ return entity;
433
439
  });
434
440
  return r;
435
441
  }