@teselagen/ui 0.8.6 → 0.9.1

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.
Files changed (42) hide show
  1. package/DataTable/EditabelCell.d.ts +10 -0
  2. package/DataTable/defaultProps.d.ts +43 -0
  3. package/DataTable/utils/computePresets.d.ts +1 -0
  4. package/DataTable/utils/getAllRows.d.ts +1 -1
  5. package/DataTable/utils/handleCopyColumn.d.ts +1 -1
  6. package/DataTable/utils/handleCopyTable.d.ts +1 -1
  7. package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +0 -1
  8. package/DataTable/utils/queryParams.d.ts +16 -12
  9. package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +1 -1
  10. package/README.md +1 -1
  11. package/index.cjs.js +1139 -1040
  12. package/index.d.ts +2 -0
  13. package/index.es.js +1139 -1040
  14. package/package.json +2 -2
  15. package/src/DataTable/Columns.js +2 -2
  16. package/src/DataTable/DisplayOptions.js +1 -1
  17. package/src/DataTable/EditabelCell.js +55 -0
  18. package/src/DataTable/FilterAndSortMenu.js +27 -30
  19. package/src/DataTable/defaultProps.js +45 -0
  20. package/src/DataTable/index.js +101 -84
  21. package/src/DataTable/style.css +1 -1
  22. package/src/DataTable/utils/computePresets.js +42 -0
  23. package/src/DataTable/utils/filterLocalEntitiesToHasura.js +128 -8
  24. package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +719 -21
  25. package/src/DataTable/utils/getAllRows.js +2 -6
  26. package/src/DataTable/utils/handleCopyColumn.js +2 -2
  27. package/src/DataTable/utils/handleCopyTable.js +2 -2
  28. package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +1 -12
  29. package/src/DataTable/utils/queryParams.js +153 -770
  30. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +185 -168
  31. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +50 -11
  32. package/src/DataTable/utils/withTableParams.js +3 -16
  33. package/src/ExcelCell.js +38 -0
  34. package/src/FormComponents/Uploader.js +5 -1
  35. package/src/FormComponents/index.js +2 -2
  36. package/src/TgSelect/index.js +15 -0
  37. package/src/autoTooltip.js +1 -0
  38. package/src/index.js +2 -0
  39. package/src/utils/determineBlackOrWhiteTextColor.js +8 -1
  40. package/style.css +10537 -0
  41. package/ui.css +1 -1
  42. package/utils/determineBlackOrWhiteTextColor.d.ts +1 -2
@@ -9,7 +9,10 @@ import {
9
9
  includes,
10
10
  isObject,
11
11
  has,
12
- orderBy
12
+ orderBy,
13
+ endsWith,
14
+ get,
15
+ forEach
13
16
  } from "lodash-es";
14
17
 
