@teselagen/ui 0.8.6-beta.14 → 0.8.6-beta.15

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.
@@ -53,7 +53,6 @@ function safeParse(val) {
53
53
  return val;
54
54
  }
55
55
  }
56
-
57
56
  export function getCurrentParamsFromUrl(location, isSimple) {
58
57
  let { search } = location;
59
58
  if (isSimple) {
@@ -239,6 +238,27 @@ export function makeDataTableHandlers({
239
238
  };
240
239
  }
241
240
 
241
+ function cleanupFilters({ filters, ccFields }) {
242
+ (filters || []).forEach(filter => {
243
+ const { filterOn, filterValue } = filter;
244
+ const field = ccFields[filterOn];
245
+ if (field.type === "number" || field.type === "integer") {
246
+ filter.filterValue = Array.isArray(filterValue)
247
+ ? filterValue.map(val => Number(val))
248
+ : Number(filterValue);
249
+ }
250
+ if (
251
+ filter.selectedFilter === "inList" &&
252
+ typeof filter.filterValue === "number"
253
+ ) {
254
+ // if an inList value only has two items like
255
+ // 2.3 then it will get parsed to a number and
256
+ // break, convert it back to a string here
257
+ filter.filterValue = filter.filterValue.toString();
258
+ }
259
+ });
260
+ }
261
+
242
262
  export function getQueryParams({
243
263
  currentParams,
244
264
  urlConnected,
@@ -266,6 +286,10 @@ export function getQueryParams({
266
286
  ...currentParams
267
287
  };
268
288
  let { page, pageSize, searchTerm, filters, order } = tableQueryParams;
289
+ const ccFields = getFieldsMappedByCCDisplayName(schema);
290
+
291
+ cleanupFilters({ filters, ccFields });
292
+
269
293
  if (page <= 0 || isNaN(page)) {
270
294
  page = undefined;
271
295
  }
@@ -283,7 +307,6 @@ export function getQueryParams({
283
307
 
284
308
  const cleanedOrder = [];
285
309
  if (order && order.length) {
286
- const ccFields = getFieldsMappedByCCDisplayName(schema);
287
310
  order.forEach(orderVal => {
288
311
  const ccDisplayName = orderVal.replace(/^-/gi, "");
289
312
  const schemaForField = ccFields[ccDisplayName];
@@ -302,15 +325,6 @@ export function getQueryParams({
302
325
  }
303
326
  });
304
327
  }
305
- // by default make sort by updated at
306
- if (!cleanedOrder.length) {
307
- cleanedOrder.push("-updatedAt");
308
- }
309
-
310
- // in case entries that have the same value in the column being sorted on
311
- // fall back to id as a secondary sort to make sure ordering happens correctly
312
- cleanedOrder.push(isCodeModel ? "code" : window.__sortId || "id");
313
-
314
328
  let toRet = {
315
329
  //these are values that might be generally useful for the wrapped component
316
330
  page,
@@ -332,18 +346,39 @@ export function getQueryParams({
332
346
  if (isLocalCall) {
333
347
  //if the table is local (aka not directly connected to a db) then we need to
334
348
  //handle filtering/paging/sorting all on the front end
349
+ const newEnts = filterLocalEntitiesToHasura(entities, {
350
+ where,
351
+ order_by: (Array.isArray(order_by) ? order_by : [order_by]).map(obj => {
352
+ const path = Object.keys(obj)[0];
353
+ return {
354
+ path,
355
+ direction: obj[path],
356
+ ownProps,
357
+ ...ccFields[path]
358
+ };
359
+ }),
360
+ limit,
361
+ offset,
362
+ isInfinite
363
+ });
364
+
335
365
  toRet = {
336
366
  ...toRet,
337
- ...filterLocalEntitiesToHasura(entities, {
338
- where,
339
- order_by,
340
- limit,
341
- offset,
342
- isInfinite
343
- })
367
+ ...newEnts
344
368
  };
345
369
  return toRet;
346
370
  } else {
371
+ if (!order_by.length) {
372
+ // if no order by is specified, we will default to sorting by updatedAt
373
+ // this is useful for models that do not have a code field
374
+ order_by.push({ updatedAt: "desc" });
375
+ }
376
+ // in case entries that have the same value in the column being sorted on
377
+ // fall back to id as a secondary sort to make sure ordering happens correctly
378
+ order_by.push(
379
+ isCodeModel ? { code: "desc" } : { [window.__sortId || "id"]: "desc" }
380
+ );
381
+
347
382
  return {
348
383
  ...toRet,
349
384
  variables: {