@teselagen/ui 0.8.6-beta.21 → 0.8.6-beta.23

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
@@ -20170,7 +20170,7 @@ function getQueryParams({
20170
20170
  });
20171
20171
  initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
20172
20172
  if (isLocalCall) {
20173
- const newEnts = filterLocalEntitiesToHasura(
20173
+ const r2 = filterLocalEntitiesToHasura(
20174
20174
  prepEntitiesForLocalFilter({ entities, ccFields }),
20175
20175
  {
20176
20176
  where,
@@ -20189,14 +20189,14 @@ function getQueryParams({
20189
20189
  isInfinite
20190
20190
  }
20191
20191
  );
20192
- toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
20192
+ toRet = __spreadValues(__spreadValues({}, toRet), r2);
20193
20193
  return toRet;
20194
20194
  } else {
20195
20195
  if (!order_by.length) {
20196
20196
  order_by.push({ updatedAt: "desc" });
20197
20197
  }
20198
20198
  order_by.push(
20199
- isCodeModel ? { code: "desc" } : { [window.__sortId || "id"]: "desc" }
20199
+ isCodeModel ? { code: "asc" } : { [window.__sortId || "id"]: "asc" }
20200
20200
  );
20201
20201
  return __spreadProps(__spreadValues({}, toRet), {
20202
20202
  variables: {
@@ -20232,15 +20232,20 @@ function getQueryParams({
20232
20232
  __name(getQueryParams, "getQueryParams");
20233
20233
  function prepEntitiesForLocalFilter({ entities, ccFields }) {
20234
20234
  const r2 = entities.map((entity) => {
20235
- const newEnt = __spreadValues({}, entity);
20235
+ const toSpread = {};
20236
+ let hasChanged = false;
20236
20237
  forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
20237
20238
  if (getValueToFilterOn) {
20238
- newEnt["___original___" + path2] = newEnt[path2];
20239
- const value = getValueToFilterOn(newEnt);
20240
- newEnt[path2] = value;
20239
+ hasChanged = true;
20240
+ toSpread["___original___" + path2] = entity[path2];
20241
+ const value = getValueToFilterOn(entity);
20242
+ toSpread[path2] = value;
20241
20243
  }
20242
20244
  });
20243
- return newEnt;
20245
+ if (hasChanged) {
20246
+ return __spreadValues(__spreadValues({}, entity), toSpread);
20247
+ }
20248
+ return entity;
20244
20249
  });
20245
20250
  return r2;
20246
20251
  }
package/index.es.js CHANGED
@@ -20152,7 +20152,7 @@ function getQueryParams({
20152
20152
  });
20153
20153
  initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
20154
20154
  if (isLocalCall) {
20155
- const newEnts = filterLocalEntitiesToHasura(
20155
+ const r2 = filterLocalEntitiesToHasura(
20156
20156
  prepEntitiesForLocalFilter({ entities, ccFields }),
20157
20157
  {
20158
20158
  where,
@@ -20171,14 +20171,14 @@ function getQueryParams({
20171
20171
  isInfinite
20172
20172
  }
20173
20173
  );
20174
- toRet = __spreadValues(__spreadValues({}, toRet), newEnts);
20174
+ toRet = __spreadValues(__spreadValues({}, toRet), r2);
20175
20175
  return toRet;
20176
20176
  } else {
20177
20177
  if (!order_by.length) {
20178
20178
  order_by.push({ updatedAt: "desc" });
20179
20179
  }
20180
20180
  order_by.push(
20181
- isCodeModel ? { code: "desc" } : { [window.__sortId || "id"]: "desc" }
20181
+ isCodeModel ? { code: "asc" } : { [window.__sortId || "id"]: "asc" }
20182
20182
  );
20183
20183
  return __spreadProps(__spreadValues({}, toRet), {
20184
20184
  variables: {
@@ -20214,15 +20214,20 @@ function getQueryParams({
20214
20214
  __name(getQueryParams, "getQueryParams");
20215
20215
  function prepEntitiesForLocalFilter({ entities, ccFields }) {
20216
20216
  const r2 = entities.map((entity) => {
20217
- const newEnt = __spreadValues({}, entity);
20217
+ const toSpread = {};
20218
+ let hasChanged = false;
20218
20219
  forEach(ccFields, ({ getValueToFilterOn, path: path2 }) => {
20219
20220
  if (getValueToFilterOn) {
20220
- newEnt["___original___" + path2] = newEnt[path2];
20221
- const value = getValueToFilterOn(newEnt);
20222
- newEnt[path2] = value;
20221
+ hasChanged = true;
20222
+ toSpread["___original___" + path2] = entity[path2];
20223
+ const value = getValueToFilterOn(entity);
20224
+ toSpread[path2] = value;
20223
20225
  }
20224
20226
  });
20225
- return newEnt;
20227
+ if (hasChanged) {
20228
+ return __spreadValues(__spreadValues({}, entity), toSpread);
20229
+ }
20230
+ return entity;
20226
20231
  });
20227
20232
  return r2;
20228
20233
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.8.6-beta.21",
3
+ "version": "0.8.6-beta.23",
4
4
  "main": "./src/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -254,10 +254,7 @@ function applyOrderBy(records, _order_by) {
254
254
 
255
255
  sortFnArray.forEach(fn => {
256
256
  // If fn is a string, treat it as a path to get from the record
257
- const getter =
258
- typeof fn === "function"
259
- ? fn
260
- : r => get(r, fn);
257
+ const getter = typeof fn === "function" ? fn : r => get(r, fn);
261
258
 
262
259
  // First handle null check for this function's/string's values
263
260
  orderFuncs.push(r => {
@@ -1239,13 +1239,13 @@ describe("filterLocalEntitiesToHasura", () => {
1239
1239
  gridRecords[2], // rowPos: 1, colPos: 1
1240
1240
  gridRecords[1], // rowPos: 1, colPos: 2
1241
1241
  gridRecords[3], // rowPos: 2, colPos: 1
1242
- gridRecords[0] // rowPos: 2, colPos: 3
1242
+ gridRecords[0] // rowPos: 2, colPos: 3
1243
1243
  ]);
1244
1244
  expect(result.entitiesAcrossPages).toEqual([
1245
- gridRecords[4],
1246
- gridRecords[2],
1247
- gridRecords[1],
1248
- gridRecords[3],
1245
+ gridRecords[4],
1246
+ gridRecords[2],
1247
+ gridRecords[1],
1248
+ gridRecords[3],
1249
1249
  gridRecords[0]
1250
1250
  ]);
1251
1251
  expect(result.entityCount).toBe(5);
@@ -1271,7 +1271,7 @@ describe("filterLocalEntitiesToHasura", () => {
1271
1271
  gridRecords[2], // rowPos: 1, colPos: null
1272
1272
  gridRecords[0], // rowPos: 2, colPos: 3
1273
1273
  gridRecords[1], // rowPos: null, colPos: 2
1274
- gridRecords[3] // rowPos: undefined, colPos: undefined
1274
+ gridRecords[3] // rowPos: undefined, colPos: undefined
1275
1275
  ]);
1276
1276
  expect(result.entitiesAcrossPages).toEqual([
1277
1277
  gridRecords[4],
@@ -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 {
@@ -381,7 +381,7 @@ export function getQueryParams({
381
381
  // in case entries that have the same value in the column being sorted on
382
382
  // fall back to id as a secondary sort to make sure ordering happens correctly
383
383
  order_by.push(
384
- isCodeModel ? { code: "desc" } : { [window.__sortId || "id"]: "desc" }
384
+ isCodeModel ? { code: "asc" } : { [window.__sortId || "id"]: "asc" }
385
385
  );
386
386
 
387
387
  return {
@@ -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
  }