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

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
@@ -22209,15 +22209,21 @@ __name(applyWhereClause, "applyWhereClause");
22209
22209
  function applyOrderBy(records, _order_by) {
22210
22210
  const order_by = isArray$2(_order_by) ? _order_by : isEmpty$1(_order_by) ? [] : [_order_by];
22211
22211
  if (order_by.length > 0) {
22212
- const fields = [];
22213
22212
  const directions = [];
22213
+ const iteratees = [];
22214
22214
  order_by.forEach((item) => {
22215
22215
  const field = Object.keys(item)[0];
22216
22216
  const direction = item[field];
22217
- fields.push(field);
22218
22217
  directions.push(direction);
22218
+ iteratees.push((record) => {
22219
+ const value = record[field];
22220
+ if (isString$1(value) && /\d/.test(value)) {
22221
+ return value.replace(/(\d+)/g, (num) => num.padStart(10, "0"));
22222
+ }
22223
+ return value;
22224
+ });
22219
22225
  });
22220
- records = orderBy$1(records, fields, directions);
22226
+ records = orderBy$1(records, iteratees, directions);
22221
22227
  }
22222
22228
  return records;
22223
22229
  }
package/index.es.js CHANGED
@@ -22191,15 +22191,21 @@ __name(applyWhereClause, "applyWhereClause");
22191
22191
  function applyOrderBy(records, _order_by) {
22192
22192
  const order_by = isArray$2(_order_by) ? _order_by : isEmpty$1(_order_by) ? [] : [_order_by];
22193
22193
  if (order_by.length > 0) {
22194
- const fields = [];
22195
22194
  const directions = [];
22195
+ const iteratees = [];
22196
22196
  order_by.forEach((item) => {
22197
22197
  const field = Object.keys(item)[0];
22198
22198
  const direction = item[field];
22199
- fields.push(field);
22200
22199
  directions.push(direction);
22200
+ iteratees.push((record) => {
22201
+ const value = record[field];
22202
+ if (isString$1(value) && /\d/.test(value)) {
22203
+ return value.replace(/(\d+)/g, (num) => num.padStart(10, "0"));
22204
+ }
22205
+ return value;
22206
+ });
22201
22207
  });
22202
- records = orderBy$1(records, fields, directions);
22208
+ records = orderBy$1(records, iteratees, directions);
22203
22209
  }
22204
22210
  return records;
22205
22211
  }
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.8",
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 = [