avo 2.16.0 → 2.16.1.pre.1.nativefields

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -2
  3. data/Gemfile.lock +78 -86
  4. data/app/components/avo/base_component.rb +7 -1
  5. data/app/components/avo/field_wrapper_component.html.erb +40 -0
  6. data/app/components/avo/field_wrapper_component.rb +102 -0
  7. data/app/components/avo/fields/badge_field/show_component.html.erb +1 -1
  8. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +3 -3
  9. data/app/components/avo/fields/belongs_to_field/show_component.html.erb +1 -1
  10. data/app/components/avo/fields/boolean_field/edit_component.html.erb +1 -1
  11. data/app/components/avo/fields/boolean_field/show_component.html.erb +1 -1
  12. data/app/components/avo/fields/boolean_group_field/edit_component.html.erb +1 -1
  13. data/app/components/avo/fields/boolean_group_field/show_component.html.erb +1 -1
  14. data/app/components/avo/fields/code_field/edit_component.html.erb +2 -2
  15. data/app/components/avo/fields/code_field/show_component.html.erb +2 -2
  16. data/app/components/avo/fields/country_field/edit_component.html.erb +1 -1
  17. data/app/components/avo/fields/country_field/show_component.html.erb +1 -1
  18. data/app/components/avo/fields/date_field/edit_component.html.erb +1 -1
  19. data/app/components/avo/fields/date_field/show_component.html.erb +1 -1
  20. data/app/components/avo/fields/date_time_field/edit_component.html.erb +1 -1
  21. data/app/components/avo/fields/date_time_field/show_component.html.erb +1 -1
  22. data/app/components/avo/fields/edit_component.rb +22 -4
  23. data/app/components/avo/fields/external_image_field/edit_component.html.erb +1 -1
  24. data/app/components/avo/fields/external_image_field/show_component.html.erb +1 -1
  25. data/app/components/avo/fields/file_field/edit_component.html.erb +1 -1
  26. data/app/components/avo/fields/file_field/show_component.html.erb +1 -1
  27. data/app/components/avo/fields/files_field/edit_component.html.erb +1 -1
  28. data/app/components/avo/fields/files_field/show_component.html.erb +1 -1
  29. data/app/components/avo/fields/gravatar_field/show_component.html.erb +1 -1
  30. data/app/components/avo/fields/id_field/edit_component.html.erb +1 -1
  31. data/app/components/avo/fields/id_field/show_component.html.erb +1 -1
  32. data/app/components/avo/fields/key_value_field/edit_component.html.erb +2 -2
  33. data/app/components/avo/fields/key_value_field/show_component.html.erb +1 -1
  34. data/app/components/avo/fields/markdown_field/edit_component.html.erb +2 -2
  35. data/app/components/avo/fields/markdown_field/show_component.html.erb +1 -1
  36. data/app/components/avo/fields/number_field/edit_component.html.erb +1 -1
  37. data/app/components/avo/fields/number_field/show_component.html.erb +1 -1
  38. data/app/components/avo/fields/password_field/edit_component.html.erb +1 -1
  39. data/app/components/avo/fields/progress_bar_field/edit_component.html.erb +1 -1
  40. data/app/components/avo/fields/progress_bar_field/show_component.html.erb +1 -1
  41. data/app/components/avo/fields/select_field/edit_component.html.erb +1 -2
  42. data/app/components/avo/fields/select_field/show_component.html.erb +1 -1
  43. data/app/components/avo/fields/show_component.rb +36 -1
  44. data/app/components/avo/fields/status_field/edit_component.html.erb +1 -1
  45. data/app/components/avo/fields/status_field/show_component.html.erb +1 -1
  46. data/app/components/avo/fields/tags_field/edit_component.html.erb +1 -5
  47. data/app/components/avo/fields/tags_field/show_component.html.erb +1 -1
  48. data/app/components/avo/fields/text_field/edit_component.html.erb +2 -2
  49. data/app/components/avo/fields/text_field/show_component.html.erb +1 -1
  50. data/app/components/avo/fields/textarea_field/edit_component.html.erb +1 -1
  51. data/app/components/avo/fields/textarea_field/show_component.html.erb +1 -1
  52. data/app/components/avo/fields/trix_field/edit_component.html.erb +2 -2
  53. data/app/components/avo/fields/trix_field/edit_component.rb +19 -1
  54. data/app/components/avo/fields/trix_field/show_component.html.erb +1 -1
  55. data/app/components/avo/index/resource_controls_component.rb +1 -0
  56. data/app/components/avo/views/resource_edit_component.html.erb +28 -26
  57. data/app/controllers/avo/application_controller.rb +8 -1
  58. data/app/controllers/avo/base_controller.rb +5 -5
  59. data/app/helpers/avo/application_helper.rb +31 -3
  60. data/app/helpers/avo/resources_helper.rb +4 -8
  61. data/app/javascript/js/controllers/action_controller.js +3 -1
  62. data/app/javascript/js/controllers/fields/date_field_controller.js +21 -1
  63. data/app/javascript/js/controllers/search_controller.js +122 -118
  64. data/avo.gemspec +1 -1
  65. data/config/master.key +1 -0
  66. data/lib/avo/base_resource.rb +5 -3
  67. data/lib/avo/concerns/fetches_things.rb +2 -0
  68. data/lib/avo/fields/base_field.rb +4 -0
  69. data/lib/avo/fields/select_field.rb +1 -0
  70. data/lib/avo/menu/menu.rb +2 -0
  71. data/lib/avo/services/authorization_service.rb +24 -20
  72. data/lib/avo/version.rb +1 -1
  73. data/lib/generators/avo/templates/field/components/edit_component.html.erb.tt +1 -1
  74. data/lib/generators/avo/templates/field/components/show_component.html.erb.tt +1 -1
  75. data/public/avo-assets/avo.base.css +26 -8
  76. data/public/avo-assets/avo.base.js +79 -79
  77. data/public/avo-assets/avo.base.js.map +3 -3
  78. metadata +8 -11
  79. data/app/components/avo/common_field_wrapper_component.html.erb +0 -26
  80. data/app/components/avo/common_field_wrapper_component.rb +0 -46
  81. data/app/components/avo/edit/field_wrapper_component.html.erb +0 -11
  82. data/app/components/avo/edit/field_wrapper_component.rb +0 -21
  83. data/app/components/avo/show/field_wrapper_component.html.erb +0 -9
  84. data/app/components/avo/show/field_wrapper_component.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ca4190d675e166dedf5f47c9c68f3b7fa57e29c9e7510262a4033f1c0cbb00d
