@teselagen/ui 0.8.6-beta.7 → 0.8.6-beta.9

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
@@ -19496,6 +19496,13 @@ function tableQueryParamsToHasuraClauses({
19496
19496
  case "isExactly":
19497
19497
  return { [filterOn]: { _eq: filterValue } };
19498
19498
  case "isEmpty":
19499
+ if (filterOn.includes(".")) {
19500
+ return {
19501
+ _not: {
19502
+ [filterOn.split(".")[0]]: {}
19503
+ }
19504
+ };
19505
+ }
19499
19506
  return {
19500
19507
  _or: [
19501
19508
  { [filterOn]: { _eq: "" } },
@@ -22209,15 +22216,21 @@ __name(applyWhereClause, "applyWhereClause");
22209
22216
  function applyOrderBy(records, _order_by) {
22210
22217
  const order_by = isArray$2(_order_by) ? _order_by : isEmpty$1(_order_by) ? [] : [_order_by];
22211
22218
  if (order_by.length > 0) {
22212
- const fields = [];
22213
22219
  const directions = [];
22220
+ const iteratees = [];
22214
22221
  order_by.forEach((item) => {
22215
22222
  const field = Object.keys(item)[0];
22216
22223
  const direction = item[field];
22217
- fields.push(field);
22218
22224
  directions.push(direction);
22225
+ iteratees.push((record) => {
22226
+ const value = record[field];
22227
+ if (isString$1(value) && /\d/.test(value)) {
22228
+ return value.replace(/(\d+)/g, (num) => num.padStart(10, "0"));
22229
+ }
22230
+ return value;
22231
+ });
22219
22232
  });
22220
- records = orderBy$1(records, fields, directions);
22233
+ records = orderBy$1(records, iteratees, directions);
22221
22234
  }
22222
22235
  return records;
22223
22236
  }
package/index.es.js CHANGED
@@ -19478,6 +19478,13 @@ function tableQueryParamsToHasuraClauses({
19478
19478
  case "isExactly":
19479
19479
  return { [filterOn]: { _eq: filterValue } };
19480
19480
  case "isEmpty":
19481
+ if (filterOn.includes(".")) {
19482
+ return {
19483
+ _not: {
19484
+ [filterOn.split(".")[0]]: {}
19485
+ }
19486
+ };
19487
+ }
19481
19488
  return {
19482
19489
  _or: [
19483
19490
  { [filterOn]: { _eq: "" } },
@@ -22191,15 +22198,21 @@ __name(applyWhereClause, "applyWhereClause");
22191
22198
  function applyOrderBy(records, _order_by) {
22192
22199
  const order_by = isArray$2(_order_by) ? _order_by : isEmpty$1(_order_by) ? [] : [_order_by];
22193
22200
  if (order_by.length > 0) {
22194
- const fields = [];
22195
22201
  const directions = [];
22202
+ const iteratees = [];
22196
22203
  order_by.forEach((item) => {
22197
22204
  const field = Object.keys(item)[0];
22198
22205
  const direction = item[field];
22199
- fields.push(field);
22200
22206
  directions.push(direction);
22207
+ iteratees.push((record) => {
22208
+ const value = record[field];
22209
+ if (isString$1(value) && /\d/.test(value)) {
22210
+ return value.replace(/(\d+)/g, (num) => num.padStart(10, "0"));
22211
+ }
22212
+ return value;
22213
+ });
22201
22214
  });
22202
- records = orderBy$1(records, fields, directions);
22215
+ records = orderBy$1(records, iteratees, directions);
22203
22216
  }
22204
22217
  return records;
22205
22218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teselagen/ui",
3
- "version": "0.8.6-beta.7",
3
+ "version": "0.8.6-beta.9",
4
4
  "main": "./src/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -239,14 +239,30 @@ function applyOrderBy(records, _order_by) {
239
239
  if (order_by.length > 0) {
240
240
  const fields = [];
241
241
  const directions = [];
242
+ const iteratees = [];
243
+
242
244
  order_by.forEach(item => {
243
245
  // Hasura-style: { field: "asc" }
244
246
  const field = Object.keys(item)[0];
245
247
  const direction = item[field];
246
248
  fields.push(field);
247
249
  directions.push(direction);
250
+
251
+ // Create a custom iteratee function for natural sorting
252
+ iteratees.push(record => {
253
+ const value = record[field];
254
+ // Use natural sorting only for strings that contain numbers
255
+ if (isString(value) && /\d/.test(value)) {
256
+ // Return the value in a format that can be naturally sorted
257
+ // This effectively creates a sort key that respects natural ordering
258
+ return value.replace(/(\d+)/g, num => num.padStart(10, "0"));
259
+ }
260
+ return value;
261
+ });
248
262
  });
249
- records = orderBy(records, fields, directions);
263
+
264
+ // Use the custom iteratees for natural sorting
265
+ records = orderBy(records, iteratees, directions);
250
266
  }
251
267
  return records;
252
268
  }
@@ -536,6 +536,24 @@ describe("filterLocalEntitiesToHasura", () => {
536
536
  expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
537
537
  expect(result.entityCount).toBe(2);
538
538
  });
539
+ it("should order order well names properly, aka names a1, a11, a2, a3 should be sorted a1, a2, a3, a11", () => {
540
+ const recordsWithNames = [
541
+ { id: 1, name: "a1" },
542
+ { id: 2, name: "a11" },
543
+ { id: 3, name: "a2" },
544
+ { id: 4, name: "a3" }
545
+ ];
546
+ const result = filterLocalEntitiesToHasura(recordsWithNames, {
547
+ order_by: { name: "asc" }
548
+ });
549
+ expect(result.entities).toEqual([
550
+ recordsWithNames[0], // a1
551
+ recordsWithNames[2], // a2
552
+ recordsWithNames[3], // a3
553
+ recordsWithNames[1] // a11
554
+ ]);
555
+ expect(result.entityCount).toBe(4);
556
+ });
539
557
  it("should order by multiple fields (age asc, name desc)", () => {
540
558
  // Make two of the ages the same for testing secondary sort
541
559
  const modifiedRecords = [
@@ -112,6 +112,15 @@ export function tableQueryParamsToHasuraClauses({
112
112
  case "isExactly":
113
113
  return { [filterOn]: { _eq: filterValue } };
114
114
  case "isEmpty":
115
+ if (filterOn.includes(".")) {
116
+ // if we're filtering on a nested field, like a sequence table with parts.name
117
+ // we really want to just query on the top level field's existence
118
+ return {
119
+ _not: {
120
+ [filterOn.split(".")[0]]: {}
121
+ }
122
+ };
123
+ }
115
124
  return {
116
125
  _or: [
117
126
  { [filterOn]: { _eq: "" } },