@kaspernj/api-maker 1.0.2011 → 1.0.2012

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 (410) hide show
  1. package/{.eslintrc.cjs → .eslintrc.js} +10 -1
  2. package/README.md +35 -0
  3. package/android/build.gradle +43 -0
  4. package/android/src/main/AndroidManifest.xml +2 -0
  5. package/android/src/main/java/expo/modules/api_maker/ApiMakerModule.kt +50 -0
  6. package/android/src/main/java/expo/modules/api_maker/ApiMakerView.kt +30 -0
  7. package/build/api.js +120 -0
  8. package/build/attribute-not-loaded-error.js +2 -0
  9. package/build/base-component.js +5 -0
  10. package/build/base-error.js +33 -0
  11. package/build/base-model/attribute.js +25 -0
  12. package/build/base-model/column.js +11 -0
  13. package/build/base-model/reflection.js +14 -0
  14. package/build/base-model/scope.js +11 -0
  15. package/build/base-model.js +828 -0
  16. package/build/bootstrap/attribute-row.js +135 -0
  17. package/build/bootstrap/attribute-rows.js +31 -0
  18. package/build/bootstrap/card.js +138 -0
  19. package/build/bootstrap/checkbox.js +97 -0
  20. package/build/bootstrap/checkboxes.js +183 -0
  21. package/build/bootstrap/index.js +2 -0
  22. package/build/bootstrap/input.js +129 -0
  23. package/build/bootstrap/invalid-feedback.js +27 -0
  24. package/build/bootstrap/paginate.js +150 -0
  25. package/build/bootstrap/radio-buttons.js +72 -0
  26. package/build/bootstrap/select.js +88 -0
  27. package/build/bootstrap/sort-link.js +131 -0
  28. package/build/cable-connection-pool.js +128 -0
  29. package/build/cable-subscription-pool.js +207 -0
  30. package/build/cable-subscription.js +21 -0
  31. package/build/cache-key-generator.js +81 -0
  32. package/build/can-can.js +134 -0
  33. package/build/channels-consumer.js +9 -0
  34. package/build/collection-loader.js +48 -0
  35. package/build/collection.js +280 -0
  36. package/build/command-submit-data.js +81 -0
  37. package/build/commands-pool.js +195 -0
  38. package/build/compose.js +9 -0
  39. package/build/config.js +62 -0
  40. package/build/custom-error.js +5 -0
  41. package/build/data-set-to-attributes.js +10 -0
  42. package/build/deserializer.js +56 -0
  43. package/build/destroy-error.js +5 -0
  44. package/build/devise.js +112 -0
  45. package/build/draggable-sort/controller.js +136 -0
  46. package/build/draggable-sort/index.js +114 -0
  47. package/build/draggable-sort/item.js +188 -0
  48. package/build/error-logger.js +101 -0
  49. package/build/error-messages.js +13 -0
  50. package/build/event-connection.js +32 -0
  51. package/build/event-emitter-listener.js +15 -0
  52. package/build/event-model-class.js +24 -0
  53. package/build/events.js +5 -0
  54. package/build/flash-message.js +79 -0
  55. package/build/form.js +83 -0
  56. package/build/history-expo.js +20 -0
  57. package/build/history-react-native.js +20 -0
  58. package/build/history.js +3 -0
  59. package/build/index.js +3 -0
  60. package/build/inputs/attachment.js +133 -0
  61. package/build/inputs/auto-submit.js +36 -0
  62. package/build/inputs/checkbox.js +138 -0
  63. package/build/inputs/checkboxes.js +112 -0
  64. package/build/inputs/id-for-component.js +15 -0
  65. package/build/inputs/input-wrapper.js +19 -0
  66. package/build/inputs/input.js +243 -0
  67. package/build/inputs/money.js +179 -0
  68. package/build/inputs/name-for-component.js +13 -0
  69. package/build/inputs/select.js +93 -0
  70. package/build/instance-of-class-name.js +23 -0
  71. package/build/key-value-store.js +53 -0
  72. package/build/link.js +73 -0
  73. package/build/logger.js +30 -0
  74. package/build/modal.js +38 -0
  75. package/build/model-class-require.js +13 -0
  76. package/build/model-events.js +30 -0
  77. package/build/model-name.js +28 -0
  78. package/build/model-prop-type.js +101 -0
  79. package/build/model-recipes-loader.js +32 -0
  80. package/build/model-recipes-model-loader.js +357 -0
  81. package/build/models-response-reader.js +40 -0
  82. package/build/models.js +8 -0
  83. package/build/money-formatter.js +78 -0
  84. package/build/not-loaded-error.js +2 -0
  85. package/build/params.js +61 -0
  86. package/build/preloaded.js +38 -0
  87. package/build/resize-observer.js +11 -0
  88. package/build/result.js +13 -0
  89. package/build/router/route.js +270 -0
  90. package/build/router/switch.js +72 -0
  91. package/build/router.js +59 -0
  92. package/build/routes-native.js +202 -0
  93. package/build/routes.js +50 -0
  94. package/build/run-last.js +35 -0
  95. package/build/serializer.js +63 -0
  96. package/build/services.js +20 -0
  97. package/build/session-status-updater.js +134 -0
  98. package/build/source-maps-loader.js +184 -0
  99. package/build/super-admin/config-reader.js +85 -0
  100. package/build/super-admin/edit-page/edit-attribute-checkbox.js +85 -0
  101. package/build/super-admin/edit-page/edit-attribute-content.js +55 -0
  102. package/build/super-admin/edit-page/edit-attribute-input.js +79 -0
  103. package/build/super-admin/edit-page/edit-attribute.js +77 -0
  104. package/build/super-admin/edit-page.js +123 -0
  105. package/build/super-admin/has-edit-config.js +12 -0
  106. package/build/super-admin/index-page.js +25 -0
  107. package/build/super-admin/index.js +181 -0
  108. package/build/super-admin/layout/header/index.js +161 -0
  109. package/build/super-admin/layout/index.js +164 -0
  110. package/build/super-admin/layout/menu/index.js +206 -0
  111. package/build/super-admin/layout/menu/menu-content.js +46 -0
  112. package/build/super-admin/layout/menu/menu-item.js +84 -0
  113. package/build/super-admin/layout/no-access.js +27 -0
  114. package/build/super-admin/model-class-table.js +61 -0
  115. package/build/super-admin/models.js +8 -0
  116. package/build/super-admin/show-nav.js +51 -0
  117. package/build/super-admin/show-page/belongs-to-attribute-row.js +29 -0
  118. package/build/super-admin/show-page/index.js +141 -0
  119. package/build/super-admin/show-reflection-actions.js +47 -0
  120. package/build/super-admin/show-reflection-link.js +48 -0
  121. package/build/super-admin/show-reflection-page.js +48 -0
  122. package/build/table/column-content.js +117 -0
  123. package/build/table/column-identifier.js +18 -0
  124. package/build/table/column-visible.js +7 -0
  125. package/build/table/components/column.js +21 -0
  126. package/build/table/components/flat-list.js +21 -0
  127. package/build/table/components/header.js +26 -0
  128. package/build/table/components/row.js +26 -0
  129. package/build/table/filters/attribute-element.js +44 -0
  130. package/build/table/filters/filter-form.js +402 -0
  131. package/build/table/filters/filter.js +90 -0
  132. package/build/table/filters/index.js +184 -0
  133. package/build/table/filters/load-search-modal.js +175 -0
  134. package/build/table/filters/reflection-element.js +37 -0
  135. package/build/table/filters/save-search-modal.js +88 -0
  136. package/build/table/filters/scope-element.js +42 -0
  137. package/build/table/header-column-content.js +68 -0
  138. package/build/table/header-column.js +144 -0
  139. package/build/table/header-select.js +105 -0
  140. package/build/table/model-callback-args.js +10 -0
  141. package/build/table/model-column.js +97 -0
  142. package/build/table/model-row.js +193 -0
  143. package/build/table/select-calculator.js +63 -0
  144. package/build/table/settings/column-row.js +97 -0
  145. package/build/table/settings/download-action.js +79 -0
  146. package/build/table/settings/index.js +92 -0
  147. package/build/table/table-settings.js +219 -0
  148. package/build/table/table.js +972 -0
  149. package/build/table/use-sorting.js +34 -0
  150. package/build/table/widths.js +75 -0
  151. package/build/table/worker-plugins-check-all-checkbox.js +125 -0
  152. package/build/table/worker-plugins-checkbox.js +115 -0
  153. package/build/translated-attributes.js +10 -0
  154. package/build/translated-collections.js +12 -0
  155. package/build/updated-attribute.js +76 -0
  156. package/build/url-encode.js +15 -0
  157. package/build/use-breakpoint.js +62 -0
  158. package/build/use-can-can.js +55 -0
  159. package/build/use-collection.js +225 -0
  160. package/build/use-created-event.js +52 -0
  161. package/build/use-current-user.js +76 -0
  162. package/build/use-destroyed-event.js +60 -0
  163. package/build/use-event-emitter.js +13 -0
  164. package/build/use-event-listener.js +16 -0
  165. package/build/use-input.js +137 -0
  166. package/build/use-model-event.js +60 -0
  167. package/build/use-model.js +169 -0
  168. package/build/use-resize-observer.js +23 -0
  169. package/build/use-router.js +104 -0
  170. package/build/use-screen-layout.js +39 -0
  171. package/build/use-updated-event.js +60 -0
  172. package/build/use-validation-errors.js +30 -0
  173. package/build/utils/card.js +51 -0
  174. package/build/utils/checkbox.js +78 -0
  175. package/build/utils/checkboxes.js +163 -0
  176. package/build/utils/default-style.js +18 -0
  177. package/build/utils/icon.js +23 -0
  178. package/build/utils/invalid-feedback.js +19 -0
  179. package/build/utils/modal.js +62 -0
  180. package/build/utils/text.js +19 -0
  181. package/build/validation-error.js +28 -0
  182. package/build/validation-errors.js +98 -0
  183. package/build/with-api-maker.js +29 -0
  184. package/build/with-collection.js +14 -0
  185. package/build/with-current-user.js +10 -0
  186. package/build/with-model.js +15 -0
  187. package/build/with-router.js +22 -0
  188. package/expo-module.config.json +17 -0
  189. package/ios/ApiMaker.podspec +29 -0
  190. package/ios/ApiMakerModule.swift +48 -0
  191. package/ios/ApiMakerView.swift +38 -0
  192. package/link.sh +8 -0
  193. package/package.json +49 -46
  194. package/src/{api.mjs → api.js} +38 -37
  195. package/src/base-component.jsx +5 -0
  196. package/src/{base-error.mjs → base-error.js} +4 -6
  197. package/src/base-model/attribute.js +33 -0
  198. package/src/base-model/column.js +13 -0
  199. package/src/base-model/reflection.js +15 -0
  200. package/src/base-model/scope.js +12 -0
  201. package/src/{base-model.mjs → base-model.js} +302 -144
  202. package/src/bootstrap/attribute-row.jsx +135 -0
  203. package/src/bootstrap/attribute-rows.jsx +27 -0
  204. package/src/bootstrap/card.jsx +149 -0
  205. package/src/bootstrap/checkbox.jsx +86 -0
  206. package/src/bootstrap/checkboxes.jsx +185 -0
  207. package/src/bootstrap/index.js +0 -0
  208. package/src/bootstrap/input.jsx +173 -0
  209. package/src/bootstrap/invalid-feedback.jsx +31 -0
  210. package/src/bootstrap/paginate.jsx +187 -0
  211. package/src/bootstrap/radio-buttons.jsx +87 -0
  212. package/src/bootstrap/select.jsx +110 -0
  213. package/src/bootstrap/sort-link.jsx +106 -0
  214. package/src/{cable-connection-pool.mjs → cable-connection-pool.js} +16 -36
  215. package/src/{cable-subscription-pool.mjs → cable-subscription-pool.js} +26 -21
  216. package/src/{cable-subscription.mjs → cable-subscription.js} +6 -4
  217. package/src/cache-key-generator.js +100 -0
  218. package/src/{can-can.mjs → can-can.js} +13 -12
  219. package/src/channels-consumer.js +10 -0
  220. package/src/collection-loader.jsx +58 -224
  221. package/src/{collection.mjs → collection.js} +98 -44
  222. package/src/{command-submit-data.mjs → command-submit-data.js} +2 -7
  223. package/src/{commands-pool.mjs → commands-pool.js} +57 -41
  224. package/src/compose.js +11 -0
  225. package/src/{config.mjs → config.js} +6 -2
  226. package/src/{custom-error.mjs → custom-error.js} +1 -1
  227. package/src/data-set-to-attributes.js +13 -0
  228. package/src/{deserializer.mjs → deserializer.js} +3 -3
  229. package/src/destroy-error.js +7 -0
  230. package/src/devise.js +129 -0
  231. package/src/draggable-sort/controller.js +137 -0
  232. package/src/draggable-sort/index.jsx +108 -0
  233. package/src/draggable-sort/item.jsx +174 -0
  234. package/src/{error-logger.mjs → error-logger.js} +12 -7
  235. package/src/{error-messages.mjs → error-messages.js} +1 -0
  236. package/src/event-connection.jsx +1 -1
  237. package/src/event-emitter-listener.jsx +8 -27
  238. package/src/event-model-class.jsx +2 -4
  239. package/src/events.js +7 -0
  240. package/src/flash-message.js +70 -0
  241. package/src/form.jsx +91 -0
  242. package/src/history-expo.js +23 -0
  243. package/src/history-react-native.js +25 -0
  244. package/src/history.js +3 -0
  245. package/src/index.js +3 -0
  246. package/src/inputs/attachment.jsx +108 -0
  247. package/src/inputs/auto-submit.js +37 -0
  248. package/src/inputs/checkbox.jsx +125 -0
  249. package/src/inputs/checkboxes.jsx +116 -0
  250. package/src/inputs/id-for-component.js +15 -0
  251. package/src/inputs/input-wrapper.jsx +16 -0
  252. package/src/inputs/input.jsx +260 -0
  253. package/src/inputs/money.jsx +187 -0
  254. package/src/inputs/name-for-component.js +15 -0
  255. package/src/inputs/select.jsx +104 -0
  256. package/src/{key-value-store.mjs → key-value-store.js} +1 -1
  257. package/src/link.jsx +54 -9
  258. package/src/logger.js +38 -0
  259. package/src/modal.jsx +37 -0
  260. package/src/model-class-require.js +17 -0
  261. package/src/{model-events.mjs → model-events.js} +1 -1
  262. package/src/{model-name.mjs → model-name.js} +8 -8
  263. package/src/{model-recipes-loader.mjs → model-recipes-loader.js} +1 -1
  264. package/src/{model-recipes-model-loader.mjs → model-recipes-model-loader.js} +5 -5
  265. package/src/{models-response-reader.mjs → models-response-reader.js} +3 -4
  266. package/src/models.js +7 -0
  267. package/src/{models.mjs.erb → models.js.erb} +6 -3
  268. package/src/{money-formatter.mjs → money-formatter.js} +5 -4
  269. package/src/{params.mjs → params.js} +17 -7
  270. package/src/{preloaded.mjs → preloaded.js} +2 -2
  271. package/src/resize-observer.jsx +10 -0
  272. package/src/result.js +13 -0
  273. package/src/router/route.jsx +246 -0
  274. package/src/router/switch.jsx +76 -0
  275. package/src/router.jsx +23 -21
  276. package/src/{routes-native.mjs → routes-native.js} +12 -6
  277. package/src/{routes.mjs → routes.js} +1 -1
  278. package/src/run-last.js +39 -0
  279. package/src/{serializer.mjs → serializer.js} +2 -2
  280. package/src/{services.mjs → services.js} +1 -1
  281. package/src/session-status-updater.js +172 -0
  282. package/src/{source-maps-loader.mjs → source-maps-loader.js} +54 -28
  283. package/src/super-admin/config-reader.jsx +93 -0
  284. package/src/super-admin/edit-page/edit-attribute-checkbox.jsx +81 -0
  285. package/src/super-admin/edit-page/edit-attribute-content.jsx +57 -0
  286. package/src/super-admin/edit-page/edit-attribute-input.jsx +71 -0
  287. package/src/super-admin/edit-page/edit-attribute.jsx +81 -0
  288. package/src/super-admin/edit-page.jsx +117 -0
  289. package/src/super-admin/has-edit-config.js +15 -0
  290. package/src/super-admin/index-page.jsx +23 -0
  291. package/src/super-admin/index.jsx +197 -0
  292. package/src/super-admin/layout/header/index.jsx +144 -0
  293. package/src/super-admin/layout/header/style.scss +45 -0
  294. package/src/super-admin/layout/index.jsx +154 -0
  295. package/src/super-admin/layout/menu/index.jsx +171 -0
  296. package/src/super-admin/layout/menu/menu-content.jsx +43 -0
  297. package/src/super-admin/layout/menu/menu-item.jsx +70 -0
  298. package/src/super-admin/layout/menu/style.scss +11 -0
  299. package/src/super-admin/layout/no-access.jsx +26 -0
  300. package/src/super-admin/model-class-table.jsx +66 -0
  301. package/src/super-admin/models.js +11 -0
  302. package/src/super-admin/show-nav.jsx +44 -0
  303. package/src/super-admin/show-page/belongs-to-attribute-row.jsx +30 -0
  304. package/src/super-admin/show-page/index.jsx +141 -0
  305. package/src/super-admin/show-reflection-actions.jsx +49 -0
  306. package/src/super-admin/show-reflection-link.jsx +40 -0
  307. package/src/super-admin/show-reflection-page.jsx +47 -0
  308. package/src/super-admin/stylesheets/variables.scss +11 -0
  309. package/src/table/column-content.jsx +122 -0
  310. package/src/table/column-identifier.js +23 -0
  311. package/src/table/column-visible.js +7 -0
  312. package/src/table/components/column.jsx +19 -0
  313. package/src/table/components/flat-list.jsx +19 -0
  314. package/src/table/components/header.jsx +21 -0
  315. package/src/table/components/row.jsx +23 -0
  316. package/src/table/filters/attribute-element.jsx +47 -0
  317. package/src/table/filters/filter-form.jsx +407 -0
  318. package/src/table/filters/filter.jsx +70 -0
  319. package/src/table/filters/index.jsx +170 -0
  320. package/src/table/filters/load-search-modal.jsx +146 -0
  321. package/src/table/filters/reflection-element.jsx +38 -0
  322. package/src/table/filters/save-search-modal.jsx +74 -0
  323. package/src/table/filters/scope-element.jsx +44 -0
  324. package/src/table/header-column-content.jsx +55 -0
  325. package/src/table/header-column.jsx +129 -0
  326. package/src/table/header-select.jsx +73 -0
  327. package/src/table/model-callback-args.js +10 -0
  328. package/src/table/model-column.jsx +82 -0
  329. package/src/table/model-row.jsx +136 -0
  330. package/src/table/select-calculator.js +65 -0
  331. package/src/table/settings/column-row.jsx +93 -0
  332. package/src/table/settings/download-action.jsx +68 -0
  333. package/src/table/settings/index.jsx +65 -0
  334. package/src/table/table-settings.js +263 -0
  335. package/src/table/table.jsx +950 -0
  336. package/src/table/use-sorting.js +35 -0
  337. package/src/table/variables.scss +11 -0
  338. package/src/table/widths.jsx +87 -0
  339. package/src/table/worker-plugins-check-all-checkbox.jsx +112 -0
  340. package/src/table/worker-plugins-checkbox.jsx +104 -0
  341. package/src/translated-attributes.js +11 -0
  342. package/src/{translated-collections.mjs → translated-collections.js} +3 -2
  343. package/src/updated-attribute.jsx +1 -1
  344. package/src/url-encode.js +18 -0
  345. package/src/use-breakpoint.js +76 -0
  346. package/src/use-can-can.js +55 -0
  347. package/src/use-collection.js +280 -0
  348. package/src/use-created-event.js +55 -0
  349. package/src/use-current-user.js +88 -0
  350. package/src/use-destroyed-event.js +60 -0
  351. package/src/use-event-emitter.js +15 -0
  352. package/src/use-event-listener.js +19 -0
  353. package/src/use-input.js +157 -0
  354. package/src/use-model-event.js +60 -0
  355. package/src/use-model.js +189 -0
  356. package/src/use-resize-observer.js +24 -0
  357. package/src/use-router.jsx +128 -0
  358. package/src/use-screen-layout.js +49 -0
  359. package/src/use-updated-event.js +60 -0
  360. package/src/use-validation-errors.js +33 -0
  361. package/src/utils/card.jsx +49 -0
  362. package/src/utils/checkbox.jsx +80 -0
  363. package/src/utils/checkboxes.jsx +158 -0
  364. package/src/utils/default-style.jsx +25 -0
  365. package/src/utils/icon.jsx +21 -0
  366. package/src/utils/invalid-feedback.jsx +20 -0
  367. package/src/utils/modal.jsx +60 -0
  368. package/src/utils/text.jsx +16 -0
  369. package/src/{validation-error.mjs → validation-error.js} +9 -5
  370. package/src/{validation-errors.mjs → validation-errors.js} +15 -27
  371. package/src/with-api-maker.jsx +31 -0
  372. package/src/with-collection.jsx +17 -0
  373. package/src/with-current-user.jsx +7 -25
  374. package/src/with-model.jsx +16 -0
  375. package/src/with-router.jsx +7 -129
  376. package/__tests__/base-model.test.js +0 -71
  377. package/__tests__/cable-connection-pool.test.js +0 -227
  378. package/__tests__/cable-subscription-pool.test.js +0 -26
  379. package/__tests__/can-can.test.js +0 -34
  380. package/__tests__/collection.test.js +0 -51
  381. package/__tests__/custom-error.test.js +0 -13
  382. package/__tests__/model-name.test.js +0 -34
  383. package/__tests__/model-prop-type.test.js +0 -113
  384. package/__tests__/params.test.js +0 -40
  385. package/__tests__/routes-native.test.js +0 -103
  386. package/__tests__/routes.test.js +0 -46
  387. package/__tests__/serializer.test.js +0 -30
  388. package/__tests__/support/task.js +0 -27
  389. package/__tests__/support/user.js +0 -32
  390. package/index.js +0 -1
  391. package/jest.config.js +0 -4
  392. package/src/can-can-loader.jsx +0 -54
  393. package/src/channels-consumer.mjs +0 -3
  394. package/src/destroy-error.mjs +0 -7
  395. package/src/devise.mjs +0 -122
  396. package/src/event-created.jsx +0 -65
  397. package/src/event-destroyed.jsx +0 -29
  398. package/src/event-listener.jsx +0 -38
  399. package/src/event-updated.jsx +0 -74
  400. package/src/logger.mjs +0 -25
  401. package/src/model-class-require.mjs +0 -10
  402. package/src/model-load-wrapper.jsx +0 -116
  403. package/src/result.mjs +0 -29
  404. package/src/session-status-updater.mjs +0 -116
  405. package/webpack.config.js +0 -15
  406. /package/src/{attribute-not-loaded-error.mjs → attribute-not-loaded-error.js} +0 -0
  407. /package/src/{instance-of-class-name.mjs → instance-of-class-name.js} +0 -0
  408. /package/src/{model-prop-type.mjs → model-prop-type.js} +0 -0
  409. /package/src/{not-loaded-error.mjs → not-loaded-error.js} +0 -0
  410. /package/src/{translated-collections-data.mjs.erb → translated-collections-data.js.erb} +0 -0