4
- data.tar.gz: 6f4f3c3f1a39fbb7b9d3566ff679cd3992b684576b1e4c1451b7d4fdd39c173f
3
+ metadata.gz: 9faaa635bf77fa6bd6267dedf2a72bea08eb21c84714da5614be28df50da9028
4
+ data.tar.gz: 34418d8586a608efdcaf5b44c4cd98450578c0719e731d3534ac243681d3b994
5
5
  SHA512:
6
- metadata.gz: c2dfc8a393554111f16a4c95ed94ef1180e9b448327d182071ebef301773e37436db614411121744107bae9252e40a5432d828ebb2661abef2148883e0675c08
7
- data.tar.gz: 3914b51410ba770dd7f8a396bddfb6bb1be58d694aebb159f23b3de1e3c841186fa85d62bf0d982ef475a5a07c80bd9f24a4cf41d0b22a874e4df073dc11da25
6
+ metadata.gz: 638a6f1809a1e379206d0358b8f8cb5767f53b3a8b5db8d61aa175744dd641c5332349d6108eb8565eae26b8629b9744da3549559243a4ced410a1b01cd41296
7
+ data.tar.gz: 3565f031cabab8fc386cab48276bfeb54592a45d5fdea58c5541935f4ebfed684223fdaf80baf26f5fb321641cb20644660abb70ca15400386dbaf9d9b5ee895
data/Gemfile CHANGED
@@ -117,8 +117,6 @@ gem "httparty"
117
117
 
118
118
  gem "iso"
119
119
 
120
- gem "hotwire-rails"
121
-
122
120
  gem "active_link_to"
123
121
 
124
122
  gem "addressable"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- avo (2.16.0)
4
+ avo (2.16.1.pre.1.nativefields)
5
5
  active_link_to
6
6
  addressable
7
7
  breadcrumbs_on_rails
@@ -9,7 +9,6 @@ PATH
9
9
  countries
10
10
  docile
11
11
  dry-initializer
12
- hotwire-rails
13
12
  httparty
14
13
  image_processing
15
14
  inline_svg
@@ -17,6 +16,7 @@ PATH
17
16
  pagy
