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

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,23 +290,80 @@ 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]]);
285
297
  expect(result.entitiesAcrossPages).toEqual([records[0]]);
286
298
  expect(result.entityCount).toBe(1);
287
299
  });
300
+ it("should filter with nested filters in _and and _or properly ", () => {
301
+ const result = filterLocalEntitiesToHasura(
302
+ [
303
+ {
304
+ id: 1,
305
+ type: {
306
+ special: "01"
307
+ }
308
+ },
309
+ {
310
+ id: 2,
311
+ type: {
312
+ special: "02"
313
+ }
314
+ }
315
+ ],
316
+ {
317
+ where: {
318
+ _and: [
319
+ {
320
+ type: {
321
+ special: {
322
+ _ilike: "%01%"
323
+ }
324
+ }
325
+ }
326
+ ],
327
+ _or: []
328
+ }
329
+ }
330
+ );
331
+ expect(result.entities).toEqual([
332
+ {
333
+ id: 1,
334
+ type: {
335
+ special: "01"
336
+ }
337
+ }
338
+ ]);
339
+ expect(result.entitiesAcrossPages).toEqual([
340
+ {
341
+ id: 1,
342
+ type: {
343
+ special: "01"
344
+ }
345
+ }
346
+ ]);
347
+ expect(result.entityCount).toBe(1);
348
+ });
288
349
 
289
350
  it("should handle empty where clause", () => {
290
- const result = filterRecords(records, {});
351
+ const result = filterLocalEntitiesToHasura(records, {});
352
+ expect(result.entities).toEqual(records);
353
+ expect(result.entitiesAcrossPages).toEqual(records);
354
+ expect(result.entityCount).toBe(4);
355
+ });
356
+ it("should handle empty _and and _or clauses", () => {
357
+ const result = filterLocalEntitiesToHasura(records, {
358
+ where: { _and: [], _or: [] }
359
+ });
291
360
  expect(result.entities).toEqual(records);
292
361
  expect(result.entitiesAcrossPages).toEqual(records);
293
362
  expect(result.entityCount).toBe(4);
294
363
  });
295
364
 
