@kaspernj/api-maker 1.0.2054 → 1.0.2055

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 (381) hide show
  1. package/build/api.js +64 -212
  2. package/build/api.js.map +1 -1
  3. package/build/attribute-not-loaded-error.js +2 -25
  4. package/build/attribute-not-loaded-error.js.map +1 -1
  5. package/build/base-component.js +3 -26
  6. package/build/base-component.js.map +1 -1
  7. package/build/base-error.js +20 -45
  8. package/build/base-error.js.map +1 -1
  9. package/build/base-model/attribute.js +14 -21
  10. package/build/base-model/attribute.js.map +1 -1
  11. package/build/base-model/column.js +4 -8
  12. package/build/base-model/column.js.map +1 -1
  13. package/build/base-model/reflection.js +11 -51
  14. package/build/base-model/reflection.js.map +1 -1
  15. package/build/base-model/scope.js +8 -45
  16. package/build/base-model/scope.js.map +1 -1
  17. package/build/base-model.js +583 -836
  18. package/build/base-model.js.map +1 -1
  19. package/build/bootstrap/attribute-row.js +87 -172
  20. package/build/bootstrap/attribute-row.js.map +1 -1
  21. package/build/bootstrap/attribute-rows.js +21 -50
  22. package/build/bootstrap/attribute-rows.js.map +1 -1
  23. package/build/bootstrap/card.js +76 -159
  24. package/build/bootstrap/card.js.map +1 -1
  25. package/build/bootstrap/checkbox.js +53 -102
  26. package/build/bootstrap/checkbox.js.map +1 -1
  27. package/build/bootstrap/checkboxes.js +116 -202
  28. package/build/bootstrap/checkboxes.js.map +1 -1
  29. package/build/bootstrap/input.js +80 -131
  30. package/build/bootstrap/input.js.map +1 -1
  31. package/build/bootstrap/invalid-feedback.js +18 -46
  32. package/build/bootstrap/invalid-feedback.js.map +1 -1
  33. package/build/bootstrap/paginate.js +99 -164
  34. package/build/bootstrap/paginate.js.map +1 -1
  35. package/build/bootstrap/radio-buttons.js +43 -80
  36. package/build/bootstrap/radio-buttons.js.map +1 -1
  37. package/build/bootstrap/select.js +43 -90
  38. package/build/bootstrap/select.js.map +1 -1
  39. package/build/bootstrap/sort-link.js +68 -151
  40. package/build/bootstrap/sort-link.js.map +1 -1
  41. package/build/cable-connection-pool.js +43 -65
  42. package/build/cable-connection-pool.js.map +1 -1
  43. package/build/cable-subscription-pool.js +104 -161
  44. package/build/cable-subscription-pool.js.map +1 -1
  45. package/build/cable-subscription.js +9 -16
  46. package/build/cable-subscription.js.map +1 -1
  47. package/build/cache-key-generator.js +27 -36
  48. package/build/cache-key-generator.js.map +1 -1
  49. package/build/can-can.js +80 -201
  50. package/build/can-can.js.map +1 -1
  51. package/build/channels-consumer.js +5 -10
  52. package/build/channels-consumer.js.map +1 -1
  53. package/build/collection-loader.js +35 -53
  54. package/build/collection-loader.js.map +1 -1
  55. package/build/collection.js +160 -307
  56. package/build/collection.js.map +1 -1
  57. package/build/command-submit-data.d.ts +1 -1
  58. package/build/command-submit-data.d.ts.map +1 -1
  59. package/build/command-submit-data.js +29 -38
  60. package/build/command-submit-data.js.map +1 -1
  61. package/build/commands-pool.js +139 -215
  62. package/build/commands-pool.js.map +1 -1
  63. package/build/compose.js +3 -11
  64. package/build/compose.js.map +1 -1
  65. package/build/config.js +20 -67
  66. package/build/config.js.map +1 -1
  67. package/build/custom-error.js +4 -29
  68. package/build/custom-error.js.map +1 -1
  69. package/build/data-set-to-attributes.js +5 -41
  70. package/build/data-set-to-attributes.js.map +1 -1
  71. package/build/deserializer.js +26 -79
  72. package/build/deserializer.js.map +1 -1
  73. package/build/destroy-error.js +4 -29
  74. package/build/destroy-error.js.map +1 -1
  75. package/build/devise.js +83 -187
  76. package/build/devise.js.map +1 -1
  77. package/build/draggable-sort/controller.js +87 -110
  78. package/build/draggable-sort/controller.js.map +1 -1
  79. package/build/draggable-sort/index.js +67 -144
  80. package/build/draggable-sort/index.js.map +1 -1
  81. package/build/draggable-sort/item.js +131 -197
  82. package/build/draggable-sort/item.js.map +1 -1
  83. package/build/error-logger.js +78 -163
  84. package/build/error-logger.js.map +1 -1
  85. package/build/error-messages.js +4 -7
  86. package/build/error-messages.js.map +1 -1
  87. package/build/event-connection.js +23 -61
  88. package/build/event-connection.js.map +1 -1
  89. package/build/event-emitter-listener.js +6 -23
  90. package/build/event-emitter-listener.js.map +1 -1
  91. package/build/event-model-class.js +19 -46
  92. package/build/event-model-class.js.map +1 -1
  93. package/build/events.js +3 -8
  94. package/build/events.js.map +1 -1
  95. package/build/form.js +65 -153
  96. package/build/form.js.map +1 -1
  97. package/build/history-expo.js +12 -24
  98. package/build/history-expo.js.map +1 -1
  99. package/build/history-react-native.js +14 -26
  100. package/build/history-react-native.js.map +1 -1
  101. package/build/history.js +2 -4
  102. package/build/history.js.map +1 -1
  103. package/build/index.js +2 -5
  104. package/build/index.js.map +1 -1
  105. package/build/inputs/attachment.js +71 -122
  106. package/build/inputs/attachment.js.map +1 -1
  107. package/build/inputs/auto-submit.js +15 -54
  108. package/build/inputs/auto-submit.js.map +1 -1
  109. package/build/inputs/checkbox.js +77 -166
  110. package/build/inputs/checkbox.js.map +1 -1
  111. package/build/inputs/checkboxes.js +75 -158
  112. package/build/inputs/checkboxes.js.map +1 -1
  113. package/build/inputs/id-for-component.js +4 -40
  114. package/build/inputs/id-for-component.js.map +1 -1
  115. package/build/inputs/input-wrapper.js +7 -26
  116. package/build/inputs/input-wrapper.js.map +1 -1
  117. package/build/inputs/input.js +158 -244
  118. package/build/inputs/input.js.map +1 -1
  119. package/build/inputs/money.js +123 -185
  120. package/build/inputs/money.js.map +1 -1
  121. package/build/inputs/name-for-component.js +4 -40
  122. package/build/inputs/name-for-component.js.map +1 -1
  123. package/build/inputs/select.js +68 -122
  124. package/build/inputs/select.js.map +1 -1
  125. package/build/instance-of-class-name.js +15 -20
  126. package/build/instance-of-class-name.js.map +1 -1
  127. package/build/is-expo.js +8 -10
  128. package/build/is-expo.js.map +1 -1
  129. package/build/key-value-store.js +51 -127
  130. package/build/key-value-store.js.map +1 -1
  131. package/build/link.js +51 -114
  132. package/build/link.js.map +1 -1
  133. package/build/logger.js +19 -25
  134. package/build/logger.js.map +1 -1
  135. package/build/merge-styles.js +5 -9
  136. package/build/merge-styles.js.map +1 -1
  137. package/build/modal.js +14 -61
  138. package/build/modal.js.map +1 -1
  139. package/build/model-class-require.js +8 -43
  140. package/build/model-class-require.js.map +1 -1
  141. package/build/model-events.js +24 -33
  142. package/build/model-events.js.map +1 -1
  143. package/build/model-name.js +15 -56
  144. package/build/model-name.js.map +1 -1
  145. package/build/model-prop-type.js +51 -62
  146. package/build/model-prop-type.js.map +1 -1
  147. package/build/model-recipes-loader.js +16 -24
  148. package/build/model-recipes-loader.js.map +1 -1
  149. package/build/model-recipes-model-loader.d.ts +1 -1
  150. package/build/model-recipes-model-loader.js +129 -207
  151. package/build/model-recipes-model-loader.js.map +1 -1
  152. package/build/models-response-reader.js +24 -65
  153. package/build/models-response-reader.js.map +1 -1
  154. package/build/models.js +5 -10
  155. package/build/models.js.map +1 -1
  156. package/build/money-formatter.d.ts +2 -2
  157. package/build/money-formatter.d.ts.map +1 -1
  158. package/build/money-formatter.js +45 -55
  159. package/build/money-formatter.js.map +1 -1
  160. package/build/not-loaded-error.js +2 -25
  161. package/build/not-loaded-error.js.map +1 -1
  162. package/build/params.js +31 -41
  163. package/build/params.js.map +1 -1
  164. package/build/preloaded.js +18 -58
  165. package/build/preloaded.js.map +1 -1
  166. package/build/resize-observer.js +5 -11
  167. package/build/resize-observer.js.map +1 -1
  168. package/build/rest-props-validator.js +4 -6
  169. package/build/rest-props-validator.js.map +1 -1
  170. package/build/result.js +10 -14
  171. package/build/result.js.map +1 -1
  172. package/build/router/route.js +178 -311
  173. package/build/router/route.js.map +1 -1
  174. package/build/router/switch.js +55 -129
  175. package/build/router/switch.js.map +1 -1
  176. package/build/router.js +33 -93
  177. package/build/router.js.map +1 -1
  178. package/build/routes-native.js +63 -147
  179. package/build/routes-native.js.map +1 -1
  180. package/build/routes.js +25 -79
  181. package/build/routes.js.map +1 -1
  182. package/build/run-last.js +19 -24
  183. package/build/run-last.js.map +1 -1
  184. package/build/serializer.js +28 -33
  185. package/build/serializer.js.map +1 -1
  186. package/build/services.js +9 -18
  187. package/build/services.js.map +1 -1
  188. package/build/session-status-updater.js +84 -183
  189. package/build/session-status-updater.js.map +1 -1
  190. package/build/source-maps-loader.d.ts +37 -0
  191. package/build/source-maps-loader.d.ts.map +1 -0
  192. package/build/source-maps-loader.js +102 -224
  193. package/build/source-maps-loader.js.map +1 -1
  194. package/build/super-admin/config-reader.d.ts +2 -2
  195. package/build/super-admin/config-reader.js +41 -82
  196. package/build/super-admin/config-reader.js.map +1 -1
  197. package/build/super-admin/edit-page/edit-attribute-checkbox.js +52 -114
  198. package/build/super-admin/edit-page/edit-attribute-checkbox.js.map +1 -1
  199. package/build/super-admin/edit-page/edit-attribute-content.js +46 -76
  200. package/build/super-admin/edit-page/edit-attribute-content.js.map +1 -1
  201. package/build/super-admin/edit-page/edit-attribute-input.js +56 -118
  202. package/build/super-admin/edit-page/edit-attribute-input.js.map +1 -1
  203. package/build/super-admin/edit-page/edit-attribute.js +39 -103
  204. package/build/super-admin/edit-page/edit-attribute.js.map +1 -1
  205. package/build/super-admin/edit-page.js +87 -200
  206. package/build/super-admin/edit-page.js.map +1 -1
  207. package/build/super-admin/has-edit-config.js +6 -12
  208. package/build/super-admin/has-edit-config.js.map +1 -1
  209. package/build/super-admin/index-page.js +16 -43
  210. package/build/super-admin/index-page.js.map +1 -1
  211. package/build/super-admin/index.js +86 -209
  212. package/build/super-admin/index.js.map +1 -1
  213. package/build/super-admin/layout/header/index.js +90 -151
  214. package/build/super-admin/layout/header/index.js.map +1 -1
  215. package/build/super-admin/layout/index.js +69 -152
  216. package/build/super-admin/layout/index.js.map +1 -1
  217. package/build/super-admin/layout/menu/index.js +84 -160
  218. package/build/super-admin/layout/menu/index.js.map +1 -1
  219. package/build/super-admin/layout/menu/menu-content.js +24 -84
  220. package/build/super-admin/layout/menu/menu-content.js.map +1 -1
  221. package/build/super-admin/layout/menu/menu-item.js +51 -101
  222. package/build/super-admin/layout/menu/menu-item.js.map +1 -1
  223. package/build/super-admin/layout/no-access.js +18 -44
  224. package/build/super-admin/layout/no-access.js.map +1 -1
  225. package/build/super-admin/model-class-table.js +44 -128
  226. package/build/super-admin/model-class-table.js.map +1 -1
  227. package/build/super-admin/models.js +5 -41
  228. package/build/super-admin/models.js.map +1 -1
  229. package/build/super-admin/show-nav.js +26 -88
  230. package/build/super-admin/show-nav.js.map +1 -1
  231. package/build/super-admin/show-page/belongs-to-attribute-row.js +17 -75
  232. package/build/super-admin/show-page/belongs-to-attribute-row.js.map +1 -1
  233. package/build/super-admin/show-page/index.js +100 -186
  234. package/build/super-admin/show-page/index.js.map +1 -1
  235. package/build/super-admin/show-reflection-actions.js +38 -99
  236. package/build/super-admin/show-reflection-actions.js.map +1 -1
  237. package/build/super-admin/show-reflection-link.js +26 -98
  238. package/build/super-admin/show-reflection-link.js.map +1 -1
  239. package/build/super-admin/show-reflection-page.js +33 -96
  240. package/build/super-admin/show-reflection-page.js.map +1 -1
  241. package/build/table/column-content.js +76 -120
  242. package/build/table/column-content.js.map +1 -1
  243. package/build/table/column-identifier.js +6 -10
  244. package/build/table/column-identifier.js.map +1 -1
  245. package/build/table/column-visible.js +1 -4
  246. package/build/table/column-visible.js.map +1 -1
  247. package/build/table/components/column.js +12 -59
  248. package/build/table/components/column.js.map +1 -1
  249. package/build/table/components/flat-list.js +12 -59
  250. package/build/table/components/flat-list.js.map +1 -1
  251. package/build/table/components/header.js +14 -61
  252. package/build/table/components/header.js.map +1 -1
  253. package/build/table/components/row.js +15 -62
  254. package/build/table/components/row.js.map +1 -1
  255. package/build/table/filters/attribute-element.js +33 -61
  256. package/build/table/filters/attribute-element.js.map +1 -1
  257. package/build/table/filters/filter-form.js +279 -482
  258. package/build/table/filters/filter-form.js.map +1 -1
  259. package/build/table/filters/filter.js +44 -72
  260. package/build/table/filters/filter.js.map +1 -1
  261. package/build/table/filters/index.js +94 -138
  262. package/build/table/filters/index.js.map +1 -1
  263. package/build/table/filters/load-search-modal.js +63 -211
  264. package/build/table/filters/load-search-modal.js.map +1 -1
  265. package/build/table/filters/reflection-element.js +26 -54
  266. package/build/table/filters/reflection-element.js.map +1 -1
  267. package/build/table/filters/save-search-modal.js +43 -139
  268. package/build/table/filters/save-search-modal.js.map +1 -1
  269. package/build/table/filters/scope-element.js +27 -55
  270. package/build/table/filters/scope-element.js.map +1 -1
  271. package/build/table/header-column-content.js +32 -70
  272. package/build/table/header-column-content.js.map +1 -1
  273. package/build/table/header-column.js +88 -217
  274. package/build/table/header-column.js.map +1 -1
  275. package/build/table/header-select.js +44 -76
  276. package/build/table/header-select.js.map +1 -1
  277. package/build/table/model-callback-args.js +4 -40
  278. package/build/table/model-callback-args.js.map +1 -1
  279. package/build/table/model-column.js +58 -143
  280. package/build/table/model-column.js.map +1 -1
  281. package/build/table/model-row.js +74 -186
  282. package/build/table/model-row.js.map +1 -1
  283. package/build/table/select-calculator.js +26 -85
  284. package/build/table/select-calculator.js.map +1 -1
  285. package/build/table/settings/column-row.js +65 -185
  286. package/build/table/settings/column-row.js.map +1 -1
  287. package/build/table/settings/download-action.js +37 -73
  288. package/build/table/settings/download-action.js.map +1 -1
  289. package/build/table/settings/index.js +37 -101
  290. package/build/table/settings/index.js.map +1 -1
  291. package/build/table/table-settings.js +184 -322
  292. package/build/table/table-settings.js.map +1 -1
  293. package/build/table/table.js +582 -780
  294. package/build/table/table.js.map +1 -1
  295. package/build/table/use-sorting.js +15 -34
  296. package/build/table/use-sorting.js.map +1 -1
  297. package/build/table/widths.js +31 -37
  298. package/build/table/widths.js.map +1 -1
  299. package/build/table/worker-plugins-check-all-checkbox.js +76 -224
  300. package/build/table/worker-plugins-check-all-checkbox.js.map +1 -1
  301. package/build/table/worker-plugins-checkbox.js +73 -184
  302. package/build/table/worker-plugins-checkbox.js.map +1 -1
  303. package/build/translated-attributes.js +5 -10
  304. package/build/translated-attributes.js.map +1 -1
  305. package/build/translated-collections.js +10 -19
  306. package/build/translated-collections.js.map +1 -1
  307. package/build/updated-attribute.js +46 -119
  308. package/build/updated-attribute.js.map +1 -1
  309. package/build/url-encode.js +5 -11
  310. package/build/url-encode.js.map +1 -1
  311. package/build/use-breakpoint.js +42 -94
  312. package/build/use-breakpoint.js.map +1 -1
  313. package/build/use-can-can.js +29 -91
  314. package/build/use-can-can.js.map +1 -1
  315. package/build/use-collection.js +118 -228
  316. package/build/use-collection.js.map +1 -1
  317. package/build/use-created-event.js +26 -43
  318. package/build/use-created-event.js.map +1 -1
  319. package/build/use-current-user-context.js +56 -150
  320. package/build/use-current-user-context.js.map +1 -1
  321. package/build/use-current-user.js +13 -31
  322. package/build/use-current-user.js.map +1 -1
  323. package/build/use-destroyed-event.js +21 -42
  324. package/build/use-destroyed-event.js.map +1 -1
  325. package/build/use-event-emitter.js +9 -14
  326. package/build/use-event-emitter.js.map +1 -1
  327. package/build/use-event-listener.js +12 -21
  328. package/build/use-event-listener.js.map +1 -1
  329. package/build/use-input.js +48 -68
  330. package/build/use-input.js.map +1 -1
  331. package/build/use-model-event.js +21 -42
  332. package/build/use-model-event.js.map +1 -1
  333. package/build/use-model.js +95 -198
  334. package/build/use-model.js.map +1 -1
  335. package/build/use-resize-observer.js +10 -20
  336. package/build/use-resize-observer.js.map +1 -1
  337. package/build/use-router.js +64 -106
  338. package/build/use-router.js.map +1 -1
  339. package/build/use-screen-layout.js +16 -18
  340. package/build/use-screen-layout.js.map +1 -1
  341. package/build/use-styles.js +23 -74
  342. package/build/use-styles.js.map +1 -1
  343. package/build/use-updated-event.js +21 -43
  344. package/build/use-updated-event.js.map +1 -1
  345. package/build/use-validation-errors.js +11 -17
  346. package/build/use-validation-errors.js.map +1 -1
  347. package/build/utils/button.js +85 -135
  348. package/build/utils/button.js.map +1 -1
  349. package/build/utils/card.js +30 -105
  350. package/build/utils/card.js.map +1 -1
  351. package/build/utils/checkbox.js +50 -111
  352. package/build/utils/checkbox.js.map +1 -1
  353. package/build/utils/checkboxes.js +108 -181
  354. package/build/utils/checkboxes.js.map +1 -1
  355. package/build/utils/default-style.js +28 -102
  356. package/build/utils/default-style.js.map +1 -1
  357. package/build/utils/header.js +7 -34
  358. package/build/utils/header.js.map +1 -1
  359. package/build/utils/icon.js +35 -116
  360. package/build/utils/icon.js.map +1 -1
  361. package/build/utils/invalid-feedback.js +15 -42
  362. package/build/utils/invalid-feedback.js.map +1 -1
  363. package/build/utils/modal.js +24 -107
  364. package/build/utils/modal.js.map +1 -1
  365. package/build/utils/text.js +9 -36
  366. package/build/utils/text.js.map +1 -1
  367. package/build/validation-error.js +30 -88
  368. package/build/validation-error.js.map +1 -1
  369. package/build/validation-errors.js +60 -110
  370. package/build/validation-errors.js.map +1 -1
  371. package/build/with-api-maker.js +14 -66
  372. package/build/with-api-maker.js.map +1 -1
  373. package/build/with-collection.js +13 -63
  374. package/build/with-collection.js.map +1 -1
  375. package/build/with-current-user.js +6 -22
  376. package/build/with-current-user.js.map +1 -1
  377. package/build/with-model.js +10 -26
  378. package/build/with-model.js.map +1 -1
  379. package/build/with-router.js +7 -34
  380. package/build/with-router.js.map +1 -1
  381. package/package.json +1 -1