18
17
  pundit
19
18
  rails (>= 6.0)
19
+ turbo-rails
20
20
  view_component (= 2.60)
21
21
  zeitwerk
22
22
 
@@ -91,8 +91,8 @@ GEM
91
91
  activerecord (>= 6.0, < 7.1)
92
92
  acts_as_list (1.0.4)
93
93
  activerecord (>= 4.2)
94
- addressable (2.8.0)
95
- public_suffix (>= 2.0.2, < 5.0)
94
+ addressable (2.8.1)
95
+ public_suffix (>= 2.0.2, < 6.0)
96
96
  annotate (3.2.0)
97
97
  activerecord (>= 3.2, < 8.0)
98
98
  rake (>= 10.4, < 14.0)
@@ -103,30 +103,30 @@ GEM
103
103
  ast (2.4.2)
104
104
  awesome_print (1.9.2)
105
105
  aws-eventstream (1.2.0)
106
- aws-partitions (1.551.0)
107
- aws-sdk-core (3.125.5)
106
+ aws-partitions (1.621.0)
107
+ aws-sdk-core (3.134.0)
108
108
  aws-eventstream (~> 1, >= 1.0.2)
109
109
  aws-partitions (~> 1, >= 1.525.0)
110
110
  aws-sigv4 (~> 1.1)
111
- jmespath (~> 1.0)
112
- aws-sdk-kms (1.53.0)
113
- aws-sdk-core (~> 3, >= 3.125.0)
111
+ jmespath (~> 1, >= 1.6.1)
112
+ aws-sdk-kms (1.58.0)
113
+ aws-sdk-core (~> 3, >= 3.127.0)
114
114
  aws-sigv4 (~> 1.1)
115
- aws-sdk-s3 (1.111.3)
116
- aws-sdk-core (~> 3, >= 3.125.0)
115
+ aws-sdk-s3 (1.114.0)
116
+ aws-sdk-core (~> 3, >= 3.127.0)
117
117
  aws-sdk-kms (~> 1)
118
118
  aws-sigv4 (~> 1.4)
119
- aws-sigv4 (1.4.0)
119
+ aws-sigv4 (1.5.1)
120
120
  aws-eventstream (~> 1, >= 1.0.2)
121
- bcrypt (3.1.16)
121
+ bcrypt (3.1.18)
122
122
  bindex (0.8.1)
123
- bootsnap (1.10.3)
123
+ bootsnap (1.13.0)
124
124
  msgpack (~> 1.2)
125
125
  breadcrumbs_on_rails (4.1.0)
126
126
  railties (>= 5.0)
127
127
  builder (3.2.4)
128
128
  bump (0.10.0)
129
- bundler-integrity (1.0.7)
129
+ bundler-integrity (1.0.9)
130
130
  byebug (11.1.3)
131
131
  capybara (3.36.0)
132
132
  addressable
@@ -140,13 +140,12 @@ GEM
140
140
  chartkick (4.2.1)
141
141
  childprocess (4.1.0)
142
142
  concurrent-ruby (1.1.10)
143
- countries (4.2.1)
144
- i18n_data (~> 0.15.0)
143
+ countries (5.1.2)
145
144
  sixarm_ruby_unaccent (~> 1.1)
146
145
  crack (0.4.5)
147
146
  rexml
148
147
  crass (1.0.6)
149
- cssbundling-rails (1.0.0)
148
+ cssbundling-rails (1.1.1)
150
149
  railties (>= 6.0.0)
151
150
  database_cleaner (2.0.1)
152
151
  database_cleaner-active_record (~> 2.0.0)
@@ -163,20 +162,20 @@ GEM
163
162
  diff-lcs (1.5.0)
164
163
  digest (3.1.0)
165
164
  docile (1.4.0)
166
- dotenv (2.7.6)
167
- dotenv-rails (2.7.6)
168
- dotenv (= 2.7.6)
165
+ dotenv (2.8.1)
166
+ dotenv-rails (2.8.1)
167
+ dotenv (= 2.8.1)
169
168
  railties (>= 3.2)
170
169
  dry-initializer (3.1.1)
171
170
  erb-formatter (0.3.0)
172
- erubi (1.10.0)
173
- factory_bot (6.2.0)
171
+ erubi (1.11.0)
172
+ factory_bot (6.2.1)
174
173
  activesupport (>= 5.0.0)
