@teselagen/ui 0.7.33-beta.4 → 0.7.33-beta.5

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.
@@ -1,6 +1,6 @@
1
- import { filterLocalEntitiesToHasura as filterRecords } from "./filterLocalEntitiesToHasura";
1
+ import { filterLocalEntitiesToHasura } from "./filterLocalEntitiesToHasura";
2
2
 
3
- describe("filterRecords", () => {
3
+ describe("filterLocalEntitiesToHasura", () => {
4
4
  const records = [
5
5
  {
6
6
  id: 123,
@@ -50,49 +50,61 @@ describe("filterRecords", () => {
50
50
  ];
51
51
 
52
52
  it("should filter by _eq", () => {
53
- const result = filterRecords(records, { where: { id: { _eq: 123 } } });
53
+ const result = filterLocalEntitiesToHasura(records, {
54
+ where: { id: { _eq: 123 } }
55
+ });
54
56
  expect(result.entities).toEqual([records[0]]);
55
57
  expect(result.entitiesAcrossPages).toEqual([records[0]]);
56
58
  expect(result.entityCount).toBe(1);
57
59
  });
58
60
 
59
61
  it("should filter by _neq", () => {
60
- const result = filterRecords(records, { where: { id: { _neq: 123 } } });
62
+ const result = filterLocalEntitiesToHasura(records, {
63
+ where: { id: { _neq: 123 } }
64
+ });
61
65
  expect(result.entities).toEqual(records.slice(1));
62
66
  expect(result.entitiesAcrossPages).toEqual(records.slice(1));
63
67
  expect(result.entityCount).toBe(3);
64
68
  });
65
69
 
66
70
  it("should filter by _gt", () => {
67
- const result = filterRecords(records, { where: { age: { _gt: 30 } } });
71
+ const result = filterLocalEntitiesToHasura(records, {
72
+ where: { age: { _gt: 30 } }
73
+ });
68
74
  expect(result.entities).toEqual([records[2]]);
69
75
  expect(result.entitiesAcrossPages).toEqual([records[2]]);
70
76
  expect(result.entityCount).toBe(1);
71
77
  });
72
78
 
73
79
  it("should filter by _gte", () => {
74
- const result = filterRecords(records, { where: { age: { _gte: 30 } } });
80
+ const result = filterLocalEntitiesToHasura(records, {
81
+ where: { age: { _gte: 30 } }
82
+ });
75
83
  expect(result.entities).toEqual([records[0], records[2]]);
76
84
  expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
77
85
  expect(result.entityCount).toBe(2);
78
86
  });
79
87
 
80
88
  it("should filter by _lt", () => {
81
- const result = filterRecords(records, { where: { age: { _lt: 25 } } });
89
+ const result = filterLocalEntitiesToHasura(records, {
90
+ where: { age: { _lt: 25 } }
91
+ });
82
92
  expect(result.entities).toEqual([records[3]]);
83
93
  expect(result.entitiesAcrossPages).toEqual([records[3]]);
84
94
  expect(result.entityCount).toBe(1);
85
95
  });
86
96
 
87
97
  it("should filter by _lte", () => {
88
- const result = filterRecords(records, { where: { age: { _lte: 25 } } });
98
+ const result = filterLocalEntitiesToHasura(records, {
99
+ where: { age: { _lte: 25 } }
100
+ });
89
101
  expect(result.entities).toEqual([records[1], records[3]]);
90
102
  expect(result.entitiesAcrossPages).toEqual([records[1], records[3]]);
91
103
  expect(result.entityCount).toBe(2);
92
104
  });
93
105
 
94
106
  it("should filter by _like", () => {
95
- const result = filterRecords(records, {
107
+ const result = filterLocalEntitiesToHasura(records, {
96
108
  where: { name: { _like: "%John%" } }
97
109
  });
98
110
  expect(result.entities).toEqual([records[0], records[2]]);
@@ -101,7 +113,7 @@ describe("filterRecords", () => {
101
113
  });
102
114
 
103
115
  it("should filter by _ilike", () => {
104
- const result = filterRecords(records, {
116
+ const result = filterLocalEntitiesToHasura(records, {
105
117
  where: { name: { _ilike: "%john%" } }
106
118
  });
107
119
  expect(result.entities).toEqual([records[0], records[2]]);
@@ -110,7 +122,7 @@ describe("filterRecords", () => {
110
122
  });
111
123
 
112
124
  it("should filter by _nlike", () => {
113
- const result = filterRecords(records, {
125
+ const result = filterLocalEntitiesToHasura(records, {
114
126
  where: { name: { _nlike: "%John%" } }
115
127
  });
116
128
  expect(result.entities).toEqual([records[1], records[3]]);
@@ -119,7 +131,7 @@ describe("filterRecords", () => {
119
131
  });
120
132
 
121
133
  it("should filter by _nilike", () => {
122
- const result = filterRecords(records, {
134
+ const result = filterLocalEntitiesToHasura(records, {
123
135
  where: { name: { _nilike: "%john%" } }
124
136
  });
125
137
  expect(result.entities).toEqual([records[1], records[3]]);
@@ -128,7 +140,7 @@ describe("filterRecords", () => {
128
140
  });
129
141
 
130
142
  it("should filter by _starts_with", () => {
131
- const result = filterRecords(records, {
143
+ const result = filterLocalEntitiesToHasura(records, {
132
144
  where: { name: { _starts_with: "John" } }
133
145
  });
134
146
  expect(result.entities).toEqual([records[0]]);
@@ -137,7 +149,7 @@ describe("filterRecords", () => {
137
149
  });
138
150
 
139
151
  it("should filter by _ends_with", () => {
140
- const result = filterRecords(records, {
152
+ const result = filterLocalEntitiesToHasura(records, {
141
153
  where: { name: { _ends_with: "Doe" } }
142
154
  });
143
155
  expect(result.entities).toEqual([records[0]]);
@@ -146,7 +158,7 @@ describe("filterRecords", () => {
146
158
  });
147
159
 
148
160
  it("should filter by _is_null", () => {
149
- const result = filterRecords(records, {
161
+ const result = filterLocalEntitiesToHasura(records, {
150
162
  where: { email: { _is_null: true } }
151
163
  });
152
164
  expect(result.entities).toEqual([records[1]]);
@@ -155,7 +167,7 @@ describe("filterRecords", () => {
155
167
  });
156
168
 
157
169
  it("should filter by _is_null false", () => {
158
- const result = filterRecords(records, {
170
+ const result = filterLocalEntitiesToHasura(records, {
159
171
  where: { email: { _is_null: false } }
160
172
  });
161
173
  expect(result.entities).toEqual([records[0], records[2], records[3]]);
@@ -168,7 +180,7 @@ describe("filterRecords", () => {
168
180
  });
169
181
 
170
182
  it("should filter by _and", () => {
171
- const result = filterRecords(records, {
183
+ const result = filterLocalEntitiesToHasura(records, {
172
184
  where: {
173
185
  _and: [{ age: { _gt: 25 } }, { city: { _eq: "London" } }]
174
186
  }
@@ -179,7 +191,7 @@ describe("filterRecords", () => {
179
191
  });
180
192
 
181
193
  it("should filter by _or", () => {
182
- const result = filterRecords(records, {
194
+ const result = filterLocalEntitiesToHasura(records, {
183
195
  where: {
184
196
  _or: [{ city: { _eq: "London" } }, { city: { _eq: "Paris" } }]
185
197
  }
@@ -194,7 +206,7 @@ describe("filterRecords", () => {
194
206
  });
195
207
 
196
208
  it("should filter by _not", () => {
197
- const result = filterRecords(records, {
209
+ const result = filterLocalEntitiesToHasura(records, {
198
210
  where: {
199
211
  _not: { is_active: { _eq: true } }
200
212
  }
@@ -205,7 +217,7 @@ describe("filterRecords", () => {
205
217
  });
206
218
 
207
219
  it("should filter by _contains", () => {
208
- const result = filterRecords(records, {
220
+ const result = filterLocalEntitiesToHasura(records, {
209
221
  where: {
210
222
  tags: { _contains: ["programming", "javascript"] }
211
223
  }
@@ -216,7 +228,7 @@ describe("filterRecords", () => {
216
228
  });
217
229
 
218
230
  it("should filter by _contained_in", () => {
219
- const result = filterRecords(records, {
231
+ const result = filterLocalEntitiesToHasura(records, {
220
232
  where: {
221
233
  tags: { _contained_in: ["programming", "javascript", "python", "java"] }
222
234
  }
@@ -227,7 +239,7 @@ describe("filterRecords", () => {
227
239
  });
228
240
 
229
241
  it("should filter by _has_key", () => {
230
- const result = filterRecords(records, {
242
+ const result = filterLocalEntitiesToHasura(records, {
231
243
  where: { data: { _has_key: "category" } }
232
244
  });
233
245
  expect(result.entities).toEqual(records);
@@ -236,7 +248,7 @@ describe("filterRecords", () => {
236
248
  });
237
249
 
238
250
  it("should filter by _has_keys_any", () => {
239
- const result = filterRecords(records, {
251
+ const result = filterLocalEntitiesToHasura(records, {
240
252
  where: {
241
253
  data: { _has_keys_any: ["category", "missingKey"] }
242
254
  }
@@ -247,7 +259,7 @@ describe("filterRecords", () => {
247
259
  });
248
260
 
249
261
  it("should filter by _has_keys_all", () => {
250
- const result = filterRecords(records, {
262
+ const result = filterLocalEntitiesToHasura(records, {
251
263
  where: {
252
264
  data: { _has_keys_all: ["category", "type"] }
253
265
  }
@@ -258,7 +270,7 @@ describe("filterRecords", () => {
258
270
  });
259
271
 
260
272
  it("should filter by _similar", () => {
261
- const result = filterRecords(records, {
273
+ const result = filterLocalEntitiesToHasura(records, {
262
274
  where: {
263
275
  username: { _similar: "(john|alice)%" }
264
276
  }
@@ -269,7 +281,7 @@ describe("filterRecords", () => {
269
281
  });
270
282
 
271
283
  it("should filter by range _gte and _lte", () => {
272
- const result = filterRecords(records, {
284
+ const result = filterLocalEntitiesToHasura(records, {
273
285
  where: { age: { _gte: 25, _lte: 30 } }
274
286
  });
275
287
  expect(result.entities).toEqual([records[0], records[1]]);
@@ -278,7 +290,7 @@ describe("filterRecords", () => {
278
290
  });
279
291
 
280
292
  it("should filter by range _gt and _lt", () => {
281
- const result = filterRecords(records, {
293
+ const result = filterLocalEntitiesToHasura(records, {
282
294
  where: { age: { _gt: 25, _lt: 35 } }
283
295
  });
284
296
  expect(result.entities).toEqual([records[0]]);
@@ -287,14 +299,22 @@ describe("filterRecords", () => {
287
299
  });
288
300
 
289
301
  it("should handle empty where clause", () => {
290
- const result = filterRecords(records, {});
302
+ const result = filterLocalEntitiesToHasura(records, {});
303
+ expect(result.entities).toEqual(records);
304
+ expect(result.entitiesAcrossPages).toEqual(records);
305
+ expect(result.entityCount).toBe(4);
306
+ });
307
+ it("should handle empty _and and _or clauses", () => {
308
+ const result = filterLocalEntitiesToHasura(records, {
309
+ where: { _and: [], _or: [] }
310
+ });
291
311
  expect(result.entities).toEqual(records);
292
312
  expect(result.entitiesAcrossPages).toEqual(records);
293
313
  expect(result.entityCount).toBe(4);
294
314
  });
295
315
 
296
316
  it("should handle nested _and and _or", () => {
297
- const result = filterRecords(records, {
317
+ const result = filterLocalEntitiesToHasura(records, {
298
318
  where: {
299
319
  _and: [
300
320
  { _or: [{ city: { _eq: "London" } }, { city: { _eq: "Paris" } }] },
@@ -311,7 +331,7 @@ describe("filterRecords", () => {
311
331
  expect(result.entityCount).toBe(3);
312
332
  });
313
333
  it("should order by age ascending", () => {
314
- const result = filterRecords(records, {
334
+ const result = filterLocalEntitiesToHasura(records, {
315
335
  order_by: { age: "asc" }
316
336
  });
317
337
  expect(result.entities).toEqual([
@@ -330,7 +350,7 @@ describe("filterRecords", () => {
330
350
  });
331
351
 
332
352
  it("should order by age descending", () => {
333
- const result = filterRecords(records, {
353
+ const result = filterLocalEntitiesToHasura(records, {
334
354
  order_by: { age: "desc" }
335
355
  });
336
356
  expect(result.entities).toEqual([
@@ -349,7 +369,7 @@ describe("filterRecords", () => {
349
369
  });
350
370
 
351
371
  it("should order by name ascending", () => {
352
- const result = filterRecords(records, {
372
+ const result = filterLocalEntitiesToHasura(records, {
353
373
  order_by: { name: "asc" }
354
374
  });
355
375
  expect(result.entities).toEqual([
@@ -368,7 +388,7 @@ describe("filterRecords", () => {
368
388
  });
369
389
 
370
390
  it("should order by name descending", () => {
371
- const result = filterRecords(records, {
391
+ const result = filterLocalEntitiesToHasura(records, {
372
392
  order_by: { name: "desc" }
373
393
  });
374
394
  expect(result.entities).toEqual([
@@ -387,7 +407,7 @@ describe("filterRecords", () => {
387
407
  });
388
408
 
389
409
  it("should filter and order", () => {
390
- const result = filterRecords(records, {
410
+ const result = filterLocalEntitiesToHasura(records, {
391
411
  where: { city: { _eq: "London" } },
392
412
  order_by: { age: "desc" }
393
413
  });
@@ -397,7 +417,7 @@ describe("filterRecords", () => {
397
417
  });
398
418
 
399
419
  it("should handle empty order_by", () => {
400
- const result = filterRecords(records, {
420
+ const result = filterLocalEntitiesToHasura(records, {
401
421
  where: { city: { _eq: "London" } }
402
422
  });
403
423
  expect(result.entities).toEqual([records[0], records[2]]);
@@ -406,7 +426,7 @@ describe("filterRecords", () => {
406
426
  });
407
427
 
408
428
  it("should handle order_by with empty where", () => {
409
- const result = filterRecords(records, {
429
+ const result = filterLocalEntitiesToHasura(records, {
410
430
  order_by: { age: "asc" }
411
431
  });
412
432
  expect(result.entities).toEqual([
@@ -425,28 +445,31 @@ describe("filterRecords", () => {
425
445
  });
426
446
 
427
447
  it("should apply limit", () => {
428
- const result = filterRecords(records, { limit: 2 });
448
+ const result = filterLocalEntitiesToHasura(records, { limit: 2 });
429
449
  expect(result.entities).toEqual([records[0], records[1]]);
430
450
  expect(result.entitiesAcrossPages).toEqual(records);
431
451
  expect(result.entityCount).toBe(4);
432
452
  });
433
453
 
434
454
  it("should apply offset", () => {
435
- const result = filterRecords(records, { offset: 2 });
455
+ const result = filterLocalEntitiesToHasura(records, { offset: 2 });
436
456
  expect(result.entities).toEqual([records[2], records[3]]);
437
457
  expect(result.entitiesAcrossPages).toEqual(records);
438
458
  expect(result.entityCount).toBe(4);
439
459
  });
440
460
 
441
461
  it("should apply limit and offset", () => {
442
- const result = filterRecords(records, { limit: 1, offset: 2 });
462
+ const result = filterLocalEntitiesToHasura(records, {
463
+ limit: 1,
464
+ offset: 2
465
+ });
443
466
  expect(result.entities).toEqual([records[2]]);
444
467
  expect(result.entitiesAcrossPages).toEqual(records);
445
468
  expect(result.entityCount).toBe(4);
446
469
  });
447
470
 
448
471
  it("should apply limit to filtered results", () => {
449
- const result = filterRecords(records, {
472
+ const result = filterLocalEntitiesToHasura(records, {
450
473
  where: { city: { _eq: "London" } },
451
474
  limit: 1
452
475
  });
@@ -456,7 +479,7 @@ describe("filterRecords", () => {
456
479
  });
457
480
 
458
481
  it("should apply offset to filtered results", () => {
459
- const result = filterRecords(records, {
482
+ const result = filterLocalEntitiesToHasura(records, {
460
483
  where: { city: { _eq: "London" } },
461
484
  offset: 1
462
485
  });
@@ -466,7 +489,7 @@ describe("filterRecords", () => {
466
489
  });
467
490
 
468
491
  it("should apply limit and offset to filtered and ordered results", () => {
469
- const result = filterRecords(records, {
492
+ const result = filterLocalEntitiesToHasura(records, {
470
493
  where: { city: { _eq: "London" } },
471
494
  order_by: { age: "desc" },
472
495
  limit: 1,
@@ -478,21 +501,21 @@ describe("filterRecords", () => {
478
501
  });
479
502
 
480
503
  it("should handle offset greater than array length", () => {
481
- const result = filterRecords(records, { offset: 10 });
504
+ const result = filterLocalEntitiesToHasura(records, { offset: 10 });
482
505
  expect(result.entities).toEqual([]);
483
506
  expect(result.entitiesAcrossPages).toEqual(records);
484
507
  expect(result.entityCount).toBe(4);
485
508
  });
486
509
 
487
510
  it("should handle limit greater than array length", () => {
488
- const result = filterRecords(records, { limit: 10 });
511
+ const result = filterLocalEntitiesToHasura(records, { limit: 10 });
489
512
  expect(result.entities).toEqual(records);
490
513
  expect(result.entitiesAcrossPages).toEqual(records);
491
514
  expect(result.entityCount).toBe(4);
492
515
  });
493
516
 
494
517
  it("should handle isInfinite option with filtering", () => {
495
- const result = filterRecords(records, {
518
+ const result = filterLocalEntitiesToHasura(records, {
496
519
  where: { city: { _eq: "London" } },
497
520
  isInfinite: true
498
521
  });
@@ -502,7 +525,7 @@ describe("filterRecords", () => {
502
525
  });
503
526
 
504
527
  it("should handle isInfinite option with filtering, limit, and offset", () => {
505
- const result = filterRecords(records, {
528
+ const result = filterLocalEntitiesToHasura(records, {
506
529
  where: { city: { _eq: "London" } },
507
530
  limit: 1,
508
531
  offset: 1,
@@ -24,4 +24,3 @@ export const addCustomColumnFilters = (where, fields, currentParams) => {
24
24
  customColumnFilter(where, currentParams);
25
25
  });
26
26
  };
27
-
@@ -1,6 +1,9 @@
1
1
  import queryString from "qs";
2
2
  import { uniqBy, clone, camelCase } from "lodash-es";
3
- import { tableQueryParamsToHasuraClauses } from "./tableQueryParamsToHasuraClauses";
3
+ import {
4
+ getFieldsMappedByCCDisplayName,
5
+ tableQueryParamsToHasuraClauses
6
+ } from "./tableQueryParamsToHasuraClauses";
4
7
  import { filterLocalEntitiesToHasura } from "./filterLocalEntitiesToHasura";
5
8
  import {
6
9
  addCustomColumnFilters,
@@ -54,17 +57,6 @@ function safeParse(val) {
54
57
  }
55
58
  }
56
59
 
57
- /**
58
- *
59
- * @param {object} field
60
- * @returns the camelCase display name of the field, to be used for filters, sorting, etc
61
- */
62
- export function getCCDisplayName(field) {
63
- return camelCase(
64
- typeof field.displayName === "string" ? field.displayName : field.path
65
- );
66
- }
67
-
68
60
  export function getCurrentParamsFromUrl(location, isSimple) {
69
61
  let { search } = location;
70
62
  if (isSimple) {
@@ -260,7 +252,7 @@ export function getQueryParams({
260
252
  isLocalCall,
261
253
  additionalFilter,
262
254
  doNotCoercePageSize,
263
- // noOrderError,
255
+ noOrderError,
264
256
  // isCodeModel,
265
257
  ownProps
266
258
  }) {
@@ -288,26 +280,44 @@ export function getQueryParams({
288
280
  )[0];
289
281
  pageSize = closest;
290
282
  }
283
+
284
+ const cleanedOrder = [];
285
+ if (order && order.length) {
286
+ const ccFields = getFieldsMappedByCCDisplayName(schema);
287
+ order.forEach(orderVal => {
288
+ const ccDisplayName = orderVal.replace(/^-/gi, "");
289
+ const schemaForField = ccFields[ccDisplayName];
290
+ if (schemaForField) {
291
+ const { path } = schemaForField;
292
+ const reversed = ccDisplayName !== orderVal;
293
+ const prefix = reversed ? "-" : "";
294
+ cleanedOrder.push(prefix + path);
295
+ } else {
296
+ !noOrderError &&
297
+ console.error(
298
+ "No schema for field found!",
299
+ ccDisplayName,
300
+ JSON.stringify(schema.fields, null, 2)
301
+ );
302
+ }
303
+ });
304
+ }
305
+
291
306
  const toReturn = {
292
307
  //these are values that might be generally useful for the wrapped component
293
308
  page,
294
309
  pageSize: ownProps.controlled_pageSize || pageSize,
295
- order,
310
+ order: cleanedOrder,
296
311
  filters,
297
312
  searchTerm
298
313
  };
299
- // tnwtodo: need to make sure ignoreSearchTerm still works
300
- // if (additionalOrFilterToUse && additionalOrFilterToUse.ignoreSearchTerm) {
301
- // searchTerm = "";
302
- // additionalOrFilterToUse = additionalOrFilterToUse.additionalOrFilterToUse;
303
- // }
304
314
 
305
315
  const { where, order_by, limit, offset } = tableQueryParamsToHasuraClauses({
306
316
  page,
307
317
  pageSize,
308
318
  searchTerm,
309
319
  filters,
310
- order,
320
+ order: cleanedOrder,
311
321
  schema
312
322
  });
313
323
  initializeHasuraWhereAndFilter(additionalFilter, where, currentParams);
@@ -315,13 +325,14 @@ export function getQueryParams({
315
325
  if (isLocalCall) {
316
326
  //if the table is local (aka not directly connected to a db) then we need to
317
327
  //handle filtering/paging/sorting all on the front end
318
- return filterLocalEntitiesToHasura(entities, {
328
+ const toRet = filterLocalEntitiesToHasura(entities, {
319
329
  where,
320
330
  order_by,
321
331
  limit,
322
332
  offset,
323
333
  isInfinite
324
334
  });
335
+ return toRet;
325
336
  } else {
326
337
  return {
327
338
  ...toReturn,