@@ -0,0 +1,170 @@
1
+ import BaseComponent from "../../base-component"
2
+ import {digg, digs} from "diggerize"
3
+ import Filter from "./filter"
4
+ import FilterForm from "./filter-form"
5
+ import LoadSearchModal from "./load-search-modal"
6
+ import SaveSearchModal from "./save-search-modal"
7
+ import Params from "../../params"
8
+ import PropTypes from "prop-types"
9
+ import * as models from "models"
10
+ import memo from "set-state-compare/src/memo"
11
+ import {shapeComponent} from "set-state-compare/src/shape-component"
12
+ import React from "react"
13
+ import useI18n from "i18n-on-steroids/src/use-i18n"
14
+ import useQueryParams from "on-location-changed/build/use-query-params"
15
+ import {View} from "react-native"
16
+
17
+ const {TableSearch} = models
18
+
19
+ export default memo(shapeComponent(class ApiMakerTableFilters extends BaseComponent {
20
+ static propTypes = {
21
+ currentUser: PropTypes.object,
22
+ modelClass: PropTypes.func.isRequired,
23
+ queryName: PropTypes.string.isRequired,
24
+ querySName: PropTypes.string.isRequired
25
+ }
26
+
27
+ setup() {
28
+ const {t} = useI18n({namespace: "js.api_maker.table.filters"})
29
+
30
+ this.queryParams = useQueryParams()
31
+ this.t = t
32
+ this.useStates({
33
+ filter: undefined,
34
+ showLoadSearchModal: undefined,
35
+ showSaveSearchModal: false
36
+ })
37
+ }
38
+
39
+ render() {
40
+ const {modelClass, querySName} = digs(this.props, "modelClass", "querySName")
41
+ const {currentUser} = this.props
42
+ const {filter, showLoadSearchModal, showSaveSearchModal} = digs(this.state, "filter", "showLoadSearchModal", "showSaveSearchModal")
43
+ const currentFilters = this.currentFilters()
44
+
45
+ return (
46
+ <View dataSet={{class: "api-maker--table--filters"}} style={{alignItems: "flex-start"}}>
47
+ {filter &&
48
+ <FilterForm
49
+ filter={filter}
50
+ key={`filter-${filter.filterIndex}`}
51
+ modelClass={modelClass}
52
+ onApplyClicked={digg(this, "onApplyClicked")}
53
+ querySearchName={querySName}
54
+ />
55
+ }
56
+ {showLoadSearchModal &&
57
+ <LoadSearchModal
58
+ currentUser={currentUser}
59
+ modelClass={modelClass}
60
+ onEditSearchPressed={digg(this, "onEditSearchPressed")}
61
+ onRequestClose={digg(this, "onRequestCloseLoadSearchModal")}
62
+ querySearchName={querySName}
63
+ />
64
+ }
65
+ {showSaveSearchModal &&
66
+ <SaveSearchModal
67
+ currentFilters={digg(this, "currentFilters")}
68
+ currentUser={currentUser}
69
+ onRequestClose={digg(this, "onRequestCloseSaveSearchModal")}
70
+ search={showSaveSearchModal}
71
+ />
72
+ }
73
+ {currentFilters?.map((filterData, filterIndex) =>
74
+ <Filter
75
+ key={filterIndex}
76
+ filterIndex={filterIndex}
77
+ onClick={this.tt.onFilterClicked}
78
+ onRemoveClicked={this.tt.onRemoveClicked}
79
+ {...filterData}
80
+ />
81
+ )}
82
+ <View className="filter-actions" style={{flexDirection: "row", marginTop: 10}}>
83
+ <button className="add-new-filter-button" onClick={this.tt.onAddFilterClicked}>
84
+ {this.t(".add_new_filter", {defaultValue: "Add new filter"})}
85
+ </button>
86
+ {currentUser &&
87
+ <>
88
+ <button className="save-search-button" onClick={this.tt.onSaveSearchClicked} style={{marginLeft: 10}}>
89
+ {this.t(".save_search", {defaultValue: "Save search"})}
90
+ </button>
91
+ <button className="load-search-button" onClick={this.tt.onLoadSearchClicked} style={{marginLeft: 10}}>
92
+ {this.t(".load_search", {defaultValue: "Load search"})}
93
+ </button>
94
+ </>
95
+ }
96
+ </View>
97
+ </View>
98
+ )
99
+ }
100
+
101
+ currentFilters = () => {
102
+ const {querySName} = digs(this.props, "querySName")
103
+ const currentFilters = this.queryParams[querySName] || []
104
+
105
+ return currentFilters.map((currentFilter) => JSON.parse(currentFilter))
106
+ }
107
+
108
+ onAddFilterClicked = (e) => {
109
+ e.preventDefault()
110
+
111
+ const newFilterIndex = this.currentFilters().length
112
+
113
+ this.setState({
114
+ filter: {
115
+ filterIndex: newFilterIndex
116
+ }
117
+ })
118
+ }
119
+
120
+ onApplyClicked = () => this.setState({filter: undefined})
121
+
122
+ onEditSearchPressed = ({search}) => {
123
+ this.onRequestCloseLoadSearchModal()
124
+ this.setState({
125
+ showSaveSearchModal: search
126
+ })
127
+ }
128
+
129
+ onFilterClicked = (filter) => this.setState({filter})
130
+
131
+ onLoadSearchClicked = (e) => {
132
+ e.preventDefault()
133
+
134
+ this.setState({
135
+ showLoadSearchModal: true
136
+ })
137
+ }
138
+
139
+ onRemoveClicked = ({filterIndex}) => {
140
+ const {querySName} = digs(this.props, "querySName")
141
+ const searchParams = Params.parse()[querySName] || {}
142
+
143
+ delete searchParams[filterIndex]
144
+
145
+ const newParams = {}
146
+
147
+ newParams[querySName] = searchParams
148
+
149
+ Params.changeParams(newParams)
150
+
151
+ this.setState({
152
+ filter: undefined
153
+ })
154
+ }
155
+
156
+ onRequestCloseLoadSearchModal = () => this.setState({showLoadSearchModal: false})
157
+ onRequestCloseSaveSearchModal = () => this.setState({showSaveSearchModal: undefined})
158
+
159
+ onSaveSearchClicked = (e) => {
160
+ e.preventDefault()
161
+
162
+ if (this.hasAnyFilters()) {
163
+ this.setState({showSaveSearchModal: new TableSearch()})
164
+ } else {
165
+ FlashMessage.alert(this.t(".no_filters_has_been_set", {defaultValue: "No filters has been set"}))
166
+ }
167
+ }
168
+
169
+ hasAnyFilters = () => Object.keys(this.currentFilters()).length > 0
170
+ }))
@@ -0,0 +1,146 @@
1
+ import React, {useMemo} from "react"
2
+ import {Pressable, View} from "react-native"
3
+ import apiMakerConfig from "@kaspernj/api-maker/build/config"
4
+ import BaseComponent from "../../base-component"
5
+ import classNames from "classnames"
6
+ import {digg} from "diggerize"
7
+ import memo from "set-state-compare/src/memo"
8
+ import {shapeComponent} from "set-state-compare/src/shape-component"
9
+ import * as models from "models"
10
+ import Params from "../../params"
11
+ import Text from "../../utils/text"
12
+ import useI18n from "i18n-on-steroids/src/use-i18n"
13
+
14
+ const {TableSearch} = models
15
+
16
+ const SearchLink = memo(shapeComponent(class SearchLink extends BaseComponent {
17
+ render() {
18
+ const {search} = this.props
19
+
20
+ return (
21
+ <View dataSet={{class: "search-row", searchId: search.id()}} style={{flexDirection: "row", width: "100%"}}>
22
+ <Pressable dataSet={{class: "load-search-link"}} onPress={this.onSearchClicked} style={{justifyContent: "center"}}>
23
+ <Text>
24
+ {search.name()}
25
+ </Text>
26
+ </Pressable>
27
+ <View style={{flexDirection: "row", marginLeft: "auto"}}>
28
+ <Pressable
29
+ dataSet={{class: "edit-search-button"}}
30
+ onPress={this.onEditPressed}
31
+ style={{
32
+ alignItems: "center",
33
+ justifyContent: "center",
34
+ width: 25,
35
+ height: 25,
36
+ backgroundColor: "#fff",
37
+ border: "1px solid #007bff",
38
+ borderRadius: 5,
39
+ color: "#007bff"
40
+ }}
41
+ >
42
+ <Text>
43
+ &#x270E;
44
+ </Text>
45
+ </Pressable>
46
+ <Pressable
47
+ dataSet={{class: "delete-search-button"}}
48
+ onPress={this.onDeletePressed}
49
+ style={{
50
+ alignItems: "center",
51
+ justifyContent: "center",
52
+ marginLeft: 5,
53
+ width: 25,
54
+ height: 25,
55
+ backgroundColor: "#fff",
56
+ border: "1px solid #dc3545",
57
+ borderRadius: 5,
58
+ color: "#dc3545"
59
+ }}
60
+ >
61
+ <Text>
62
+ &#x2715;
63
+ </Text>
64
+ </Pressable>
65
+ </View>
66
+ </View>
67
+ )
68
+ }
69
+
70
+ onDeletePressed = async () => {
71
+ if (!confirm("Are you sure?")) {
72
+ return
73
+ }
74
+
75
+ const {search} = this.props
76
+
77
+ await search.destroy()
78
+ this.props.onDeleted({search})
79
+ }
80
+
81
+ onEditPressed = () => this.props.onEditPressed({search: this.props.search})
82
+ onSearchClicked = () => this.props.onClick({search: this.props.search})
83
+ }))
84
+
85
+ export default memo(shapeComponent(class ApiMakerTableFiltersLoadSearchModal extends BaseComponent {
86
+ setup() {
87
+ const {t} = useI18n({namespace: "js.api_maker.table.filters.load_search_modal"})
88
+
89
+ this.useStates({
90
+ editSearch: undefined,
91
+ searches: undefined
92
+ })
93
+ this.setInstance({t})
94
+
95
+ useMemo(() => {
96
+ this.loadSearches()
97
+ }, [])
98
+ }
99
+
100
+ loadSearches = async () => {
101
+ const {currentUser} = this.props
102
+ const userType = digg(currentUser.modelClassData(), "name")
103
+ const searches = await TableSearch
104
+ .ransack({user_id_eq: currentUser.id(), user_type_eq: userType})
105
+ .toArray()
106
+
107
+ this.setState({searches})
108
+ }
109
+
110
+ render() {
111
+ const {t} = this
112
+ const {className, currentUser, modelClass, onEditSearchPressed, onRequestClose, querySearchName, ...restProps} = this.props
113
+ const Modal = apiMakerConfig.getModal()
114
+
115
+ return (
116
+ <Modal className={classNames("api-maker--table--filters--load-search-modal", className)} onRequestClose={onRequestClose} {...restProps}>
117
+ <View>
118
+ <Text>
119
+ {t(".choose_a_search", {defaultValue: "Choose a search"})}
120
+ </Text>
121
+ </View>
122
+ {this.state.searches?.map((search) =>
123
+ <SearchLink key={search.id()} onClick={this.onSearchClicked} onDeleted={this.onSearchDeleted} onEditPressed={onEditSearchPressed} search={search} />
124
+ )}
125
+ </Modal>
126
+ )
127
+ }
128
+
129
+ onSearchClicked = ({search}) => {
130
+ const {onRequestClose, querySearchName} = this.props
131
+ const queryParams = search.queryParams()
132
+ const newParams = {}
133
+
134
+ newParams[querySearchName] = queryParams.map((queryParam) => JSON.stringify(queryParam))
135
+
136
+ Params.changeParams(newParams)
137
+
138
+ onRequestClose()
139
+ }
140
+
141
+ onSearchDeleted = ({search}) => {
142
+ this.setState({
143
+ searches: this.state.searches.filter((existingSearch) => existingSearch.id() != search.id())
144
+ })
145
+ }
146
+ }))
@@ -0,0 +1,38 @@
1
+ import BaseComponent from "../../base-component"
2
+ import PropTypes from "prop-types"
3
+ import PropTypesExact from "prop-types-exact"
4
+ import memo from "set-state-compare/src/memo"
5
+ import {Pressable} from "react-native"
6
+ import React from "react"
7
+ import {shapeComponent} from "set-state-compare/src/shape-component"
8
+ import Text from "../../utils/text"
9
+
10
+ export default memo(shapeComponent(class ReflectionElement extends BaseComponent {
11
+ static propTypes = PropTypesExact({
12
+ modelClassName: PropTypes.string.isRequired,
13
+ onClick: PropTypes.func.isRequired,
14
+ reflection: PropTypes.object.isRequired
15
+ })
16
+
17
+ render() {
18
+ const {modelClassName, reflection} = this.p
19
+ const {humanName, reflectionName} = reflection
20
+
21
+ return (
22
+ <Pressable
23
+ dataSet={{
24
+ class: "reflection-element",
25
+ modelClass: modelClassName,
26
+ reflectionName
27
+ }}
28
+ onPress={this.tt.onReflectionClicked}
29
+ >
30
+ <Text>
31
+ {humanName}
32
+ </Text>
33
+ </Pressable>
34
+ )
35
+ }
36
+
37
+ onReflectionClicked = () => this.p.onClick({reflection: this.p.reflection})
38
+ }))
@@ -0,0 +1,74 @@
1
+ import apiMakerConfig from "@kaspernj/api-maker/build/config"
2
+ import BaseComponent from "../../base-component"
3
+ import Checkbox from "../../bootstrap/checkbox"
4
+ import {digg} from "diggerize"
5
+ import FlashMessage from "../../flash-message"
6
+ import {Form} from "../../form"
7
+ import Input from "../../bootstrap/input"
8
+ import modelClassRequire from "../../model-class-require"
9
+ import React from "react"
10
+ import {shapeComponent} from "set-state-compare/src/shape-component"
11
+ import memo from "set-state-compare/src/memo"
12
+ import useI18n from "i18n-on-steroids/src/use-i18n"
13
+
14
+ const TableSearch = modelClassRequire("TableSearch")
15
+
16
+ export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal extends BaseComponent {
17
+ setup() {
18
+ const {t} = useI18n({namespace: "js.api_maker.table.filters.save_search_modal"})
19
+
20
+ this.t = t
21
+ this.useStates({form: null})
22
+ }
23
+
24
+ render() {
25
+ const {currentFilters, currentUser, onRequestClose, search, ...restProps} = this.props
26
+ const Modal = apiMakerConfig.getModal()
27
+
28
+ return (
29
+ <Modal onRequestClose={onRequestClose} {...restProps}>
30
+ <Form onSubmit={this.tt.onSaveSearchSubmit} setForm={this.setStates.form}>
31
+ <Input
32
+ defaultValue={search.name()}
33
+ id="table_search_name"
34
+ label={this.t(".search_name", {defaultValue: "Search name"})}
35
+ name="table_search[name]"
36
+ />
37
+ <Checkbox
38
+ defaultChecked={search.public()}
39
+ id="table_search_public"
40
+ label={this.t(".public", {defaultValue: "Public"})}
41
+ name="table_search[public]"
42
+ />
43
+ <button className="save-search-submit-button">
44
+ {this.t(".save_search", {defaultValue: "Save search"})}
45
+ </button>
46
+ </Form>
47
+ </Modal>
48
+ )
49
+ }
50
+
51
+ onSaveSearchSubmit = async () => {
52
+ const formData = this.s.form.asObject()
53
+ const {currentFilters, currentUser, onRequestClose, search} = this.p
54
+ const hasUserTypeColumn = Boolean(TableSearch.attributes().find((attribute) => attribute.name() == "user_type"))
55
+
56
+ if (search.isNewRecord()) {
57
+ formData.table_search.query_params = JSON.stringify(currentFilters())
58
+ }
59
+
60
+ if (hasUserTypeColumn) {
61
+ formData.table_search.user_type = digg(currentUser.modelClassData(), "className")
62
+ }
63
+
64
+ formData.table_search.user_id = currentUser.id()
65
+
66
+ try {
67
+ await search.saveRaw(formData)
68
+ FlashMessage.success(this.t(".", {defaultValue: "The search was saved."}))
69
+ onRequestClose()
70
+ } catch (error) {
71
+ FlashMessage.errorResponse(error)
72
+ }
73
+ }
74
+ }))
@@ -0,0 +1,44 @@
1
+ import BaseComponent from "../../base-component"
2
+ import PropTypes from "prop-types"
3
+ import memo from "set-state-compare/src/memo"
4
+ import {Pressable} from "react-native"
5
+ import React from "react"
6
+ import {shapeComponent} from "set-state-compare/src/shape-component"
7
+ import Text from "../../utils/text"
8
+
9
+ export default memo(shapeComponent(class ScopeElement extends BaseComponent {
10
+ static defaultProps = {
11
+ active: false
12
+ }
13
+
14
+ static propTypes = {
15
+ active: PropTypes.bool.isRequired,
16
+ onScopeClicked: PropTypes.func.isRequired,
17
+ scope: PropTypes.string.isRequired
18
+ }
19
+
20
+ render() {
21
+ const {active, scope} = this.p
22
+ const style = {}
23
+
24
+ if (active) style.fontWeight = "bold"
25
+
26
+ return (
27
+ <Pressable
28
+ dataSet={{class: "scope-element", scopeName: scope}}
29
+ key={scope}
30
+ onPress={this.tt.onScopeClicked}
31
+ >
32
+ <Text style={style}>
33
+ {scope}
34
+ </Text>
35
+ </Pressable>
36
+ )
37
+ }
38
+
39
+ onScopeClicked = (e) => {
40
+ e.preventDefault()
41
+
42
+ this.p.onScopeClicked({scope: this.p.scope})
43
+ }
44
+ }))
@@ -0,0 +1,55 @@
1
+ import BaseComponent from "../base-component"
2
+ import {digs} from "diggerize"
3
+ import memo from "set-state-compare/src/memo"
4
+ import {View} from "react-native"
5
+ import PropTypes from "prop-types"
6
+ import propTypesExact from "prop-types-exact"
7
+ import React from "react"
8
+ import {shapeComponent} from "set-state-compare/src/shape-component"
9
+ import SortLink from "../bootstrap/sort-link"
10
+ import Text from "../utils/text"
11
+
12
+ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
13
+ static propTypes = propTypesExact({
14
+ column: PropTypes.object.isRequired,
15
+ sortLinkProps: PropTypes.object,
16
+ table: PropTypes.object.isRequired,
17
+ tableSettingColumn: PropTypes.object.isRequired
18
+ })
19
+
20
+ render() {
21
+ const {column, table, tableSettingColumn} = this.p
22
+ const {defaultParams} = table.props
23
+ const {styleForHeaderText} = table.tt
24
+ const {query} = digs(table.collection, "query")
25
+ const columnProps = table.columnProps(column)
26
+
27
+ return (
28
+ <View
29
+ dataSet={{
30
+ component: "api-maker/table/header-column-content",
31
+ identifier: tableSettingColumn.identifier()
32
+ }}
33
+ style={{display: "flex", flexDirection: "row", alignItems: "center"}}
34
+ {...columnProps}
35
+ >
36
+ {tableSettingColumn.hasSortKey() && query &&
37
+ <SortLink
38
+ attribute={tableSettingColumn.sortKey()}
39
+ defaultParams={defaultParams}
40
+ query={query}
41
+ style={{whiteSpace: "nowrap", overflow: "hidden"}}
42
+ textProps={{ellipsizeMode: "clip", numberOfLines: 1, style: styleForHeaderText()}}
43
+ title={table.headerLabelForColumn(column)}
44
+ {...this.props.sortLinkProps}
45
+ />
46
+ }
47
+ {(!tableSettingColumn.hasSortKey() || !query) &&
48
+ <Text ellipsizeMode="clip" numberOfLines={1} style={{fontWeight: "bold"}}>
49
+ {table.headerLabelForColumn(column)}
50
+ </Text>
51
+ }
52
+ </View>
53
+ )
54
+ }
55
+ }))
@@ -0,0 +1,129 @@
1
+ import React, {useMemo} from "react"
2
+ import BaseComponent from "../base-component"
3
+ import classNames from "classnames"
4
+ import Header from "./components/header"
5
+ import HeaderColumnContent from "./header-column-content"
6
+ import Icon from "../utils/icon"
7
+ import memo from "set-state-compare/src/memo"
8
+ import {Animated, PanResponder} from "react-native"
9
+ import PropTypes from "prop-types"
10
+ import propTypesExact from "prop-types-exact"
11
+ import {shapeComponent} from "set-state-compare/src/shape-component"
12
+ import useBreakpoint from "../use-breakpoint"
13
+ import Widths from "./widths"
14
+
15
+ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
16
+ static propTypes = propTypesExact({
17
+ active: PropTypes.bool.isRequired,
18
+ animatedWidth: PropTypes.instanceOf(Animated.Value).isRequired,
19
+ animatedZIndex: PropTypes.instanceOf(Animated.Value).isRequired,
20
+ column: PropTypes.object.isRequired,
21
+ resizing: PropTypes.bool.isRequired,
22
+ table: PropTypes.object.isRequired,
23
+ tableSettingColumn: PropTypes.object.isRequired,
24
+ touchProps: PropTypes.object.isRequired,
25
+ widths: PropTypes.instanceOf(Widths).isRequired
26
+ })
27
+
28
+ setup() {
29
+ const {name: breakpoint, mdUp, smDown} = useBreakpoint()
30
+
31
+ this.setInstance({breakpoint, mdUp, smDown})
32
+ this.useStates({
33
+ resizing: false
34
+ })
35
+
36
+ this.resizePanResponder = useMemo(
37
+ () => PanResponder.create({
38
+ onStartShouldSetPanResponder: (_e) => {
39
+ this.originalWidth = this.currentWidth
40
+ this.setState({resizing: true})
41
+ this.p.table.setState({resizing: true})
42
+
43
+ return true
44
+ },
45
+ onPanResponderMove: (_e, gestate) => {
46
+ const newWidth = this.tt.originalWidth + gestate.dx
47
+
48
+ this.p.widths.setWidthOfColumn({
49
+ identifier: this.p.tableSettingColumn.identifier(),
50
+ width: newWidth
51
+ })
52
+ },
53
+ onPanResponderRelease: this.tt.onResizeEnd,
54
+ onPanResponderTerminate: this.tt.onResizeEnd,
55
+ onPanResponderTerminationRequest: () => false // Don't let another PanResponder steal focus and stop resizing until release
56
+ }),
57
+ []
58
+ )
59
+ }
60
+
61
+ onResizeEnd = async () => {
62
+ this.p.table.setState({lastUpdate: new Date(), resizing: false})
63
+ this.setState({resizing: false})
64
+
65
+ const width = this.p.widths.getWidthOfColumn(this.p.tableSettingColumn.identifier())
66
+
67
+ await this.p.tableSettingColumn.update({width})
68
+ }
69
+
70
+ render() {
71
+ const {mdUp} = this.tt
72
+ const {active, animatedWidth, column, resizing, table, tableSettingColumn, touchProps} = this.p
73
+ const {styleForHeader} = table.tt
74
+ const headerProps = table.headerProps(column)
75
+ const {style, ...restColumnProps} = headerProps
76
+ const actualStyle = useMemo(
77
+ () => {
78
+ const actualStyle = Object.assign(
79
+ {
80
+ cursor: resizing ? "col-resize" : undefined,
81
+ width: mdUp ? animatedWidth : "100%",
82
+ height: mdUp ? "100%" : undefined
83
+ },
84
+ style
85
+ )
86
+
87
+ return actualStyle
88
+ },
89
+ [active, animatedWidth, mdUp, resizing, style]
90
+ )
91
+
92
+ return (
93
+ <Header
94
+ dataSet={{
95
+ className: classNames(...table.headerClassNameForColumn(column)),
96
+ identifier: tableSettingColumn.identifier()
97
+ }}
98
+ onLayout={this.tt.onLayout}
99
+ style={styleForHeader({style: actualStyle})}
100
+ {...restColumnProps}
101
+ >
102
+ {mdUp &&
103
+ <Icon name="bars" style={{marginRight: 3, fontSize: 12}} {...touchProps} />
104
+ }
105
+ <HeaderColumnContent column={column} table={table} tableSettingColumn={tableSettingColumn} />
106
+ {mdUp &&
107
+ <Animated.View
108
+ style={{
109
+ position: "absolute",
110
+ top: 0,
111
+ right: 0,
112
+ width: 10,
113
+ height: "100%",
114
+ cursor: "col-resize",
115
+ zIndex: 9999
116
+ }}
117
+ {...this.tt.resizePanResponder.panHandlers}
118
+ />
119
+ }
120
+ </Header>
121
+ )
122
+ }
123
+
124
+ onLayout = (e) => {
125
+ const {width} = e.nativeEvent.layout
126
+
127
+ this.currentWidth = width
128
+ }
129
+ }))