@teselagen/ui 0.8.6-beta.20 → 0.8.6-beta.21
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 =
|
|
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(
|
|
19823
|
+
orderFuncs.push(getter);
|
|
19823
19824
|
ascOrDescArray.push(direction);
|
|
19824
19825
|
});
|
|
19825
19826
|
} else if (getValueToFilterOn) {
|
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 =
|
|
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(
|
|
19805
|
+
orderFuncs.push(getter);
|
|
19805
19806
|
ascOrDescArray.push(direction);
|
|
19806
19807
|
});
|
|
19807
19808
|
} else if (getValueToFilterOn) {
|
package/package.json
CHANGED
|
@@ -249,21 +249,25 @@ function applyOrderBy(records, _order_by) {
|
|
|
249
249
|
direction = direction || "desc";
|
|
250
250
|
|
|
251
251
|
if (sortFn) {
|
|
252
|
-
//
|
|
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
|
-
//
|
|
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);
|
|
261
|
+
|
|
262
|
+
// First handle null check for this function's/string's values
|
|
259
263
|
orderFuncs.push(r => {
|
|
260
|
-
const val =
|
|
264
|
+
const val = getter(r);
|
|
261
265
|
return val !== null && val !== undefined ? 1 : 0;
|
|
262
266
|
});
|
|
263
267
|
ascOrDescArray.push("desc"); // Always push nulls to the bottom
|
|
264
268
|
|
|
265
|
-
// Then the actual sort function
|
|
266
|
-
orderFuncs.push(
|
|
269
|
+
// Then the actual sort function or path getter
|
|
270
|
+
orderFuncs.push(getter);
|
|
267
271
|
ascOrDescArray.push(direction);
|
|
268
272
|
});
|
|
269
273
|
} 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
|
});
|