175
174
  factory_bot_rails (6.2.0)
176
175
  factory_bot (~> 6.2.0)
177
176
  railties (>= 5.0.0)
178
- faker (2.19.0)
179
- i18n (>= 1.6, < 2)
177
+ faker (2.22.0)
178
+ i18n (>= 1.8.11, < 2)
180
179
  ffi (1.15.5)
181
180
  friendly_id (5.4.2)
182
181
  activerecord (>= 4.0.0)
@@ -186,44 +185,38 @@ GEM
186
185
  gem-release (2.2.2)
187
186
  globalid (1.0.0)
188
187
  activesupport (>= 5.0)
189
- groupdate (5.2.4)
190
- activesupport (>= 5)
188
+ groupdate (6.1.0)
189
+ activesupport (>= 5.2)
191
190
  hashdiff (1.0.1)
192
191
  hightop (0.3.0)
193
192
  activesupport (>= 5.2)
194
- hotwire-livereload (1.1.0)
193
+ hotwire-livereload (1.2.2)
195
194
  listen (>= 3.0.0)
196
195
  rails (>= 6.0.0)
197
- hotwire-rails (0.1.3)
198
- rails (>= 6.0.0)
199
- stimulus-rails
200
- turbo-rails
201
- htmlbeautifier (1.4.1)
196
+ htmlbeautifier (1.4.2)
202
197
  httparty (0.20.0)
203
198
  mime-types (~> 3.0)
204
199
  multi_xml (>= 0.5.2)
205
200
  i18n (1.12.0)
206
201
  concurrent-ruby (~> 1.0)
207
- i18n_data (0.15.0)
208
- simple_po_parser (~> 1.1)
209
202
  image_processing (1.12.2)
210
203
  mini_magick (>= 4.9.5, < 5)
211
204
  ruby-vips (>= 2.0.17, < 3)
212
205
  inline_svg (1.8.0)
213
206
  activesupport (>= 3.0)
214
207
  nokogiri (>= 1.6)
215
- io-wait (0.2.1)
216
208
  iso (0.4.0)
217
209
  i18n
218
210
  jmespath (1.6.1)
219
- jsbundling-rails (1.0.0)
211
+ jsbundling-rails (1.0.3)
220
212
  railties (>= 6.0.0)
213
+ json (2.6.2)
221
214
  launchy (2.5.0)
222
215
  addressable (~> 2.7)
223
216
  listen (3.7.1)
224
217
  rb-fsevent (~> 0.10, >= 0.10.3)
225
218
  rb-inotify (~> 0.9, >= 0.9.10)
226
- loofah (2.18.0)
219
+ loofah (2.19.0)
227
220
  crass (~> 1.0.2)
228
221
  nokogiri (>= 1.5.9)
229
222
  mail (2.7.1)
@@ -233,7 +226,7 @@ GEM
233
226
  zeitwerk
234
227
  marcel (1.0.2)
235
228
  matrix (0.4.2)
236
- meta-tags (2.16.0)
229
+ meta-tags (2.17.0)
237
230
  actionpack (>= 3.2.0, < 7.1)
238
231
  method_source (1.0.0)
239
232
  mime-types (3.4.1)
@@ -242,29 +235,28 @@ GEM
242
235
  mini_magick (4.11.0)
243
236
  mini_mime (1.1.2)
244
237
  mini_portile2 (2.8.0)
245
- minitest (5.16.2)
246
- msgpack (1.4.4)
238
+ minitest (5.16.3)
239
+ msgpack (1.5.6)
247
240
  multi_xml (0.6.0)
248
- net-protocol (0.1.2)
249
- io-wait
241
+ net-protocol (0.1.3)
250
242
  timeout
251
243
  net-smtp (0.3.1)
252
244
  digest
253
245
  net-protocol
254
246
  timeout
255
247
  nio4r (2.5.8)
256
- nokogiri (1.13.7)
248
+ nokogiri (1.13.8)
257
249
  mini_portile2 (~> 2.8.0)
258
250
  racc (~> 1.4)
259
251
  orm_adapter (0.5.0)
260
252
  pagy (5.10.1)
261
253
  activesupport
262
- parallel (1.21.0)
263
- parser (3.1.0.0)
254
+ parallel (1.22.1)
255
+ parser (3.1.2.1)
264
256
  ast (~> 2.4.1)