@@ -1,493 +1,290 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || (function () {
34
- var ownKeys = function(o) {
35
- ownKeys = Object.getOwnPropertyNames || function (o) {
36
- var ar = [];
37
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
- return ar;
39
- };
40
- return ownKeys(o);
41
- };
42
- return function (mod) {
43
- if (mod && mod.__esModule) return mod;
44
- var result = {};
45
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
- __setModuleDefault(result, mod);
47
- return result;
48
- };
49
- })();
50
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
51
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
52
- return new (P || (P = Promise))(function (resolve, reject) {
53
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
54
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
55
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
56
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useRef } from "react";
3
+ import { ActivityIndicator, View } from "react-native";
4
+ import AttributeElement from "./attribute-element";
5
+ import BaseComponent from "../../base-component.js";
6
+ import Button from "../../utils/button";
7
+ import Card from "../../utils/card";
8
+ import { digg, digs } from "diggerize";
9
+ import * as inflection from "inflection";
10
+ import { Form } from "../../form";
11
+ import Header from "../../utils/header";
12
+ import Input from "../../inputs/input";
13
+ import memo from "set-state-compare/build/memo.js";
14
+ import Params from "../../params.js";
15
+ import PropTypes from "prop-types";
16
+ import PropTypesExact from "prop-types-exact";
17
+ import React from "react";
18
+ import ReflectionElement from "./reflection-element";
19
+ import ScopeElement from "./scope-element";
20
+ import Select from "../../inputs/select";
21
+ import Services from "../../services.js";
22
+ import { shapeComponent } from "set-state-compare/build/shape-component.js";
23
+ import Text from "../../utils/text";
24
+ import useBreakpoint from "../../use-breakpoint.js";
25
+ import useI18n from "i18n-on-steroids/src/use-i18n.mjs";
26
+ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends BaseComponent {
27
+ static propTypes = PropTypesExact({
28
+ filter: PropTypes.object,
29
+ modelClass: PropTypes.func.isRequired,
30
+ onApplyClicked: PropTypes.func.isRequired,
31
+ onRequestClose: PropTypes.func.isRequired,
32
+ querySearchName: PropTypes.string.isRequired
57
33
  });
58
- };
59
- var __generator = (this && this.__generator) || function (thisArg, body) {
60
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
61
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
62
- function verb(n) { return function (v) { return step([n, v]); }; }
63
- function step(op) {
64
- if (f) throw new TypeError("Generator is already executing.");
65
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
66
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
67
- if (y = 0, t) op = [op[0] & 2, t.value];
68
- switch (op[0]) {
69
- case 0: case 1: t = op; break;
70
- case 4: _.label++; return { value: op[1], done: false };
71
- case 5: _.label++; y = op[1]; op = [0]; continue;
72
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
73
- default:
74
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
75
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
76
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
77
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
78
- if (t[2]) _.ops.pop();
79
- _.trys.pop(); continue;
34
+ setup() {
35
+ const { t } = useI18n({ namespace: "js.api_maker.table.filters.filter_form" });
36
+ this.useStates({
37
+ associations: null,
38
+ attribute: undefined,
39
+ actualCurrentModelClass: () => ({ modelClass: this.p.modelClass }),
40
+ loading: 0,
41
+ modelClassName: digg(this.p.modelClass.modelClassData(), "className"),
42
+ path: [],
43
+ predicate: undefined,
44
+ predicates: undefined,
45
+ ransackableAttributes: undefined,
46
+ ransackableScopes: undefined,
47
+ scope: this.props.filter.sc,
48
+ value: this.props.filter.v
49
+ });
50
+ this.setInstance({
51
+ breakpoint: useBreakpoint(),
52
+ t,
53
+ valueInputRef: useRef(),
54
+ });
55
+ useMemo(() => {
56
+ this.loadRansackPredicates();
57
+ if (this.props.filter.v) {
58
+ this.loadInitialValuesWithLoadingIndicator();
80
59
  }
81
- op = body.call(thisArg, _);
82
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
83
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
60
+ }, []);
61
+ useMemo(() => {
62
+ this.loadAssociations();
63
+ }, [this.s.modelClassName]);
64
+ }
65
+ currentModelClass = () => digg(this.s.actualCurrentModelClass, "modelClass");
66
+ parseAssociationData(result) {
67
+ const associations = result.associations.map(({ human_name, model_class_name, reflection_name, resource }) => ({
68
+ humanName: human_name,
69
+ modelClassName: model_class_name,
70
+ reflectionName: inflection.camelize(reflection_name, true),
71
+ resource
72
+ }));
73
+ const ransackableAttributes = digg(result, "ransackable_attributes").map(({ attribute_name: attributeName, human_name: humanName }) => ({
74
+ attributeName, humanName
75
+ }));
76
+ const ransackableScopes = digg(result, "ransackable_scopes");
77
+ return { associations, ransackableAttributes, ransackableScopes };
84
78
  }
85
- };
86
- var __importDefault = (this && this.__importDefault) || function (mod) {
87
- return (mod && mod.__esModule) ? mod : { "default": mod };
88
- };
89
- var _a;
90
- Object.defineProperty(exports, "__esModule", { value: true });
91
- var jsx_runtime_1 = require("react/jsx-runtime");
92
- var react_1 = require("react");
93
- var react_native_1 = require("react-native");
94
- var attribute_element_1 = __importDefault(require("./attribute-element"));
95
- var base_component_js_1 = __importDefault(require("../../base-component.js"));
96
- var button_1 = __importDefault(require("../../utils/button"));
97
- var card_1 = __importDefault(require("../../utils/card"));
98
- var diggerize_1 = require("diggerize");
99
- var inflection = __importStar(require("inflection"));
100
- var form_1 = require("../../form");
101
- var header_1 = __importDefault(require("../../utils/header"));
102
- var input_1 = __importDefault(require("../../inputs/input"));
103
- var memo_js_1 = __importDefault(require("set-state-compare/build/memo.js"));
104
- var params_js_1 = __importDefault(require("../../params.js"));
105
- var prop_types_1 = __importDefault(require("prop-types"));
106
- var prop_types_exact_1 = __importDefault(require("prop-types-exact"));
107
- var react_2 = __importDefault(require("react"));
108
- var reflection_element_1 = __importDefault(require("./reflection-element"));
109
- var scope_element_1 = __importDefault(require("./scope-element"));
110
- var select_1 = __importDefault(require("../../inputs/select"));
111
- var services_js_1 = __importDefault(require("../../services.js"));
112
- var shape_component_js_1 = require("set-state-compare/build/shape-component.js");
113
- var text_1 = __importDefault(require("../../utils/text"));
114
- var use_breakpoint_js_1 = __importDefault(require("../../use-breakpoint.js"));
115
- var use_i18n_mjs_1 = __importDefault(require("i18n-on-steroids/src/use-i18n.mjs"));
116
- exports.default = (0, memo_js_1.default)((0, shape_component_js_1.shapeComponent)((_a = /** @class */ (function (_super) {
117
- __extends(ApiMakerTableFiltersFilterForm, _super);
118
- function ApiMakerTableFiltersFilterForm() {
119
- var _this = _super !== null && _super.apply(this, arguments) || this;
120
- _this.currentModelClass = function () { return (0, diggerize_1.digg)(_this.s.actualCurrentModelClass, "modelClass"); };
121
- _this.decreaseLoading = function () { return _this.setState(function (prevState) { return ({ loading: prevState.loading - 1 }); }); };
122
- _this.increaseLoading = function () { return _this.setState(function (prevState) { return ({ loading: prevState.loading + 1 }); }); };
123
- _this.onAttributeClicked = function (_b) {
124
- var attribute = _b.attribute;
125
- _this.setState({
126
- attribute: attribute,
127
- scope: undefined
128
- });
129
- };
130
- _this.onPredicateChanged = function (e) {
131
- var chosenPredicateName = (0, diggerize_1.digg)(e, "target", "value");
132
- var predicate = _this.s.predicates.find(function (predicate) { return predicate.name == chosenPredicateName; });
133
- _this.setState({ predicate: predicate });
134
- };
135
- _this.onReflectionClicked = function (_b) {
136
- var reflection = _b.reflection;
137
- var newPath = _this.s.path.concat([reflection]);
138
- _this.setState({
139
- associations: null,
140
- attribute: undefined,
141
- actualCurrentModelClass: { modelClass: (0, diggerize_1.digg)(reflection, "resource") },
142
- modelClassName: (0, diggerize_1.digg)(reflection, "modelClassName"),
143
- path: newPath,
144
- predicate: undefined
145
- });
146
- };
147
- _this.onScopeClicked = function (_b) {
148
- var scope = _b.scope;
149
- _this.setState({
150
- attribute: undefined,
151
- predicate: undefined,
152
- scope: scope
153
- });
154
- };
155
- _this.onSubmit = function () {
156
- var _b = _this.p, filter = _b.filter, querySearchName = _b.querySearchName;
157
- var _c = _this.s, attribute = _c.attribute, path = _c.path, predicate = _c.predicate, scope = _c.scope;
158
- var filterIndex = (0, diggerize_1.digs)(filter, "filterIndex").filterIndex;
159
- var searchParams = params_js_1.default.parse()[querySearchName] || {};
160
- var value = (0, diggerize_1.digg)(_this.tt.valueInputRef, "current", "value");
161
- var p = path.map(function (reflection) { return inflection.underscore(reflection.reflectionName); });
162
- var newSearchParams = {
163
- p: p,
164
- v: value
165
- };
166
- if (attribute) {
167
- newSearchParams.a = (0, diggerize_1.digg)(attribute, "attributeName");
168
- newSearchParams.pre = (0, diggerize_1.digg)(predicate, "name");
169
- }
170
- else if (scope) {
171
- newSearchParams.sc = scope;
172
- }
173
- else {
174
- throw new Error("Dont know if should search for attribute or scope?");
175
- }
176
- searchParams[filterIndex] = JSON.stringify(newSearchParams);
177
- var newParams = {};
178
- newParams[querySearchName] = searchParams;
179
- params_js_1.default.changeParams(newParams);
180
- _this.props.onApplyClicked();
181
- };
182
- return _this;
79
+ async loadAssociations() {
80
+ this.increaseLoading();
81
+ try {
82
+ if (!this.s.modelClassName)
83
+ throw new Error("'modelClassName' not set in state");
84
+ const result = await Services.current().sendRequest("Models::Associations", { model_class_name: this.s.modelClassName });
85
+ const { associations, ransackableAttributes, ransackableScopes } = this.parseAssociationData(result);
86
+ this.setState({ associations, ransackableAttributes, ransackableScopes });
183
87
  }
184
- ApiMakerTableFiltersFilterForm.prototype.setup = function () {
185
- var _this = this;
186
- var t = (0, use_i18n_mjs_1.default)({ namespace: "js.api_maker.table.filters.filter_form" }).t;
187
- this.useStates({
188
- associations: null,
189
- attribute: undefined,
190
- actualCurrentModelClass: function () { return ({ modelClass: _this.p.modelClass }); },
191
- loading: 0,
192
- modelClassName: (0, diggerize_1.digg)(this.p.modelClass.modelClassData(), "className"),
193
- path: [],
194
- predicate: undefined,
195
- predicates: undefined,
196
- ransackableAttributes: undefined,
197
- ransackableScopes: undefined,
198
- scope: this.props.filter.sc,
199
- value: this.props.filter.v
200
- });
201
- this.setInstance({
202
- breakpoint: (0, use_breakpoint_js_1.default)(),
203
- t: t,
204
- valueInputRef: (0, react_1.useRef)(),
205
- });
206
- (0, react_1.useMemo)(function () {
207
- _this.loadRansackPredicates();
208
- if (_this.props.filter.v) {
209
- _this.loadInitialValuesWithLoadingIndicator();
210
- }
211
- }, []);
212
- (0, react_1.useMemo)(function () {
213
- _this.loadAssociations();
214
- }, [this.s.modelClassName]);
215
- };
216
- ApiMakerTableFiltersFilterForm.prototype.parseAssociationData = function (result) {
217
- var associations = result.associations.map(function (_b) {
218
- var human_name = _b.human_name, model_class_name = _b.model_class_name, reflection_name = _b.reflection_name, resource = _b.resource;
219
- return ({
220
- humanName: human_name,
221
- modelClassName: model_class_name,
222
- reflectionName: inflection.camelize(reflection_name, true),
223
- resource: resource
224
- });
225
- });
226
- var ransackableAttributes = (0, diggerize_1.digg)(result, "ransackable_attributes").map(function (_b) {
227
- var attributeName = _b.attribute_name, humanName = _b.human_name;
228
- return ({
229
- attributeName: attributeName,
230
- humanName: humanName
231
- });
232
- });
233
- var ransackableScopes = (0, diggerize_1.digg)(result, "ransackable_scopes");
234
- return { associations: associations, ransackableAttributes: ransackableAttributes, ransackableScopes: ransackableScopes };
235
- };
236
- ApiMakerTableFiltersFilterForm.prototype.loadAssociations = function () {
237
- return __awaiter(this, void 0, void 0, function () {
238
- var result, _b, associations, ransackableAttributes, ransackableScopes;
239
- return __generator(this, function (_c) {
240
- switch (_c.label) {
241
- case 0:
242
- this.increaseLoading();
243
- _c.label = 1;
244
- case 1:
245
- _c.trys.push([1, , 3, 4]);
246
- if (!this.s.modelClassName)
247
- throw new Error("'modelClassName' not set in state");
248
- return [4 /*yield*/, services_js_1.default.current().sendRequest("Models::Associations", { model_class_name: this.s.modelClassName })];
249
- case 2:
250
- result = _c.sent();
251
- _b = this.parseAssociationData(result), associations = _b.associations, ransackableAttributes = _b.ransackableAttributes, ransackableScopes = _b.ransackableScopes;
252
- this.setState({ associations: associations, ransackableAttributes: ransackableAttributes, ransackableScopes: ransackableScopes });
253
- return [3 /*break*/, 4];
254
- case 3:
255
- this.decreaseLoading();
256
- return [7 /*endfinally*/];
257
- case 4: return [2 /*return*/];
258
- }
259
- });
260
- });
261
- };
262
- ApiMakerTableFiltersFilterForm.prototype.loadInitialValuesWithLoadingIndicator = function () {
263
- return __awaiter(this, void 0, void 0, function () {
264
- return __generator(this, function (_b) {
265
- switch (_b.label) {
266
- case 0:
267
- _b.trys.push([0, , 2, 3]);
268
- this.increaseLoading();
269
- return [4 /*yield*/, this.loadInitialValues()];
270
- case 1:
271
- _b.sent();
272
- return [3 /*break*/, 3];
273
- case 2:
274
- this.decreaseLoading();
275
- return [7 /*endfinally*/];
276
- case 3: return [2 /*return*/];
277
- }
278
- });
279
- });
280
- };
281
- ApiMakerTableFiltersFilterForm.prototype.loadInitialValues = function () {
282
- return __awaiter(this, void 0, void 0, function () {
283
- var result, data, modelClassName, path, _loop_1, this_1, _i, _b, pathPart, ransackableAttributes, attribute, ransackableAttribute;
284
- return __generator(this, function (_c) {
285
- switch (_c.label) {
286
- case 0:
287
- if (!this.s.modelClassName)
288
- throw new Error("'modelClassName' not set in state");
289
- return [4 /*yield*/, services_js_1.default.current().sendRequest("Models::Associations", { model_class_name: this.s.modelClassName })];
290
- case 1:
291
- result = _c.sent();
292
- data = this.parseAssociationData(result);
293
- modelClassName = this.s.modelClassName;
294
- path = [];
295
- _loop_1 = function (pathPart) {
296
- var reflection, pathNames;
297
- return __generator(this, function (_d) {
298
- switch (_d.label) {
299
- case 0:
300
- reflection = data.associations.find(function (association) { return (0, diggerize_1.digg)(association, "reflectionName") == inflection.camelize(pathPart, true); });
301
- if (!reflection)
302
- throw new Error("Couldn't find association by that name ".concat(this_1.s.modelClassName, "#").concat(pathPart));
303
- modelClassName = (0, diggerize_1.digg)(reflection, "modelClassName");
304
- if (!modelClassName) {
305
- pathNames = path.map(function (pathPart) { return pathPart.name(); }).join(".");
306
- throw new Error("No model class name from ".concat(pathNames, ".").concat(reflection.name()));
307
- }
308
- return [4 /*yield*/, services_js_1.default.current().sendRequest("Models::Associations", { model_class_name: modelClassName })];
309
- case 1:
310
- result = _d.sent();
311
- data = this_1.parseAssociationData(result);
312
- path.push(reflection);
313
- return [2 /*return*/];
314
- }
315
- });
316
- };
317
- this_1 = this;
318
- _i = 0, _b = this.props.filter.p;
319
- _c.label = 2;
320
- case 2:
321
- if (!(_i < _b.length)) return [3 /*break*/, 5];
322
- pathPart = _b[_i];
323
- return [5 /*yield**/, _loop_1(pathPart)];
324
- case 3:
325
- _c.sent();
326
- _c.label = 4;
327
- case 4:
328
- _i++;
329
- return [3 /*break*/, 2];
330
- case 5:
331
- ransackableAttributes = data.ransackableAttributes;
332
- attribute = this.p.filter.a;
333
- ransackableAttribute = ransackableAttributes.find(function (ransackableAttribute) { return (0, diggerize_1.digg)(ransackableAttribute, "attributeName") == attribute; });
334
- this.setState({ attribute: ransackableAttribute, modelClassName: modelClassName, path: path });
335
- return [2 /*return*/];
336
- }
337
- });
338
- });
339
- };
340
- ApiMakerTableFiltersFilterForm.prototype.loadRansackPredicates = function () {
341
- return __awaiter(this, void 0, void 0, function () {
342
- var response, predicates, currentPredicate;
343
- var _this = this;
344
- return __generator(this, function (_b) {
345
- switch (_b.label) {
346
- case 0:
347
- this.increaseLoading();
348
- _b.label = 1;
349
- case 1:
350
- _b.trys.push([1, , 3, 4]);
351
- return [4 /*yield*/, services_js_1.default.current().sendRequest("Ransack::Predicates")];
352
- case 2:
353
- response = _b.sent();
354
- predicates = (0, diggerize_1.digg)(response, "predicates");
355
- currentPredicate = void 0;
356
- if (this.props.filter.pre) {
357
- currentPredicate = predicates.find(function (predicate) { return predicate.name == _this.props.filter.pre; });
358
- }
359
- this.setState({
360
- predicate: currentPredicate,
361
- predicates: predicates
362
- });
363
- return [3 /*break*/, 4];
364
- case 3:
365
- this.decreaseLoading();
366
- return [7 /*endfinally*/];
367
- case 4: return [2 /*return*/];
368
- }
369
- });
370
- });
371
- };
372
- ApiMakerTableFiltersFilterForm.prototype.render = function () {
373
- var _this = this;
374
- var _b, _c;
375
- var _d = this.tt, breakpoint = _d.breakpoint, t = _d.t, valueInputRef = _d.valueInputRef;
376
- var _e = this.s, attribute = _e.attribute, path = _e.path, predicate = _e.predicate, predicates = _e.predicates, scope = _e.scope, value = _e.value;
377
- var mdUp = breakpoint.mdUp;
378
- var submitEnabled = false;
379
- if (attribute && predicate) {
380
- submitEnabled = true;
381
- }
382
- else if (scope) {
383
- submitEnabled = true;
88
+ finally {
89
+ this.decreaseLoading();
90
+ }
91
+ }
92
+ decreaseLoading = () => this.setState((prevState) => ({ loading: prevState.loading - 1 }));
93
+ increaseLoading = () => this.setState((prevState) => ({ loading: prevState.loading + 1 }));
94
+ async loadInitialValuesWithLoadingIndicator() {
95
+ try {
96
+ this.increaseLoading();
97
+ await this.loadInitialValues();
98
+ }
99
+ finally {
100
+ this.decreaseLoading();
101
+ }
102
+ }
103
+ async loadInitialValues() {
104
+ if (!this.s.modelClassName)
105
+ throw new Error("'modelClassName' not set in state");
106
+ let result = await Services.current().sendRequest("Models::Associations", { model_class_name: this.s.modelClassName });
107
+ let data = this.parseAssociationData(result);
108
+ let modelClassName = this.s.modelClassName;
109
+ const path = [];
110
+ for (const pathPart of this.props.filter.p) {
111
+ const reflection = data.associations.find((association) => digg(association, "reflectionName") == inflection.camelize(pathPart, true));
112
+ if (!reflection)
113
+ throw new Error(`Couldn't find association by that name ${this.s.modelClassName}#${pathPart}`);
114
+ modelClassName = digg(reflection, "modelClassName");
115
+ if (!modelClassName) {
116
+ const pathNames = path.map((pathPart) => pathPart.name()).join(".");
117
+ throw new Error(`No model class name from ${pathNames}.${reflection.name()}`);
384
118
  }
385
- return ((0, jsx_runtime_1.jsxs)(card_1.default, { testID: "api-maker/table/filters/filter-form", style: this.cache("cardStyle", {
386
- width: mdUp ? undefined : "100%",
387
- minWidth: 50,
388
- minHeight: 50
389
- }, [mdUp]), children: [(0, jsx_runtime_1.jsxs)(form_1.Form, { onSubmit: this.tt.onSubmit, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: { flexDirection: "row" }, children: path.map(function (_b, pathPartIndex) {
390
- var humanName = _b.humanName, reflectionName = _b.reflectionName;
391
- return (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { flexDirection: "row" }, children: [pathPartIndex > 0 &&
392
- (0, jsx_runtime_1.jsx)(text_1.default, { style: { marginRight: 5, marginLeft: 5 }, children: "-" }), (0, jsx_runtime_1.jsx)(text_1.default, { children: humanName })] }, "".concat(pathPartIndex, "-").concat(reflectionName));
393
- }) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { flexDirection: mdUp ? "row" : "column" }, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { marginTop: mdUp ? undefined : 25 }, children: [(0, jsx_runtime_1.jsx)(header_1.default, { children: t(".relationships", { defaultValue: "Relationships" }) }), this.s.associations && this.sortedReflectionsByName(this.s.associations).map(function (reflection) {
394
- return (0, jsx_runtime_1.jsx)(reflection_element_1.default, { modelClassName: _this.s.modelClassName, onClick: _this.tt.onReflectionClicked, reflection: reflection }, reflection.reflectionName);
395
- })] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { marginTop: mdUp ? undefined : 25 }, children: [(0, jsx_runtime_1.jsx)(header_1.default, { children: t(".attributes", { defaultValue: "Attributes" }) }), this.s.ransackableAttributes && ((_b = this.sortedAttributesByName(this.s.ransackableAttributes)) === null || _b === void 0 ? void 0 : _b.map(function (attribute) {
396
- var _b;
397
- return (0, jsx_runtime_1.jsx)(attribute_element_1.default, { active: attribute.attributeName == ((_b = _this.s.attribute) === null || _b === void 0 ? void 0 : _b.attributeName), attribute: attribute, modelClassName: _this.s.modelClassName, onClick: _this.tt.onAttributeClicked }, attribute.attributeName);
398
- })), (_c = this.s.ransackableScopes) === null || _c === void 0 ? void 0 : _c.map(function (scope) {
399
- return (0, jsx_runtime_1.jsx)(scope_element_1.default, { active: scope == _this.s.scope, scope: scope, onScopeClicked: _this.tt.onScopeClicked }, scope);
400
- })] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { marginTop: mdUp ? undefined : 25 }, children: [(0, jsx_runtime_1.jsx)(header_1.default, { children: t(".search", { defaultValue: "Search" }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { children: predicates && !this.s.scope &&
401
- (0, jsx_runtime_1.jsx)(select_1.default, { className: "predicate-select", defaultValue: predicate === null || predicate === void 0 ? void 0 : predicate.name, includeBlank: true, onChange: this.tt.onPredicateChanged, options: predicates.map(function (predicate) { return (0, diggerize_1.digg)(predicate, "name"); }) }) }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: { marginTop: 10 }, children: ((attribute && predicate) || scope) &&
402
- (0, jsx_runtime_1.jsx)(input_1.default, { className: "value-input", defaultValue: value, inputRef: valueInputRef }) })] })] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { flexDirection: "row", justifyContent: "end", marginTop: 10 }, children: [(0, jsx_runtime_1.jsx)(button_1.default, { danger: true, icon: "remove", label: t(".cancel", { defaultValue: "Cancel" }), onPress: this.p.onRequestClose, pressableProps: this.cancelButtonPressableProps || (this.cancelButtonPressableProps = {
403
- marginRight: 5
404
- }) }), (0, jsx_runtime_1.jsx)(button_1.default, { disabled: !submitEnabled, icon: "check", label: t(".apply", { defaultValue: "Apply" }), pressableProps: this.appleButtonPressableProps || (this.appleButtonPressableProps = {
405
- style: { marginLeft: 5 },
406
- testID: "apply-filter-button"
407
- }), submit: true })] })] }), this.s.loading > 0 &&
408
- (0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
409
- alignItems: "center",
410
- justifyContent: "center",
411
- position: "absolute",
412
- width: "100%",
413
- height: "100%"
414
- }, children: (0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "large" }) })] }));
415
- };
416
- ApiMakerTableFiltersFilterForm.prototype.currentModelClassFromPath = function (path) {
417
- var modelClass = this.p.modelClass;
418
- var currentModelClass = modelClass;
419
- var _loop_2 = function (pathPart) {
420
- var camelizedPathPart = inflection.camelize(pathPart, true);
421
- var association = currentModelClass.ransackableAssociations().find(function (reflection) { return reflection.name() == camelizedPathPart; });
422
- if (!association) {
423
- var ransackableAssociationNames = currentModelClass.ransackableAssociations().map(function (reflection) { return reflection.name(); }).join(", ");
424
- throw new Error("Could not find a Ransackable association by that name: ".concat(camelizedPathPart, " in ").concat(ransackableAssociationNames));
425
- }
426
- currentModelClass = association.modelClass();
427
- };
428
- for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
429
- var pathPart = path_1[_i];
430
- _loop_2(pathPart);
119
+ result = await Services.current().sendRequest("Models::Associations", { model_class_name: modelClassName });
120
+ data = this.parseAssociationData(result);
121
+ path.push(reflection);
122
+ }
123
+ const { ransackableAttributes } = data;
124
+ const attribute = this.p.filter.a;
125
+ const ransackableAttribute = ransackableAttributes.find((ransackableAttribute) => digg(ransackableAttribute, "attributeName") == attribute);
126
+ this.setState({ attribute: ransackableAttribute, modelClassName, path });
127
+ }
128
+ async loadRansackPredicates() {
129
+ this.increaseLoading();
130
+ try {
131
+ const response = await Services.current().sendRequest("Ransack::Predicates");
132
+ const predicates = digg(response, "predicates");
133
+ let currentPredicate;
134
+ if (this.props.filter.pre) {
135
+ currentPredicate = predicates.find((predicate) => predicate.name == this.props.filter.pre);
431
136
  }
432
- return currentModelClass;
433
- };
434
- ApiMakerTableFiltersFilterForm.prototype.currentPathParts = function () {
435
- var modelClass = this.p.modelClass;
436
- var path = this.s.path;
437
- var result = [];
438
- var currentModelClass = modelClass;
439
- result.push({
440
- modelClass: modelClass,
441
- translation: modelClass.modelName().human({ count: 2 })
137
+ this.setState({
138
+ predicate: currentPredicate,
139
+ predicates
442
140
  });
443
- var _loop_3 = function (pathPart) {
444
- var camelizedPathPart = inflection.camelize(pathPart, true);
445
- var pathPartTranslation = currentModelClass.humanAttributeName(camelizedPathPart);
446
- currentModelClass = currentModelClass.ransackableAssociations().find(function (reflection) { return reflection.name() == camelizedPathPart; }).modelClass();
447
- result.push({
448
- modelClass: currentModelClass,
449
- translation: pathPartTranslation
450
- });
451
- };
452
- for (var _i = 0, path_2 = path; _i < path_2.length; _i++) {
453
- var pathPart = path_2[_i];
454
- _loop_3(pathPart);
141
+ }
142
+ finally {
143
+ this.decreaseLoading();
144
+ }
145
+ }
146
+ render() {
147
+ const { breakpoint, t, valueInputRef } = this.tt;
148
+ const { attribute, path, predicate, predicates, scope, value } = this.s;
149
+ const { mdUp } = breakpoint;
150
+ let submitEnabled = false;
151
+ if (attribute && predicate) {
152
+ submitEnabled = true;
153
+ }
154
+ else if (scope) {
155
+ submitEnabled = true;
156
+ }
157
+ return (_jsxs(Card, { testID: "api-maker/table/filters/filter-form", style: this.cache("cardStyle", {
158
+ width: mdUp ? undefined : "100%",
159
+ minWidth: 50,
160
+ minHeight: 50
161
+ }, [mdUp]), children: [_jsxs(Form, { onSubmit: this.tt.onSubmit, children: [_jsx(View, { style: { flexDirection: "row" }, children: path.map(({ humanName, reflectionName }, pathPartIndex) => _jsxs(View, { style: { flexDirection: "row" }, children: [pathPartIndex > 0 &&
162
+ _jsx(Text, { style: { marginRight: 5, marginLeft: 5 }, children: "-" }), _jsx(Text, { children: humanName })] }, `${pathPartIndex}-${reflectionName}`)) }), _jsxs(View, { style: { flexDirection: mdUp ? "row" : "column" }, children: [_jsxs(View, { style: { marginTop: mdUp ? undefined : 25 }, children: [_jsx(Header, { children: t(".relationships", { defaultValue: "Relationships" }) }), this.s.associations && this.sortedReflectionsByName(this.s.associations).map((reflection) => _jsx(ReflectionElement, { modelClassName: this.s.modelClassName, onClick: this.tt.onReflectionClicked, reflection: reflection }, reflection.reflectionName))] }), _jsxs(View, { style: { marginTop: mdUp ? undefined : 25 }, children: [_jsx(Header, { children: t(".attributes", { defaultValue: "Attributes" }) }), this.s.ransackableAttributes && this.sortedAttributesByName(this.s.ransackableAttributes)?.map((attribute) => _jsx(AttributeElement, { active: attribute.attributeName == this.s.attribute?.attributeName, attribute: attribute, modelClassName: this.s.modelClassName, onClick: this.tt.onAttributeClicked }, attribute.attributeName)), this.s.ransackableScopes?.map((scope) => _jsx(ScopeElement, { active: scope == this.s.scope, scope: scope, onScopeClicked: this.tt.onScopeClicked }, scope))] }), _jsxs(View, { style: { marginTop: mdUp ? undefined : 25 }, children: [_jsx(Header, { children: t(".search", { defaultValue: "Search" }) }), _jsx(View, { children: predicates && !this.s.scope &&
163
+ _jsx(Select, { className: "predicate-select", defaultValue: predicate?.name, includeBlank: true, onChange: this.tt.onPredicateChanged, options: predicates.map((predicate) => digg(predicate, "name")) }) }), _jsx(View, { style: { marginTop: 10 }, children: ((attribute && predicate) || scope) &&
164
+ _jsx(Input, { className: "value-input", defaultValue: value, inputRef: valueInputRef }) })] })] }), _jsxs(View, { style: { flexDirection: "row", justifyContent: "end", marginTop: 10 }, children: [_jsx(Button, { danger: true, icon: "remove", label: t(".cancel", { defaultValue: "Cancel" }), onPress: this.p.onRequestClose, pressableProps: this.cancelButtonPressableProps ||= {
165
+ marginRight: 5
166
+ } }), _jsx(Button, { disabled: !submitEnabled, icon: "check", label: t(".apply", { defaultValue: "Apply" }), pressableProps: this.appleButtonPressableProps ||= {
167
+ style: { marginLeft: 5 },
168
+ testID: "apply-filter-button"
169
+ }, submit: true })] })] }), this.s.loading > 0 &&
170
+ _jsx(View, { style: {
171
+ alignItems: "center",
172
+ justifyContent: "center",
173
+ position: "absolute",
174
+ width: "100%",
175
+ height: "100%"
176
+ }, children: _jsx(ActivityIndicator, { size: "large" }) })] }));
177
+ }
178
+ currentModelClassFromPath(path) {
179
+ const { modelClass } = this.p;
180
+ let currentModelClass = modelClass;
181
+ for (const pathPart of path) {
182
+ const camelizedPathPart = inflection.camelize(pathPart, true);
183
+ const association = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() == camelizedPathPart);
184
+ if (!association) {
185
+ const ransackableAssociationNames = currentModelClass.ransackableAssociations().map((reflection) => reflection.name()).join(", ");
186
+ throw new Error(`Could not find a Ransackable association by that name: ${camelizedPathPart} in ${ransackableAssociationNames}`);
455
187
  }
456
- return result;
457
- };
458
- ApiMakerTableFiltersFilterForm.prototype.reflectionsWithModelClass = function (reflections) {
459
- return reflections.filter(function (reflection) {
460
- try {
461
- reflection.modelClass();
462
- return true;
463
- }
464
- catch (error) {
465
- return false;
466
- }
467
- });
468
- };
469
- ApiMakerTableFiltersFilterForm.prototype.sortedAttributesByName = function (attributes) {
470
- return attributes.sort(function (a, b) {
471
- return (0, diggerize_1.digg)(a, "humanName")
472
- .toLowerCase()
473
- .localeCompare((0, diggerize_1.digg)(b, "humanName").toLowerCase());
474
- });
475
- };
476
- ApiMakerTableFiltersFilterForm.prototype.sortedReflectionsByName = function (reflections) {
477
- return reflections.sort(function (a, b) {
478
- return (0, diggerize_1.digg)(a, "humanName")
479
- .toLowerCase()
480
- .localeCompare((0, diggerize_1.digg)(b, "humanName").toLowerCase());
188
+ currentModelClass = association.modelClass();
189
+ }
190
+ return currentModelClass;
191
+ }
192
+ currentPathParts() {
193
+ const { modelClass } = this.p;
194
+ const { path } = this.s;
195
+ const result = [];
196
+ let currentModelClass = modelClass;
197
+ result.push({
198
+ modelClass,
199
+ translation: modelClass.modelName().human({ count: 2 })
200
+ });
201
+ for (const pathPart of path) {
202
+ const camelizedPathPart = inflection.camelize(pathPart, true);
203
+ const pathPartTranslation = currentModelClass.humanAttributeName(camelizedPathPart);
204
+ currentModelClass = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() == camelizedPathPart).modelClass();
205
+ result.push({
206
+ modelClass: currentModelClass,
207
+ translation: pathPartTranslation
481
208
  });
209
+ }
210
+ return result;
211
+ }
212
+ onAttributeClicked = ({ attribute }) => {
213
+ this.setState({
214
+ attribute,
215
+ scope: undefined
216
+ });
217
+ };
218
+ onPredicateChanged = (e) => {
219
+ const chosenPredicateName = digg(e, "target", "value");
220
+ const predicate = this.s.predicates.find((predicate) => predicate.name == chosenPredicateName);
221
+ this.setState({ predicate });
222
+ };
223
+ onReflectionClicked = ({ reflection }) => {
224
+ const newPath = this.s.path.concat([reflection]);
225
+ this.setState({
226
+ associations: null,
227
+ attribute: undefined,
228
+ actualCurrentModelClass: { modelClass: digg(reflection, "resource") },
229
+ modelClassName: digg(reflection, "modelClassName"),
230
+ path: newPath,
231
+ predicate: undefined
232
+ });
233
+ };
234
+ onScopeClicked = ({ scope }) => {
235
+ this.setState({
236
+ attribute: undefined,
237
+ predicate: undefined,
238
+ scope
239
+ });
240
+ };
241
+ onSubmit = () => {
242
+ const { filter, querySearchName } = this.p;
243
+ const { attribute, path, predicate, scope } = this.s;
244
+ const { filterIndex } = digs(filter, "filterIndex");
245
+ const searchParams = Params.parse()[querySearchName] || {};
246
+ const value = digg(this.tt.valueInputRef, "current", "value");
247
+ const p = path.map((reflection) => inflection.underscore(reflection.reflectionName));
248
+ const newSearchParams = {
249
+ p,
250
+ v: value
482
251
  };
483
- return ApiMakerTableFiltersFilterForm;
484
- }(base_component_js_1.default)),
485
- _a.propTypes = (0, prop_types_exact_1.default)({
486
- filter: prop_types_1.default.object,
487
- modelClass: prop_types_1.default.func.isRequired,
488
- onApplyClicked: prop_types_1.default.func.isRequired,
489
- onRequestClose: prop_types_1.default.func.isRequired,
490
- querySearchName: prop_types_1.default.string.isRequired
491
- }),
492
- _a)));
252
+ if (attribute) {
253
+ newSearchParams.a = digg(attribute, "attributeName");
254
+ newSearchParams.pre = digg(predicate, "name");
255
+ }
256
+ else if (scope) {
257
+ newSearchParams.sc = scope;
258
+ }
259
+ else {
260
+ throw new Error("Dont know if should search for attribute or scope?");
261
+ }
262
+ searchParams[filterIndex] = JSON.stringify(newSearchParams);
263
+ const newParams = {};
264
+ newParams[querySearchName] = searchParams;
265
+ Params.changeParams(newParams);
266
+ this.props.onApplyClicked();
267
+ };
268
+ reflectionsWithModelClass(reflections) {
269
+ return reflections.filter((reflection) => {
270
+ try {
271
+ reflection.modelClass();
272
+ return true;
273
+ }
274
+ catch (error) {
275
+ return false;
276
+ }
277
+ });
278
+ }
279
+ sortedAttributesByName(attributes) {
280
+ return attributes.sort((a, b) => digg(a, "humanName")
281
+ .toLowerCase()
282
+ .localeCompare(digg(b, "humanName").toLowerCase()));
283
+ }
284
+ sortedReflectionsByName(reflections) {
285
+ return reflections.sort((a, b) => digg(a, "humanName")
286
+ .toLowerCase()
287
+ .localeCompare(digg(b, "humanName").toLowerCase()));
288
+ }
289
+ }));
493
290
  //# sourceMappingURL=filter-form.js.map