296
365
  it("should handle nested _and and _or", () => {
297
- const result = filterRecords(records, {
366
+ const result = filterLocalEntitiesToHasura(records, {
298
367
  where: {
299
368
  _and: [
300
369
  { _or: [{ city: { _eq: "London" } }, { city: { _eq: "Paris" } }] },
@@ -311,7 +380,7 @@ describe("filterRecords", () => {
311
380
  expect(result.entityCount).toBe(3);
312
381
  });
313
382
  it("should order by age ascending", () => {
314
- const result = filterRecords(records, {
383
+ const result = filterLocalEntitiesToHasura(records, {
315
384
  order_by: { age: "asc" }
316
385
  });
317
386
  expect(result.entities).toEqual([
@@ -330,7 +399,7 @@ describe("filterRecords", () => {
330
399
  });
331
400
 
332
401
  it("should order by age descending", () => {
333
- const result = filterRecords(records, {
402
+ const result = filterLocalEntitiesToHasura(records, {
334
403
  order_by: { age: "desc" }
335
404
  });
336
405
  expect(result.entities).toEqual([
@@ -349,7 +418,7 @@ describe("filterRecords", () => {
349
418
  });
350
419
 
351
420
  it("should order by name ascending", () => {
352
- const result = filterRecords(records, {
421
+ const result = filterLocalEntitiesToHasura(records, {
353
422
  order_by: { name: "asc" }
354
423
  });
355
424
  expect(result.entities).toEqual([
@@ -368,7 +437,7 @@ describe("filterRecords", () => {
368
437
  });
369
438
 
370
439
  it("should order by name descending", () => {
371
- const result = filterRecords(records, {
440
+ const result = filterLocalEntitiesToHasura(records, {
372
441
  order_by: { name: "desc" }
373
442
  });
374
443
  expect(result.entities).toEqual([
@@ -387,7 +456,7 @@ describe("filterRecords", () => {
387
456
  });
388
457
 
389
458
  it("should filter and order", () => {
390
- const result = filterRecords(records, {
459
+ const result = filterLocalEntitiesToHasura(records, {
391
460
  where: { city: { _eq: "London" } },
392
461
  order_by: { age: "desc" }
393
462
  });
@@ -397,7 +466,7 @@ describe("filterRecords", () => {
397
466
  });
398
467
 
399
468
  it("should handle empty order_by", () => {
400
- const result = filterRecords(records, {
469
+ const result = filterLocalEntitiesToHasura(records, {
401
470
  where: { city: { _eq: "London" } }
402
471
  });
403
472
  expect(result.entities).toEqual([records[0], records[2]]);
@@ -406,7 +475,7 @@ describe("filterRecords", () => {
406
475
  });
407
476
 
408
477
  it("should handle order_by with empty where", () => {
409
- const result = filterRecords(records, {
478
+ const result = filterLocalEntitiesToHasura(records, {
410
479
  order_by: { age: "asc" }
411
480
  });
412
481
  expect(result.entities).toEqual([
@@ -425,28 +494,31 @@ describe("filterRecords", () => {
425
494
  });
426
495
 
427
496
  it("should apply limit", () => {
428
- const result = filterRecords(records, { limit: 2 });
497
+ const result = filterLocalEntitiesToHasura(records, { limit: 2 });
429
498
  expect(result.entities).toEqual([records[0], records[1]]);
430
499
  expect(result.entitiesAcrossPages).toEqual(records);
431
500
  expect(result.entityCount).toBe(4);
432
501
  });
433
502
 
434
503
  it("should apply offset", () => {
435
- const result = filterRecords(records, { offset: 2 });
504
+ const result = filterLocalEntitiesToHasura(records, { offset: 2 });
436
505
  expect(result.entities).toEqual([records[2], records[3]]);
437
506
  expect(result.entitiesAcrossPages).toEqual(records);
438
507
  expect(result.entityCount).toBe(4);
439
508
  });
440
509
 
441
510
  it("should apply limit and offset", () => {
442
- const result = filterRecords(records, { limit: 1, offset: 2 });
511
+ const result = filterLocalEntitiesToHasura(records, {
512
+ limit: 1,
513
+ offset: 2
514
+ });
443
515
  expect(result.entities).toEqual([records[2]]);
444
516
  expect(result.entitiesAcrossPages).toEqual(records);
445
517
  expect(result.entityCount).toBe(4);
446
518
  });
447
519
 
448
520
  it("should apply limit to filtered results", () => {
449
- const result = filterRecords(records, {
521
+ const result = filterLocalEntitiesToHasura(records, {
450
522
  where: { city: { _eq: "London" } },
451
523
  limit: 1
452
524
  });
@@ -456,7 +528,7 @@ describe("filterRecords", () => {
456
528
  });
457
529
 
458
530
  it("should apply offset to filtered results", () => {
459
- const result = filterRecords(records, {
531
+ const result = filterLocalEntitiesToHasura(records, {
460
532
  where: { city: { _eq: "London" } },
461
533
  offset: 1
462
534
  });
@@ -466,7 +538,7 @@ describe("filterRecords", () => {
466
538
  });
467
539
 
468
540
  it("should apply limit and offset to filtered and ordered results", () => {
469
- const result = filterRecords(records, {
541
+ const result = filterLocalEntitiesToHasura(records, {
470
542
  where: { city: { _eq: "London" } },
471
543
  order_by: { age: "desc" },
472
544
  limit: 1,
@@ -478,21 +550,21 @@ describe("filterRecords", () => {
478
550
  });
479
551
 
480
552
  it("should handle offset greater than array length", () => {
481
- const result = filterRecords(records, { offset: 10 });
553
+ const result = filterLocalEntitiesToHasura(records, { offset: 10 });
482
554
  expect(result.entities).toEqual([]);
483
555
  expect(result.entitiesAcrossPages).toEqual(records);
484
556
  expect(result.entityCount).toBe(4);
485
557
  });
486
558
 
487
559
  it("should handle limit greater than array length", () => {
488
- const result = filterRecords(records, { limit: 10 });
560
+ const result = filterLocalEntitiesToHasura(records, { limit: 10 });
489
561
  expect(result.entities).toEqual(records);
490
562
  expect(result.entitiesAcrossPages).toEqual(records);
491
563
  expect(result.entityCount).toBe(4);
492
564
  });
493
565
 
494
566
  it("should handle isInfinite option with filtering", () => {
495
- const result = filterRecords(records, {
567
+ const result = filterLocalEntitiesToHasura(records, {
496
568
  where: { city: { _eq: "London" } },
497
569
  isInfinite: true
498
570
  });
@@ -502,7 +574,7 @@ describe("filterRecords", () => {
502
574
  });
503
575
 
504
576
  it("should handle isInfinite option with filtering, limit, and offset", () => {
505
- const result = filterRecords(records, {
577
+ const result = filterLocalEntitiesToHasura(records, {
506
578
  where: { city: { _eq: "London" } },
507
579
  limit: 1,
508
580
  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
  }
291
- const toReturn = {
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
+
306
+ let toRet = {
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,16 +325,20 @@ 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, {
319
- where,
320
- order_by,
321
- limit,
322
- offset,
323
- isInfinite
324
- });
328
+ toRet = {
329
+ ...toRet,
330
+ ...filterLocalEntitiesToHasura(entities, {
331
+ where,
332
+ order_by,
333
+ limit,
334
+ offset,
335
+ isInfinite
336
+ })
337
+ };
338
+ return toRet;
325
339
  } else {
326
340
  return {
327
- ...toReturn,
341
+ ...toRet,
328
342
  variables: {
329
343
  where,
330
344
  order_by,