265
- pg (1.3.1)
266
- public_suffix (4.0.6)
267
- puma (5.6.4)
257
+ pg (1.4.3)
258
+ public_suffix (5.0.0)
259
+ puma (5.6.5)
268
260
  nio4r (~> 2.0)
269
261
  pundit (2.2.0)
270
262
  activesupport (>= 3.0.0)
@@ -304,27 +296,27 @@ GEM
304
296
  thor (~> 1.0)
305
297
  rainbow (3.1.1)
306
298
  rake (13.0.6)
307
- ransack (2.5.0)
308
- activerecord (>= 5.2.4)
309
- activesupport (>= 5.2.4)
299
+ ransack (3.2.1)
300
+ activerecord (>= 6.1.5)
301
+ activesupport (>= 6.1.5)
310
302
  i18n
311
- rb-fsevent (0.11.0)
303
+ rb-fsevent (0.11.1)
312
304
  rb-inotify (0.10.1)
313
305
  ffi (~> 1.0)
314
- redis (4.6.0)
315
- regexp_parser (2.2.0)
306
+ redis (4.8.0)
307
+ regexp_parser (2.5.0)
316
308
  responders (3.0.1)
317
309
  actionpack (>= 5.0)
318
310
  railties (>= 5.0)
319
311
  rexml (3.2.5)
320
- rspec-core (3.10.2)
321
- rspec-support (~> 3.10.0)
322
- rspec-expectations (3.10.2)
312
+ rspec-core (3.11.0)
313
+ rspec-support (~> 3.11.0)
314
+ rspec-expectations (3.11.0)
323
315
  diff-lcs (>= 1.2.0, < 2.0)
324
- rspec-support (~> 3.10.0)
325
- rspec-mocks (3.10.3)
316
+ rspec-support (~> 3.11.0)
317
+ rspec-mocks (3.11.1)
326
318
  diff-lcs (>= 1.2.0, < 2.0)
327
- rspec-support (~> 3.10.0)
319
+ rspec-support (~> 3.11.0)
328
320
  rspec-rails (4.0.2)
329
321
  actionpack (>= 4.2)
330
322
  activesupport (>= 4.2)
@@ -333,34 +325,35 @@ GEM
333
325
  rspec-expectations (~> 3.10)
334
326
  rspec-mocks (~> 3.10)
335
327
  rspec-support (~> 3.10)
336
- rspec-support (3.10.3)
337
- rubocop (1.25.0)
328
+ rspec-support (3.11.0)
329
+ rubocop (1.35.0)
330
+ json (~> 2.3)
338
331
  parallel (~> 1.10)
339
- parser (>= 3.1.0.0)
332
+ parser (>= 3.1.2.1)
340
333
  rainbow (>= 2.2.2, < 4.0)
341
334
  regexp_parser (>= 1.8, < 3.0)
342
- rexml
343
- rubocop-ast (>= 1.15.1, < 2.0)
335
+ rexml (>= 3.2.5, < 4.0)
336
+ rubocop-ast (>= 1.20.1, < 2.0)
344
337
  ruby-progressbar (~> 1.7)
345
338
  unicode-display_width (>= 1.4.0, < 3.0)
346
- rubocop-ast (1.15.1)
347
- parser (>= 3.0.1.1)
348
- rubocop-performance (1.13.2)
339
+ rubocop-ast (1.21.0)
340
+ parser (>= 3.1.1.0)
341
+ rubocop-performance (1.14.3)
349
342
  rubocop (>= 1.7.0, < 2.0)
350
343
  rubocop-ast (>= 0.4.0)
351
- rubocop-shopify (2.5.0)
352
- rubocop (~> 1.25)
344
+ rubocop-shopify (2.9.0)
345
+ rubocop (~> 1.33)
353
346
  ruby-debug-ide (0.7.3)
354
347
  rake (>= 0.8.1)
355
348
  ruby-progressbar (1.11.0)
356
349
  ruby-vips (2.1.4)
357
350
  ffi (~> 1.12)
358
351
  rubyzip (2.3.2)
359
- selenium-webdriver (4.1.0)
352
+ selenium-webdriver (4.4.0)
360
353
  childprocess (>= 0.5, < 5.0)
361
354
  rexml (~> 3.2, >= 3.2.5)
362
- rubyzip (>= 1.2.2)
363
- simple_po_parser (1.1.5)
355
+ rubyzip (>= 1.2.2, < 3.0)
356
+ websocket (~> 1.0)
364
357
  simplecov (0.21.2)