15
18
  export function filterLocalEntitiesToHasura(
@@ -27,6 +30,7 @@ export function filterLocalEntitiesToHasura(
27
30
  if (order_by) {
28
31
  filteredRecords = applyOrderBy(filteredRecords, order_by);
29
32
  }
33
+ filteredRecords = restoreEntitiesFromLocalFilter(filteredRecords);
30
34
 
31
35
  // Store the complete filtered and ordered records for pagination info
32
36
  const allFilteredRecords = [...filteredRecords];
@@ -74,7 +78,7 @@ function applyWhereClause(records, where) {
74
78
  return false;
75
79
  }
76
80
  } else {
77
- const value = record[key];
81
+ const value = get(record, key);
78
82
  const conditions = filter[key];
79
83
 
80
84
  // Handle nested object properties
@@ -225,12 +229,128 @@ function applyWhereClause(records, where) {
225
229
  return records.filter(record => applyFilter(record, where));
226
230
  }
227
231
 
228
- function applyOrderBy(records, order_by) {
229
- const keys = Object.keys(order_by);
230
- if (keys.length > 0) {
231
- const field = keys[0];
232
- const direction = order_by[field] === "asc" ? "asc" : "desc";
233
- return orderBy(records, [field], [direction]);
232
+ // takes in an array of records and an order_by clause
233
+ // order_by looks like this: [{ some_field: "asc" }, { some_other_field: "desc" }] or {some_field: "asc"}
234
+ // returns the records sorted by the order_by clause
235
+ function applyOrderBy(records, _order_by) {
236
+ const order_by = isArray(_order_by)
237
+ ? _order_by
238
+ : isEmpty(_order_by)
239
+ ? []
240
+ : [_order_by];
241
+
242
+ if (order_by.length > 0) {
243
+ const orderFuncs = [];
244
+ const ascOrDescArray = [];
245
+
246
+ order_by.forEach(
247
+ ({ path, direction, type, sortFn, getValueToFilterOn, ownProps }) => {
248
+ // Default direction is "desc" if not specified
249
+ direction = direction || "desc";
250
+
251
+ if (sortFn) {
252
+ // Allow sortFn to be a function, a string, or an array of functions/strings
253
+ const sortFnArray = Array.isArray(sortFn) ? sortFn : [sortFn];
254
+
255
+ sortFnArray.forEach(fn => {
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
260
+ orderFuncs.push(r => {
261
+ const val = getter(r);
262
+ return val !== null && val !== undefined ? 1 : 0;
263
+ });
264
+ ascOrDescArray.push("desc"); // Always push nulls to the bottom
265
+
266
+ // Then the actual sort function or path getter
267
+ orderFuncs.push(getter);
268
+ ascOrDescArray.push(direction);
269
+ });
270
+ } else if (getValueToFilterOn) {
271
+ // Custom getValue function
272
+ // First handle null check
273
+ orderFuncs.push(r => {
274
+ const val = getValueToFilterOn(r, ownProps);
275
+ return val !== null && val !== undefined ? 1 : 0;
276
+ });
277
+ ascOrDescArray.push("desc"); // Always push nulls to the bottom
278
+
279
+ // Then the actual value getter function
280
+ orderFuncs.push(r => getValueToFilterOn(r, ownProps));
281
+ ascOrDescArray.push(direction);
282
+ } else if (type === "timestamp") {
283
+ // Sort nulls/undefined to the bottom regardless of sort direction
284
+ orderFuncs.push(r => {
285
+ const val = get(r, path);
286
+ // First check if value exists, this ensures nulls go to the bottom
287
+ return val ? 1 : 0;
288
+ });
289
+ ascOrDescArray.push("desc"); // always put nulls at the bottom
290
+
291
+ // Then actual timestamp sorting
292
+ orderFuncs.push(r => {
293
+ const val = get(r, path);
294
+ return val ? new Date(val).getTime() : -Infinity;
295
+ });
296
+ ascOrDescArray.push(direction);
297
+ } else if (path && endsWith(path.toLowerCase(), "id")) {
298
+ // Handle ID fields - sort numerically
299
+ // First handle null check
300
+ orderFuncs.push(r => {
301
+ const val = get(r, path);
302
+ return val !== null && val !== undefined ? 1 : 0;
303
+ });
304
+ ascOrDescArray.push("desc"); // Always push nulls to the bottom
305
+
306
+ // Then the actual ID parsing
307
+ orderFuncs.push(o => {
308
+ const val = get(o, path);
309
+ if (val === null || val === undefined) return -Infinity;
310
+ return parseInt(val, 10) || 0;
311
+ });
312
+ ascOrDescArray.push(direction);
313
+ } else {
314
+ // Default sorting
315
+ // First sort by existence (non-nulls first)
316
+ orderFuncs.push(r => {
317
+ const val = get(r, path);
318
+ return val !== null && val !== undefined ? 1 : 0;
319
+ });
320
+ ascOrDescArray.push("desc"); // Always put nulls at the bottom
321
+
322
+ // Then sort by actual value
323
+ orderFuncs.push(r => {
324
+ const val = get(r, path);
325
+ if (val === null || val === undefined) return -Infinity;
326
+
327
+ // For string sorting, implement natural sort
328
+ if (isString(val)) {
329
+ return val.toLowerCase().replace(/(\d+)/g, num =>
330
+ // Pad numbers with leading zeros for proper natural sort
331
+ num.padStart(10, "0")
332
+ );
333
+ }
334
+ return val;
335
+ });
336
+ ascOrDescArray.push(direction);
337
+ }
338
+ }
339
+ );
340
+
341
+ records = orderBy(records, orderFuncs, ascOrDescArray);
234
342
  }
235
343
  return records;
236
344
  }
345
+
346
+ function restoreEntitiesFromLocalFilter(ents) {
347
+ return ents.map(entity => {
348
+ forEach(entity, (val, key) => {
349
+ if (key.startsWith?.("___original___")) {
350
+ entity[key.slice("___original___".length)] = val;
351
+ delete entity[key];
352
+ }
353
+ });
354
+ return entity;
355
+ });
356
+ }