@teselagen/ui 0.7.33-beta.3 → 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.
Files changed (142) hide show
  1. package/DataTable/utils/queryParams.d.ts +3 -8
  2. package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +12 -0
  3. package/index.cjs.js +161 -27
  4. package/index.es.js +161 -27
  5. package/package.json +1 -1
  6. package/src/AdvancedOptions.spec.js +26 -0
  7. package/src/AsyncValidateFieldSpinner/index.js +12 -0
  8. package/src/BlueprintError/index.js +14 -0
  9. package/src/BounceLoader/index.js +16 -0
  10. package/src/BounceLoader/style.css +45 -0
  11. package/src/CollapsibleCard/index.js +68 -0
  12. package/src/CollapsibleCard/style.css +23 -0
  13. package/src/DNALoader/index.js +20 -0
  14. package/src/DNALoader/style.css +251 -0
  15. package/src/{Columns.js → DataTable/Columns.js} +1 -1
  16. package/src/{DisplayOptions.js → DataTable/DisplayOptions.js} +1 -1
  17. package/src/DataTable/index.js +3209 -0
  18. package/src/DataTable/style.css +608 -0
  19. package/src/{filterLocalEntitiesToHasura.js → DataTable/utils/filterLocalEntitiesToHasura.js} +6 -0
  20. package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +538 -0
  21. package/src/DataTable/utils/index.js +55 -0
  22. package/src/{initializeHasuraWhereAndFilter.js → DataTable/utils/initializeHasuraWhereAndFilter.js} +0 -1
  23. package/src/{queryParams.js → DataTable/utils/queryParams.js} +32 -21
  24. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +250 -0
  25. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +206 -0
  26. package/src/{withTableParams.js → DataTable/utils/withTableParams.js} +2 -2
  27. package/src/DialogFooter/index.js +86 -0
  28. package/src/DialogFooter/style.css +9 -0
  29. package/src/FormComponents/index.js +1266 -0
  30. package/src/FormComponents/style.css +275 -0
  31. package/src/FormComponents/utils.js +6 -0
  32. package/src/HotkeysDialog/index.js +79 -0
  33. package/src/HotkeysDialog/style.css +54 -0
  34. package/src/InfoHelper/index.js +78 -0
  35. package/src/InfoHelper/style.css +7 -0
  36. package/src/IntentText/index.js +18 -0
  37. package/src/Loading/index.js +70 -0
  38. package/src/Loading/style.css +4 -0
  39. package/src/MenuBar/index.js +423 -0
  40. package/src/MenuBar/style.css +45 -0
  41. package/src/PromptUnsavedChanges/index.js +38 -0
  42. package/src/ResizableDraggableDialog/index.js +141 -0
  43. package/src/ResizableDraggableDialog/style.css +42 -0
  44. package/src/ScrollToTop/index.js +72 -0
  45. package/src/TagSelect/index.js +69 -0
  46. package/src/TagSelect/style.css +13 -0
  47. package/src/TgHtmlSelect/index.js +20 -0
  48. package/src/TgSelect/index.js +537 -0
  49. package/src/TgSelect/style.css +61 -0
  50. package/src/TgSuggest/index.js +124 -0
  51. package/src/Timeline/index.js +15 -0
  52. package/src/Timeline/style.css +29 -0
  53. package/src/enhancers/withDialog/index.js +196 -0
  54. package/src/index.js +88 -1
  55. package/src/showConfirmationDialog/index.js +148 -0
  56. package/src/style.css +261 -9
  57. package/src/utils/hooks/index.js +1 -0
  58. package/DataTable/utils/simplifyHasuraWhere.d.ts +0 -1
  59. package/src/simplifyHasuraWhere.js +0 -80
  60. package/src/tableQueryParamsToHasuraClauses.js +0 -113
  61. /package/src/{CellDragHandle.js → DataTable/CellDragHandle.js} +0 -0
  62. /package/src/{ColumnFilterMenu.js → DataTable/ColumnFilterMenu.js} +0 -0
  63. /package/src/{DisabledLoadingComponent.js → DataTable/DisabledLoadingComponent.js} +0 -0
  64. /package/src/{DropdownCell.js → DataTable/DropdownCell.js} +0 -0
  65. /package/src/{EditableCell.js → DataTable/EditableCell.js} +0 -0
  66. /package/src/{FilterAndSortMenu.js → DataTable/FilterAndSortMenu.js} +0 -0
  67. /package/src/{PagingTool.js → DataTable/PagingTool.js} +0 -0
  68. /package/src/{RenderCell.js → DataTable/RenderCell.js} +0 -0
  69. /package/src/{SearchBar.js → DataTable/SearchBar.js} +0 -0
  70. /package/src/{SortableColumns.js → DataTable/SortableColumns.js} +0 -0
  71. /package/src/{TableFormTrackerContext.js → DataTable/TableFormTrackerContext.js} +0 -0
  72. /package/src/{ThComponent.js → DataTable/ThComponent.js} +0 -0
  73. /package/src/{dataTableEnhancer.js → DataTable/dataTableEnhancer.js} +0 -0
  74. /package/src/{defaultFormatters.js → DataTable/defaultFormatters.js} +0 -0
  75. /package/src/{defaultValidators.js → DataTable/defaultValidators.js} +0 -0
  76. /package/src/{editCellHelper.js → DataTable/editCellHelper.js} +0 -0
  77. /package/src/{getCellVal.js → DataTable/getCellVal.js} +0 -0
  78. /package/src/{getVals.js → DataTable/getVals.js} +0 -0
  79. /package/src/{isTruthy.js → DataTable/isTruthy.js} +0 -0
  80. /package/src/{isValueEmpty.js → DataTable/isValueEmpty.js} +0 -0
  81. /package/src/{convertSchema.js → DataTable/utils/convertSchema.js} +0 -0
  82. /package/src/{formatPasteData.js → DataTable/utils/formatPasteData.js} +0 -0
  83. /package/src/{getAllRows.js → DataTable/utils/getAllRows.js} +0 -0
  84. /package/src/{getCellCopyText.js → DataTable/utils/getCellCopyText.js} +0 -0
  85. /package/src/{getCellInfo.js → DataTable/utils/getCellInfo.js} +0 -0
  86. /package/src/{getFieldPathToField.js → DataTable/utils/getFieldPathToField.js} +0 -0
  87. /package/src/{getIdOrCodeOrIndex.js → DataTable/utils/getIdOrCodeOrIndex.js} +0 -0
  88. /package/src/{getLastSelectedEntity.js → DataTable/utils/getLastSelectedEntity.js} +0 -0
  89. /package/src/{getNewEntToSelect.js → DataTable/utils/getNewEntToSelect.js} +0 -0
  90. /package/src/{getRowCopyText.js → DataTable/utils/getRowCopyText.js} +0 -0
  91. /package/src/{getTableConfigFromStorage.js → DataTable/utils/getTableConfigFromStorage.js} +0 -0
  92. /package/src/{handleCopyColumn.js → DataTable/utils/handleCopyColumn.js} +0 -0
  93. /package/src/{handleCopyHelper.js → DataTable/utils/handleCopyHelper.js} +0 -0
  94. /package/src/{handleCopyRows.js → DataTable/utils/handleCopyRows.js} +0 -0
  95. /package/src/{handleCopyTable.js → DataTable/utils/handleCopyTable.js} +0 -0
  96. /package/src/{isBottomRightCornerOfRectangle.js → DataTable/utils/isBottomRightCornerOfRectangle.js} +0 -0
  97. /package/src/{isEntityClean.js → DataTable/utils/isEntityClean.js} +0 -0
  98. /package/src/{primarySelectedValue.js → DataTable/utils/primarySelectedValue.js} +0 -0
  99. /package/src/{removeCleanRows.js → DataTable/utils/removeCleanRows.js} +0 -0
  100. /package/src/{rowClick.js → DataTable/utils/rowClick.js} +0 -0
  101. /package/src/{selection.js → DataTable/utils/selection.js} +0 -0
  102. /package/src/{useTableEntities.js → DataTable/utils/useTableEntities.js} +0 -0
  103. /package/src/{utils.js → DataTable/utils/utils.js} +0 -0
  104. /package/src/{withSelectedEntities.js → DataTable/utils/withSelectedEntities.js} +0 -0
  105. /package/src/{validateTableWideErrors.js → DataTable/validateTableWideErrors.js} +0 -0
  106. /package/src/{viewColumn.js → DataTable/viewColumn.js} +0 -0
  107. /package/src/{FormSeparator.js → FormComponents/FormSeparator.js} +0 -0
  108. /package/src/{LoadingDots.js → FormComponents/LoadingDots.js} +0 -0
  109. /package/src/{Uploader.js → FormComponents/Uploader.js} +0 -0
  110. /package/src/{getNewName.js → FormComponents/getNewName.js} +0 -0
  111. /package/src/{itemUpload.js → FormComponents/itemUpload.js} +0 -0
  112. /package/src/{sortify.js → FormComponents/sortify.js} +0 -0
  113. /package/src/{tryToMatchSchemas.js → FormComponents/tryToMatchSchemas.js} +0 -0
  114. /package/src/{TimelineEvent.js → Timeline/TimelineEvent.js} +0 -0
  115. /package/src/{tg_modalState.js → enhancers/withDialog/tg_modalState.js} +0 -0
  116. /package/src/{withField.js → enhancers/withField.js} +0 -0
  117. /package/src/{withFields.js → enhancers/withFields.js} +0 -0
  118. /package/src/{withLocalStorage.js → enhancers/withLocalStorage.js} +0 -0
  119. /package/src/{adHoc.js → utils/adHoc.js} +0 -0
  120. /package/src/{basicHandleActionsWithFullState.js → utils/basicHandleActionsWithFullState.js} +0 -0
  121. /package/src/{browserUtils.js → utils/browserUtils.js} +0 -0
  122. /package/src/{combineReducersWithFullState.js → utils/combineReducersWithFullState.js} +0 -0
  123. /package/src/{commandControls.js → utils/commandControls.js} +0 -0
  124. /package/src/{commandUtils.js → utils/commandUtils.js} +0 -0
  125. /package/src/{determineBlackOrWhiteTextColor.js → utils/determineBlackOrWhiteTextColor.js} +0 -0
  126. /package/src/{getDayjsFormatter.js → utils/getDayjsFormatter.js} +0 -0
  127. /package/src/{getTextFromEl.js → utils/getTextFromEl.js} +0 -0
  128. /package/src/{handlerHelpers.js → utils/handlerHelpers.js} +0 -0
  129. /package/src/{useDeepEqualMemo.js → utils/hooks/useDeepEqualMemo.js} +0 -0
  130. /package/src/{useStableReference.js → utils/hooks/useStableReference.js} +0 -0
  131. /package/src/{hotkeyUtils.js → utils/hotkeyUtils.js} +0 -0
  132. /package/src/{isBeingCalledExcessively.js → utils/isBeingCalledExcessively.js} +0 -0
  133. /package/src/{menuUtils.js → utils/menuUtils.js} +0 -0
  134. /package/src/{popoverOverflowModifiers.js → utils/popoverOverflowModifiers.js} +0 -0
  135. /package/src/{pureNoFunc.js → utils/pureNoFunc.js} +0 -0
  136. /package/src/{renderOnDoc.js → utils/renderOnDoc.js} +0 -0
  137. /package/src/{showProgressToast.js → utils/showProgressToast.js} +0 -0
  138. /package/src/{tagUtils.js → utils/tagUtils.js} +0 -0
  139. /package/src/{tgFormValues.js → utils/tgFormValues.js} +0 -0
  140. /package/src/{useTraceUpdate.js → utils/useTraceUpdate.js} +0 -0
  141. /package/src/{withSelectTableRecords.js → utils/withSelectTableRecords.js} +0 -0
  142. /package/src/{withStore.js → utils/withStore.js} +0 -0