365
358
  docile (~> 1.1)
366
359
  simplecov-html (~> 0.11)
@@ -369,7 +362,7 @@ GEM
369
362
  rexml
370
363
  simplecov (~> 0.19)
371
364
  simplecov-html (0.12.3)
372
- simplecov_json_formatter (0.1.3)
365
+ simplecov_json_formatter (0.1.4)
373
366
  sixarm_ruby_unaccent (1.2.0)
374
367
  spring (4.0.0)
375
368
  spring-commands-rspec (1.0.4)
@@ -381,20 +374,19 @@ GEM
381
374
  actionpack (>= 5.2)
382
375
  activesupport (>= 5.2)
383
376
  sprockets (>= 3.0.0)
384
- standard (1.7.0)
385
- rubocop (= 1.25.0)
386
- rubocop-performance (= 1.13.2)
387
- stimulus-rails (1.0.2)
388
- railties (>= 6.0.0)
389
- test-prof (1.0.7)
377
+ standard (1.16.0)
378
+ rubocop (= 1.35.0)
379
+ rubocop-performance (= 1.14.3)
380
+ test-prof (1.0.10)
390
381
  thor (1.2.1)
391
- timeout (0.2.0)
392
- turbo-rails (1.0.1)
382
+ timeout (0.3.0)
383
+ turbo-rails (1.3.0)
393
384
  actionpack (>= 6.0.0)
385
+ activejob (>= 6.0.0)
394
386
  railties (>= 6.0.0)
395
387
  tzinfo (2.0.5)
396
388
  concurrent-ruby (~> 1.0)
397
- unicode-display_width (2.1.0)
389
+ unicode-display_width (2.2.0)
398
390
  view_component (2.60.0)
399
391
  activesupport (>= 5.0.0, < 8.0)
400
392
  method_source (~> 1.0)
@@ -409,10 +401,11 @@ GEM
409
401
  nokogiri (~> 1.6)
410
402
  rubyzip (>= 1.3.0)
411
403
  selenium-webdriver (~> 4.0)
412
- webmock (3.14.0)
404
+ webmock (3.18.1)
413
405
  addressable (>= 2.8.0)
414
406
  crack (>= 0.3.2)
415
407
  hashdiff (>= 0.4.0, < 2.0.0)
408
+ websocket (1.2.9)
416
409
  websocket-driver (0.7.5)
417
410
  websocket-extensions (>= 0.1.0)
418
411
  websocket-extensions (0.1.5)
@@ -455,7 +448,6 @@ DEPENDENCIES
455
448
  groupdate
456
449
  hightop
457
450
  hotwire-livereload (~> 1.1)
458
- hotwire-rails
459
451
  htmlbeautifier
460
452
  httparty
461
453
  image_processing (~> 1.12)
@@ -16,9 +16,15 @@ class Avo::BaseComponent < ViewComponent::Base
16
16
  nil
17
17
  end
18
18
 
19
+ # Fetch the resource and hydrate it with the model
19
20
  def relation_resource
20
21
  model = params[:via_resource_class] || params[:via_relation_class]
21
- ::Avo::App.get_resource_by_model_name model.safe_constantize
22
+ model_klass = model.safe_constantize
23
+
24
+ resource = ::Avo::App.get_resource_by_model_name model_klass
25
+ model = model_klass.find params[:via_resource_id]
26
+
27
+ resource.dup.hydrate model: model
22
28
  end
23
29
 
24
30
  # Get the resource for the resource using the klass attribute so we get the namespace too
@@ -0,0 +1,40 @@
1
+ <%= content_tag :div,
2
+ class: classes,
3
+ style: style,
4
+ data: data do %>
5
+ <div class="h-full pt-4 md:pt-0 md:h-14 flex self-start items-center text-slate-800">
6
+ <div class="<% if displayed_in_modal %> md:w-48 <% else %> md:w-64 px-6 md:px-6 <% end %> w-48 flex uppercase font-semibold text-gray-500 text-sm" data-slot="label">
7
+ <% if form.present? %>
8
+ <%= form.label field.id, label %>
9
+ <% else %>
10
+ <%= field.name %>
11
+ <% end %>
12
+ <% if on_edit? && field.is_required? %> <span class="text-red-600 ml-1">*</span> <% end %>
13
+ </div>
14
+ </div>
15
+ <div class="flex-1 flex flex-row md:min-h-inherit py-2 <% unless displayed_in_modal %> px-6 <% end %>">
16
+ <% if on_show? %>
17
+ <div class="self-center <% if full_width %> w-full <% else %> w-full md:w-8/12 <% end %>" data-slot="value">
18
+ <% if field.value.blank? and dash_if_blank %>
19
+
20
+ <% else %>
21
+ <%= content %>
22
+ <% end %>
23
+ </div>
24
+ <% elsif on_edit? %>
25
+ <div class="self-center <% if displayed_in_modal or full_width or compact? %> w-full <% else %> w-full md:w-8/12 <% end %>" data-slot="value">
26
+ <%= content %>
27
+ <% if record.present? and record.errors.include? field.id %>
28
+ <div class="text-red-600 mt-2 text-sm"><%= record.errors.full_messages_for(field.id).to_sentence %></div>
29
+ <% end %>
30
+ <% if help.present? %>
31
+ <div class="text-gray-600 mt-2 text-sm"><%== help %></div>
32
+ <% end %>
33
+ </div>
34
+ <% end %>
35
+ </div>
36
+ <% if params[:avo_debug].present? %>
37
+ <!-- Raw value: -->
38
+ <!-- <%== field.value.inspect %> -->
39
+ <% end %>
40
+ <% end %>
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Avo::FieldWrapperComponent < ViewComponent::Base
4
+ # attr_reader :classes
5
+ attr_reader :dash_if_blank
6
+ # attr_reader :data
7
+ attr_reader :displayed_in_modal
8
+ # attr_reader :help
9
+ attr_reader :field
10
+ attr_reader :form
11
+ attr_reader :full_width
12
+ # attr_reader :label
13
+ attr_reader :resource
14
+ # attr_reader :record
15
+ # attr_reader :style
16
+ attr_reader :view
17
+
18
+ def initialize(
19
+ compact: false,
20
+ dash_if_blank: true,
21
+ data: {},
22
+ displayed_in_modal: false,
23
+ help: nil, # do we really need it?
24
+ field: nil,
25
+ form: nil,
26
+ full_width: false,
27
+ label: nil, # do we really need it?
28
+ resource: nil,
29
+ style: "",
30
+ view: :show,
31
+ **args
32
+ )
33
+ @args = args
34
+ @classes = args[:class].present? ? args[:class] : ""
35
+ @compact = compact
36
+ @dash_if_blank = dash_if_blank
37
+ @data = data
38
+ @displayed_in_modal = displayed_in_modal
39
+ @help = help
40
+ @field = field
41
+ @form = form
42
+ @full_width = full_width
43
+ @label = label
44
+ @resource = resource
45
+ @style = style
46
+ @view = view
47
+ end
48
+
49
+ def classes(extra_classes = "")
50
+ "relative flex flex-col flex-grow pb-2 md:pb-0 leading-tight min-h-14 #{compact? ? "" : "md:flex-row md:items-center"} #{@classes || ""} #{extra_classes || ""} #{@field.get_html(:classes, view: view, element: :wrapper)}"
51
+ end
52
+
53
+ def style
54
+ "#{@style} #{@field.get_html(:style, view: view, element: :wrapper)}"
55
+ end
56
+
57
+ def label
58
+ @label || @field.name
59
+ end
60
+
61
+ def on_show?
62
+ view == :show
63
+ end
64
+
65
+ def on_edit?
66
+ view == :edit
67
+ end
68
+
69
+ def help
70
+ @help || @field.help
71
+ end
72
+
73
+ def record
74
+ resource.present? ? resource.model : nil
75
+ end
76
+
77
+ def data
78
+ attributes = {
79
+ field_id: @field.id,
80
+ field_type: @field.type
81
+ }
82
+
83
+ # Add the built-in stimulus integration data tags.
84
+ if @resource.present?
85
+ @resource.get_stimulus_controllers.split(" ").each do |controller|
86
+ attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
87
+ end
88
+ end
89
+
90
+ # Fetch the data attributes off the html option
91
+ wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper
92
+ if wrapper_data_attributes.present?
93
+ attributes.merge! wrapper_data_attributes
94
+ end
95
+
96
+ attributes
97
+ end
98
+
99
+ def compact?
100
+ @compact
101
+ end
102
+ end
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= render Avo::Fields::Common::BadgeViewerComponent.new value: @field.value, options: @field.options %>
3
3
  <% end %>