@@ -0,0 +1,538 @@
1
+ import { filterLocalEntitiesToHasura } from "./filterLocalEntitiesToHasura";
2
+
3
+ describe("filterLocalEntitiesToHasura", () => {
4
+ const records = [
5
+ {
6
+ id: 123,
7
+ name: "John Doe",
8
+ age: 30,
9
+ is_active: true,
10
+ city: "London",
11
+
12
+ tags: ["programming", "javascript"],
13
+ email: "john@example.com",
14
+ data: { category: "A", type: "X" },
15
+ username: "john123"
16
+ },
17
+ {
18
+ id: 456,
19
+ name: "Jane Smith",
20
+ age: 25,
21
+ is_active: false,
22
+ city: "Paris",
23
+ tags: ["javascript", "python"],
24
+ email: null,
25
+ data: { category: "B", type: "Y" },
26
+ username: "jane456"
27
+ },
28
+ {
29
+ id: 789,
30
+ name: "Alice Johnson",
31
+ age: 35,
32
+ is_active: true,
33
+ city: "London",
34
+ tags: ["programming", "python", "java"],
35
+ email: "alice@example.com",
36
+ data: { category: "A", type: "Z" },
37
+ username: "alice789"
38
+ },
39
+ {
40
+ id: 101,
41
+ name: "Bob Williams",
42
+ age: 20,
43
+ is_active: false,
44
+ city: "New York",
45
+ tags: ["java"],
46
+ email: "bob@example.com",
47
+ data: { category: "C", type: "X" },
48
+ username: "bob101"
49
+ }
50
+ ];
51
+
52
+ it("should filter by _eq", () => {
53
+ const result = filterLocalEntitiesToHasura(records, {
54
+ where: { id: { _eq: 123 } }
55
+ });
56
+ expect(result.entities).toEqual([records[0]]);
57
+ expect(result.entitiesAcrossPages).toEqual([records[0]]);
58
+ expect(result.entityCount).toBe(1);
59
+ });
60
+
61
+ it("should filter by _neq", () => {
62
+ const result = filterLocalEntitiesToHasura(records, {
63
+ where: { id: { _neq: 123 } }
64
+ });
65
+ expect(result.entities).toEqual(records.slice(1));
66
+ expect(result.entitiesAcrossPages).toEqual(records.slice(1));
67
+ expect(result.entityCount).toBe(3);
68
+ });
69
+
70
+ it("should filter by _gt", () => {
71
+ const result = filterLocalEntitiesToHasura(records, {
72
+ where: { age: { _gt: 30 } }
73
+ });
74
+ expect(result.entities).toEqual([records[2]]);
75
+ expect(result.entitiesAcrossPages).toEqual([records[2]]);
76
+ expect(result.entityCount).toBe(1);
77
+ });
78
+
79
+ it("should filter by _gte", () => {
80
+ const result = filterLocalEntitiesToHasura(records, {
81
+ where: { age: { _gte: 30 } }
82
+ });
83
+ expect(result.entities).toEqual([records[0], records[2]]);
84
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
85
+ expect(result.entityCount).toBe(2);
86
+ });
87
+
88
+ it("should filter by _lt", () => {
89
+ const result = filterLocalEntitiesToHasura(records, {
90
+ where: { age: { _lt: 25 } }
91
+ });
92
+ expect(result.entities).toEqual([records[3]]);
93
+ expect(result.entitiesAcrossPages).toEqual([records[3]]);
94
+ expect(result.entityCount).toBe(1);
95
+ });
96
+
97
+ it("should filter by _lte", () => {
98
+ const result = filterLocalEntitiesToHasura(records, {
99
+ where: { age: { _lte: 25 } }
100
+ });
101
+ expect(result.entities).toEqual([records[1], records[3]]);
102
+ expect(result.entitiesAcrossPages).toEqual([records[1], records[3]]);
103
+ expect(result.entityCount).toBe(2);
104
+ });
105
+
106
+ it("should filter by _like", () => {
107
+ const result = filterLocalEntitiesToHasura(records, {
108
+ where: { name: { _like: "%John%" } }
109
+ });
110
+ expect(result.entities).toEqual([records[0], records[2]]);
111
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
112
+ expect(result.entityCount).toBe(2);
113
+ });
114
+
115
+ it("should filter by _ilike", () => {
116
+ const result = filterLocalEntitiesToHasura(records, {
117
+ where: { name: { _ilike: "%john%" } }
118
+ });
119
+ expect(result.entities).toEqual([records[0], records[2]]);
120
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
121
+ expect(result.entityCount).toBe(2);
122
+ });
123
+
124
+ it("should filter by _nlike", () => {
125
+ const result = filterLocalEntitiesToHasura(records, {
126
+ where: { name: { _nlike: "%John%" } }
127
+ });
128
+ expect(result.entities).toEqual([records[1], records[3]]);
129
+ expect(result.entitiesAcrossPages).toEqual([records[1], records[3]]);
130
+ expect(result.entityCount).toBe(2);
131
+ });
132
+
133
+ it("should filter by _nilike", () => {
134
+ const result = filterLocalEntitiesToHasura(records, {
135
+ where: { name: { _nilike: "%john%" } }
136
+ });
137
+ expect(result.entities).toEqual([records[1], records[3]]);
138
+ expect(result.entitiesAcrossPages).toEqual([records[1], records[3]]);
139
+ expect(result.entityCount).toBe(2);
140
+ });
141
+
142
+ it("should filter by _starts_with", () => {
143
+ const result = filterLocalEntitiesToHasura(records, {
144
+ where: { name: { _starts_with: "John" } }
145
+ });
146
+ expect(result.entities).toEqual([records[0]]);
147
+ expect(result.entitiesAcrossPages).toEqual([records[0]]);
148
+ expect(result.entityCount).toBe(1);
149
+ });
150
+
151
+ it("should filter by _ends_with", () => {
152
+ const result = filterLocalEntitiesToHasura(records, {
153
+ where: { name: { _ends_with: "Doe" } }
154
+ });
155
+ expect(result.entities).toEqual([records[0]]);
156
+ expect(result.entitiesAcrossPages).toEqual([records[0]]);
157
+ expect(result.entityCount).toBe(1);
158
+ });
159
+
160
+ it("should filter by _is_null", () => {
161
+ const result = filterLocalEntitiesToHasura(records, {
162
+ where: { email: { _is_null: true } }
163
+ });
164
+ expect(result.entities).toEqual([records[1]]);
165
+ expect(result.entitiesAcrossPages).toEqual([records[1]]);
166
+ expect(result.entityCount).toBe(1);
167
+ });
168
+
169
+ it("should filter by _is_null false", () => {
170
+ const result = filterLocalEntitiesToHasura(records, {
171
+ where: { email: { _is_null: false } }
172
+ });
173
+ expect(result.entities).toEqual([records[0], records[2], records[3]]);
174
+ expect(result.entitiesAcrossPages).toEqual([
175
+ records[0],
176
+ records[2],
177
+ records[3]
178
+ ]);
179
+ expect(result.entityCount).toBe(3);
180
+ });
181
+
182
+ it("should filter by _and", () => {
183
+ const result = filterLocalEntitiesToHasura(records, {
184
+ where: {
185
+ _and: [{ age: { _gt: 25 } }, { city: { _eq: "London" } }]
186
+ }
187
+ });
188
+ expect(result.entities).toEqual([records[0], records[2]]);
189
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
190
+ expect(result.entityCount).toBe(2);
191
+ });
192
+
193
+ it("should filter by _or", () => {
194
+ const result = filterLocalEntitiesToHasura(records, {
195
+ where: {
196
+ _or: [{ city: { _eq: "London" } }, { city: { _eq: "Paris" } }]
197
+ }
198
+ });
199
+ expect(result.entities).toEqual([records[0], records[1], records[2]]);
200
+ expect(result.entitiesAcrossPages).toEqual([
201
+ records[0],
202
+ records[1],
203
+ records[2]
204
+ ]);
205
+ expect(result.entityCount).toBe(3);
206
+ });
207
+
208
+ it("should filter by _not", () => {
209
+ const result = filterLocalEntitiesToHasura(records, {
210
+ where: {
211
+ _not: { is_active: { _eq: true } }
212
+ }
213
+ });
214
+ expect(result.entities).toEqual([records[1], records[3]]);
215
+ expect(result.entitiesAcrossPages).toEqual([records[1], records[3]]);
216
+ expect(result.entityCount).toBe(2);
217
+ });
218
+
219
+ it("should filter by _contains", () => {
220
+ const result = filterLocalEntitiesToHasura(records, {
221
+ where: {
222
+ tags: { _contains: ["programming", "javascript"] }
223
+ }
224
+ });
225
+ expect(result.entities).toEqual([records[0]]);
226
+ expect(result.entitiesAcrossPages).toEqual([records[0]]);
227
+ expect(result.entityCount).toBe(1);
228
+ });
229
+
230
+ it("should filter by _contained_in", () => {
231
+ const result = filterLocalEntitiesToHasura(records, {
232
+ where: {
233
+ tags: { _contained_in: ["programming", "javascript", "python", "java"] }
234
+ }
235
+ });
236
+ expect(result.entities).toEqual(records);
237
+ expect(result.entitiesAcrossPages).toEqual(records);
238
+ expect(result.entityCount).toBe(4);
239
+ });
240
+
241
+ it("should filter by _has_key", () => {
242
+ const result = filterLocalEntitiesToHasura(records, {
243
+ where: { data: { _has_key: "category" } }
244
+ });
245
+ expect(result.entities).toEqual(records);
246
+ expect(result.entitiesAcrossPages).toEqual(records);
247
+ expect(result.entityCount).toBe(4);
248
+ });
249
+
250
+ it("should filter by _has_keys_any", () => {
251
+ const result = filterLocalEntitiesToHasura(records, {
252
+ where: {
253
+ data: { _has_keys_any: ["category", "missingKey"] }
254
+ }
255
+ });
256
+ expect(result.entities).toEqual(records);
257
+ expect(result.entitiesAcrossPages).toEqual(records);
258
+ expect(result.entityCount).toBe(4);
259
+ });
260
+
261
+ it("should filter by _has_keys_all", () => {
262
+ const result = filterLocalEntitiesToHasura(records, {
263
+ where: {
264
+ data: { _has_keys_all: ["category", "type"] }
265
+ }
266
+ });
267
+ expect(result.entities).toEqual(records);
268
+ expect(result.entitiesAcrossPages).toEqual(records);
269
+ expect(result.entityCount).toBe(4);
270
+ });
271
+
272
+ it("should filter by _similar", () => {
273
+ const result = filterLocalEntitiesToHasura(records, {
274
+ where: {
275
+ username: { _similar: "(john|alice)%" }
276
+ }
277
+ });
278
+ expect(result.entities).toEqual([records[0], records[2]]);
279
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
280
+ expect(result.entityCount).toBe(2);
281
+ });
282
+
283
+ it("should filter by range _gte and _lte", () => {
284
+ const result = filterLocalEntitiesToHasura(records, {
285
+ where: { age: { _gte: 25, _lte: 30 } }
286
+ });
287
+ expect(result.entities).toEqual([records[0], records[1]]);
288
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[1]]);
289
+ expect(result.entityCount).toBe(2);
290
+ });
291
+
292
+ it("should filter by range _gt and _lt", () => {
293
+ const result = filterLocalEntitiesToHasura(records, {
294
+ where: { age: { _gt: 25, _lt: 35 } }
295
+ });
296
+ expect(result.entities).toEqual([records[0]]);
297
+ expect(result.entitiesAcrossPages).toEqual([records[0]]);
298
+ expect(result.entityCount).toBe(1);
299
+ });
300
+
301
+ it("should handle empty where clause", () => {
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
+ });
311
+ expect(result.entities).toEqual(records);
312
+ expect(result.entitiesAcrossPages).toEqual(records);
313
+ expect(result.entityCount).toBe(4);
314
+ });
315
+
316
+ it("should handle nested _and and _or", () => {
317
+ const result = filterLocalEntitiesToHasura(records, {
318
+ where: {
319
+ _and: [
320
+ { _or: [{ city: { _eq: "London" } }, { city: { _eq: "Paris" } }] },
321
+ { age: { _gt: 20 } }
322
+ ]
323
+ }
324
+ });
325
+ expect(result.entities).toEqual([records[0], records[1], records[2]]);
326
+ expect(result.entitiesAcrossPages).toEqual([
327
+ records[0],
328
+ records[1],
329
+ records[2]
330
+ ]);
331
+ expect(result.entityCount).toBe(3);
332
+ });
333
+ it("should order by age ascending", () => {
334
+ const result = filterLocalEntitiesToHasura(records, {
335
+ order_by: { age: "asc" }
336
+ });
337
+ expect(result.entities).toEqual([
338
+ records[3],
339
+ records[1],
340
+ records[0],
341
+ records[2]
342
+ ]);
343
+ expect(result.entitiesAcrossPages).toEqual([
344
+ records[3],
345
+ records[1],
346
+ records[0],
347
+ records[2]
348
+ ]);
349
+ expect(result.entityCount).toBe(4);
350
+ });
351
+
352
+ it("should order by age descending", () => {
353
+ const result = filterLocalEntitiesToHasura(records, {
354
+ order_by: { age: "desc" }
355
+ });
356
+ expect(result.entities).toEqual([
357
+ records[2],
358
+ records[0],
359
+ records[1],
360
+ records[3]
361
+ ]);
362
+ expect(result.entitiesAcrossPages).toEqual([
363
+ records[2],
364
+ records[0],
365
+ records[1],
366
+ records[3]
367
+ ]);
368
+ expect(result.entityCount).toBe(4);
369
+ });
370
+
371
+ it("should order by name ascending", () => {
372
+ const result = filterLocalEntitiesToHasura(records, {
373
+ order_by: { name: "asc" }
374
+ });
375
+ expect(result.entities).toEqual([
376
+ records[2],
377
+ records[3],
378
+ records[1],
379
+ records[0]
380
+ ]);
381
+ expect(result.entitiesAcrossPages).toEqual([
382
+ records[2],
383
+ records[3],
384
+ records[1],
385
+ records[0]
386
+ ]);
387
+ expect(result.entityCount).toBe(4);
388
+ });
389
+
390
+ it("should order by name descending", () => {
391
+ const result = filterLocalEntitiesToHasura(records, {
392
+ order_by: { name: "desc" }
393
+ });
394
+ expect(result.entities).toEqual([
395
+ records[0],
396
+ records[1],
397
+ records[3],
398
+ records[2]
399
+ ]);
400
+ expect(result.entitiesAcrossPages).toEqual([
401
+ records[0],
402
+ records[1],
403
+ records[3],
404
+ records[2]
405
+ ]);
406
+ expect(result.entityCount).toBe(4);
407
+ });
408
+
409
+ it("should filter and order", () => {
410
+ const result = filterLocalEntitiesToHasura(records, {
411
+ where: { city: { _eq: "London" } },
412
+ order_by: { age: "desc" }
413
+ });
414
+ expect(result.entities).toEqual([records[2], records[0]]);
415
+ expect(result.entitiesAcrossPages).toEqual([records[2], records[0]]);
416
+ expect(result.entityCount).toBe(2);
417
+ });
418
+
419
+ it("should handle empty order_by", () => {
420
+ const result = filterLocalEntitiesToHasura(records, {
421
+ where: { city: { _eq: "London" } }
422
+ });
423
+ expect(result.entities).toEqual([records[0], records[2]]);
424
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
425
+ expect(result.entityCount).toBe(2);
426
+ });
427
+
428
+ it("should handle order_by with empty where", () => {
429
+ const result = filterLocalEntitiesToHasura(records, {
430
+ order_by: { age: "asc" }
431
+ });
432
+ expect(result.entities).toEqual([
433
+ records[3],
434
+ records[1],
435
+ records[0],
436
+ records[2]
437
+ ]);
438
+ expect(result.entitiesAcrossPages).toEqual([
439
+ records[3],
440
+ records[1],
441
+ records[0],
442
+ records[2]
443
+ ]);
444
+ expect(result.entityCount).toBe(4);
445
+ });
446
+
447
+ it("should apply limit", () => {
448
+ const result = filterLocalEntitiesToHasura(records, { limit: 2 });
449
+ expect(result.entities).toEqual([records[0], records[1]]);
450
+ expect(result.entitiesAcrossPages).toEqual(records);
451
+ expect(result.entityCount).toBe(4);
452
+ });
453
+
454
+ it("should apply offset", () => {
455
+ const result = filterLocalEntitiesToHasura(records, { offset: 2 });
456
+ expect(result.entities).toEqual([records[2], records[3]]);
457
+ expect(result.entitiesAcrossPages).toEqual(records);
458
+ expect(result.entityCount).toBe(4);
459
+ });
460
+
461
+ it("should apply limit and offset", () => {
462
+ const result = filterLocalEntitiesToHasura(records, {
463
+ limit: 1,
464
+ offset: 2
465
+ });
466
+ expect(result.entities).toEqual([records[2]]);
467
+ expect(result.entitiesAcrossPages).toEqual(records);
468
+ expect(result.entityCount).toBe(4);
469
+ });
470
+
471
+ it("should apply limit to filtered results", () => {
472
+ const result = filterLocalEntitiesToHasura(records, {
473
+ where: { city: { _eq: "London" } },
474
+ limit: 1
475
+ });
476
+ expect(result.entities).toEqual([records[0]]);
477
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
478
+ expect(result.entityCount).toBe(2);
479
+ });
480
+
481
+ it("should apply offset to filtered results", () => {
482
+ const result = filterLocalEntitiesToHasura(records, {
483
+ where: { city: { _eq: "London" } },
484
+ offset: 1
485
+ });
486
+ expect(result.entities).toEqual([records[2]]);
487
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
488
+ expect(result.entityCount).toBe(2);
489
+ });
490
+
491
+ it("should apply limit and offset to filtered and ordered results", () => {
492
+ const result = filterLocalEntitiesToHasura(records, {
493
+ where: { city: { _eq: "London" } },
494
+ order_by: { age: "desc" },
495
+ limit: 1,
496
+ offset: 1
497
+ });
498
+ expect(result.entities).toEqual([records[0]]);
499
+ expect(result.entitiesAcrossPages).toEqual([records[2], records[0]]);
500
+ expect(result.entityCount).toBe(2);
501
+ });
502
+
503
+ it("should handle offset greater than array length", () => {
504
+ const result = filterLocalEntitiesToHasura(records, { offset: 10 });
505
+ expect(result.entities).toEqual([]);
506
+ expect(result.entitiesAcrossPages).toEqual(records);
507
+ expect(result.entityCount).toBe(4);
508
+ });
509
+
510
+ it("should handle limit greater than array length", () => {
511
+ const result = filterLocalEntitiesToHasura(records, { limit: 10 });
512
+ expect(result.entities).toEqual(records);
513
+ expect(result.entitiesAcrossPages).toEqual(records);
514
+ expect(result.entityCount).toBe(4);
515
+ });
516
+
517
+ it("should handle isInfinite option with filtering", () => {
518
+ const result = filterLocalEntitiesToHasura(records, {
519
+ where: { city: { _eq: "London" } },
520
+ isInfinite: true
521
+ });
522
+ expect(result.entities).toEqual([records[0], records[2]]);
523
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
524
+ expect(result.entityCount).toBe(2);
525
+ });
526
+
527
+ it("should handle isInfinite option with filtering, limit, and offset", () => {
528
+ const result = filterLocalEntitiesToHasura(records, {
529
+ where: { city: { _eq: "London" } },
530
+ limit: 1,
531
+ offset: 1,
532
+ isInfinite: true
533
+ });
534
+ expect(result.entities).toEqual([records[0], records[2]]);
535
+ expect(result.entitiesAcrossPages).toEqual([records[0], records[2]]);
536
+ expect(result.entityCount).toBe(2);
537
+ });
538
+ });
@@ -0,0 +1,55 @@
1
+ import { isEntityClean } from "./isEntityClean";
2
+ import { getSelectedRowsFromEntities } from "./selection";
3
+ import { removeCleanRows } from "./removeCleanRows";
4
+ import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
5
+ import { getRecordsFromIdMap } from "./withSelectedEntities";
6
+ import { formatPasteData } from "./formatPasteData";
7
+ import { getFieldPathToField } from "./getFieldPathToField";
8
+ import {
9
+ defaultParsePaste,
10
+ getEntityIdToEntity,
11
+ getFieldPathToIndex,
12
+ getNumberStrAtEnd,
13
+ stripNumberAtEnd
14
+ } from "./utils";
15
+ import { getAllRows } from "./getAllRows";
16
+ import { getNewEntToSelect } from "./getNewEntToSelect";
17
+ import { getLastSelectedEntity } from "./getLastSelectedEntity";
18
+ import { getCellInfo } from "./getCellInfo";
19
+ import { getCellCopyText } from "./getCellCopyText";
20
+ import { getRowCopyText } from "./getRowCopyText";
21
+ import { handleCopyHelper } from "./handleCopyHelper";
22
+ import { handleCopyRows } from "./handleCopyRows";
23
+ import { handleCopyColumn } from "./handleCopyColumn";
24
+ import { isBottomRightCornerOfRectangle } from "./isBottomRightCornerOfRectangle";
25
+ import { handleCopyTable } from "./handleCopyTable";
26
+ import { PRIMARY_SELECTED_VAL } from "./primarySelectedValue";
27
+ import { useTableEntities } from "./useTableEntities";
28
+
29
+ export {
30
+ defaultParsePaste,
31
+ formatPasteData,
32
+ getAllRows,
33
+ getCellCopyText,
34
+ getCellInfo,
35
+ getEntityIdToEntity,
36
+ getFieldPathToIndex,
37
+ getFieldPathToField,
38
+ getIdOrCodeOrIndex,
39
+ getLastSelectedEntity,
40
+ getNewEntToSelect,
41
+ getNumberStrAtEnd,
42
+ getRecordsFromIdMap,
43
+ getRowCopyText,
44
+ getSelectedRowsFromEntities,
45
+ handleCopyColumn,
46
+ handleCopyHelper,
47
+ handleCopyRows,
48
+ handleCopyTable,
49
+ isBottomRightCornerOfRectangle,
50
+ isEntityClean,
51
+ PRIMARY_SELECTED_VAL,
52
+ removeCleanRows,
53
+ stripNumberAtEnd,
54
+ useTableEntities
55
+ };
@@ -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,