@@ -12,7 +12,7 @@
12
12
  data-association="<%= @field.id %>"
13
13
  data-association-class="<%= @field&.target_resource&.model_class || nil %>"
14
14
  >
15
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, help: @field.polymorphic_help || '' do %>
15
+ <%= field_wrapper **field_wrapper_args, help: @field.polymorphic_help || '' do %>
16
16
  <%= @form.select @field.type_input_foreign_key, @field.types.map { |type| [::Avo::App.get_resource_by_model_name(type.to_s).name, type.to_s] },
17
17
  {
18
18
  value: @field.value,
@@ -40,7 +40,7 @@
40
40
  data-belongs-to-field-target="type"
41
41
  data-type="<%= type %>"
42
42
  >
43
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, label: ::Avo::App.get_resource_by_model_name(type.to_s).name do %>
43
+ <%= field_wrapper **field_wrapper_args, label: ::Avo::App.get_resource_by_model_name(type.to_s).name do %>
44
44
  <% if @field.searchable %>
45
45
  <%= render Avo::Fields::BelongsToField::AutocompleteComponent.new form: @form,
46
46
  disabled: disabled,
@@ -79,7 +79,7 @@
79
79
  <% end %>
80
80
  </div>
81
81
  <% else %>
82
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
82
+ <%= field_wrapper **field_wrapper_args do %>
83
83
  <% if @field.searchable %>
84
84
  <%= render Avo::Fields::BelongsToField::AutocompleteComponent.new form: @form,
85
85
  field: @field,
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= link_to @field.label, resource_view_path %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, dash_if_blank: false, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args, dash_if_blank: false do %>
2
2
  <div class="h-8 flex items-center">
3
3
  <%= @form.check_box @field.id,
4
4
  checked: @field.value,
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index, dash_if_blank: false do %>
1
+ <%= field_wrapper **field_wrapper_args, dash_if_blank: false do %>
2
2
  <%= render Avo::Fields::Common::BooleanCheckComponent.new checked: @field.value %>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <div class="flex items-center">
3
3
  <div class="space-y-2">
4
4
  <% model_param_key = model_name_from_record_or_class(@resource.model).param_key %>
@@ -1,3 +1,3 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index, dash_if_blank: false do %>
1
+ <%= field_wrapper **field_wrapper_args, dash_if_blank: false do %>
2
2
  <%= render Avo::Fields::Common::BooleanGroupComponent.new options: @field.options, value: @field.value %>
3
3
  <% end %>
@@ -1,10 +1,10 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <div data-controller="code-field">
3
3
  <%= @form.text_area @field.id,
4
4
  class: classes("w-full"),
5
5
  data: {
6
6
  'code-field-target': 'element',
7
- view: @resource.view,
7
+ view: view,
8
8
  language: @field.language,
9
9
  theme: @field.theme,
10
10
  'tab-size': @field.tab_size,
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index, full_width: true do %>
1
+ <%= field_wrapper **field_wrapper_args, full_width: true do %>
2
2
  <div data-controller="code-field" style="--height: <%= @field.height %>">
3
3
  <%= text_area_tag @field.id, @field.value,
4
4
  class: helpers.input_classes('w-full'),
@@ -6,7 +6,7 @@
6
6
  disabled: true,
7
7
  data: {
8
8
  'code-field-target': 'element',
9
- view: @resource.view,
9
+ view: view,
10
10
  language: @field.language,
11
11
  theme: @field.theme,
12
12
  'tab-size': @field.tab_size,
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= @form.select @field.id, @field.select_options, {
3
3
  selected: @field.value,
4
4
  include_blank: @field.include_blank
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <% if @field.display_code %>
3
3
  <%= @field.value %>
4
4
  <% else %>
@@ -1,4 +1,4 @@
1
- <%= edit_field_wrapper field: @field, index: @index, form: @form, resource: @resource, displayed_in_modal: @displayed_in_modal do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= content_tag :div, data: {
3
3
  controller: "date-field",
4
4
  date_field_view_value: @view,
@@ -1,4 +1,4 @@
1
- <%= show_field_wrapper field: @field, resource: @resource, index: @index do %>
1
+ <%= field_wrapper **field_wrapper_args do %>
2
2
  <%= content_tag :div, data: {
3
3
  controller: "date-field",
4
4
  date_field_view_value: @view,