avo 3.10.10 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -4
  3. data/Gemfile.lock +51 -49
  4. data/app/components/avo/actions_component.html.erb +10 -6
  5. data/app/components/avo/actions_component.rb +37 -55
  6. data/app/components/avo/button_component.rb +3 -3
  7. data/app/components/avo/fields/belongs_to_field/edit_component.html.erb +8 -4
  8. data/app/components/avo/fields/belongs_to_field/show_component.rb +1 -1
  9. data/app/components/avo/fields/common/files/list_viewer_component.rb +1 -1
  10. data/app/components/avo/fields/has_one_field/show_component.rb +3 -3
  11. data/app/components/avo/index/resource_controls_component.rb +9 -5
  12. data/app/components/avo/paginator_component.html.erb +1 -1
  13. data/app/components/avo/paginator_component.rb +1 -1
  14. data/app/components/avo/panel_component.html.erb +6 -4
  15. data/app/components/avo/resource_component.rb +3 -2
  16. data/app/components/avo/resource_sidebar_component.html.erb +1 -1
  17. data/app/components/avo/views/resource_edit_component.html.erb +2 -2
  18. data/app/components/avo/views/resource_index_component.html.erb +2 -2
  19. data/app/components/avo/views/resource_index_component.rb +17 -4
  20. data/app/components/avo/views/resource_show_component.html.erb +2 -2
  21. data/app/controllers/avo/actions_controller.rb +1 -1
  22. data/app/controllers/avo/application_controller.rb +1 -1
  23. data/app/controllers/avo/associations_controller.rb +55 -18
  24. data/app/controllers/avo/base_controller.rb +7 -2
  25. data/app/controllers/avo/search_controller.rb +1 -1
  26. data/app/helpers/avo/application_helper.rb +1 -1
  27. data/app/javascript/avo.base.js +8 -0
  28. data/app/views/avo/actions/show.html.erb +3 -3
  29. data/app/views/avo/associations/new.html.erb +45 -20
  30. data/app/views/avo/base/close_modal_and_reload_field.turbo_stream.erb +1 -1
  31. data/app/views/layouts/avo/application.html.erb +1 -2
  32. data/config/initializers/pagy.rb +1 -1
  33. data/lib/avo/base_action.rb +1 -0
  34. data/lib/avo/engine.rb +8 -4
  35. data/lib/avo/fields/base_field.rb +2 -2
  36. data/lib/avo/fields/belongs_to_field.rb +14 -8
  37. data/lib/avo/fields/concerns/is_required.rb +1 -1
  38. data/lib/avo/fields/has_base_field.rb +3 -1
  39. data/lib/avo/fields/has_one_field.rb +1 -1
  40. data/lib/avo/fields_execution_context.rb +13 -0
  41. data/lib/avo/resources/base.rb +32 -22
  42. data/lib/avo/version.rb +1 -1
  43. data/lib/avo.rb +10 -8
  44. data/lib/generators/avo/templates/initializer/avo.tt +3 -3
  45. data/lib/generators/avo/templates/locales/avo.ar.yml +1 -0
  46. data/lib/generators/avo/templates/locales/avo.de.yml +1 -0
  47. data/lib/generators/avo/templates/locales/avo.en.yml +1 -0
  48. data/lib/generators/avo/templates/locales/avo.es.yml +1 -0
  49. data/lib/generators/avo/templates/locales/avo.fr.yml +1 -0
  50. data/lib/generators/avo/templates/locales/avo.it.yml +1 -0
  51. data/lib/generators/avo/templates/locales/avo.ja.yml +1 -0
  52. data/lib/generators/avo/templates/locales/avo.nb.yml +1 -0
  53. data/lib/generators/avo/templates/locales/avo.nl.yml +1 -0
  54. data/lib/generators/avo/templates/locales/avo.nn.yml +1 -0
  55. data/lib/generators/avo/templates/locales/avo.pl.yml +1 -0
  56. data/lib/generators/avo/templates/locales/avo.pt-BR.yml +1 -0
  57. data/lib/generators/avo/templates/locales/avo.pt.yml +1 -0
  58. data/lib/generators/avo/templates/locales/avo.ro.yml +1 -0
  59. data/lib/generators/avo/templates/locales/avo.ru.yml +1 -0
  60. data/lib/generators/avo/templates/locales/avo.tr.yml +1 -0
  61. data/lib/generators/avo/templates/locales/avo.uk.yml +1 -0
  62. data/lib/generators/avo/templates/locales/avo.zh.yml +1 -0
  63. data/lib/tasks/avo_tasks.rake +1 -1
  64. data/public/avo-assets/avo.base.css +49 -2
  65. data/public/avo-assets/avo.base.js +129 -129
  66. data/public/avo-assets/avo.base.js.map +3 -3
  67. data/tailwind.preset.js +2 -3
  68. metadata +4 -3
  69. /data/{lib → app}/avo/base_resource.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfef7f3999741b8b92840a20ce2b32e82d0ed5319d9b63d595faf956c39f7deb
4
- data.tar.gz: 70eac6048c48f2aa7fded5d45e725cb9053a889dc2050e41501f6f34decfd539
3
+ metadata.gz: 1f8dfd2427a19d5e2700a60013dc358f09ea5045296d27bd94660a3a8a2e8728
4
+ data.tar.gz: c981ab154fa0a42682eb1b8db713585165a4e8864a7612d534f9e9ac07aebbad
5
5
  SHA512:
6
- metadata.gz: 3b54e5fd59211b1fff90560f5b619db0a0c885cef1a1d913ff38d05c6d60bf54489d0aee3881efca45c3f37a57eb853c77633c12bbe63c7723b57af3f8da2a5d
7
- data.tar.gz: 709aeca555ffe9a30eb70c79e284d1cbcd214eed91c623fa33dc5342018414634f99d5bbae2b30ceecbfe82d8ba4cf0c3fa575a08448913f5a247fa9aba439fd
6
+ metadata.gz: 2d0eb9fd3be357036607c18cdb8e8d7663ddee4d6f917981c4209397227c68924737b76c39c8f47a1e029924dd3e192a9d612064f2d4f8b042ed82eb47903716
7
+ data.tar.gz: cfbf2d89029d9997f9c13b8bb203de79212ffbf612c2f08d876031bbf39037beff6b93c9b31fccd7cf8117af0417f699966057f1e6cc93d8d659f41019801fa5
data/Gemfile CHANGED
@@ -130,10 +130,7 @@ gem "addressable"
130
130
  gem 'meta-tags'
131
131
 
132
132
  # Search
133
- # gem "ransack", "~> 4.1", ">= 4.1.1"
134
-
135
- # Temporary use of fork to add Rails 8 support
136
- gem "ransack", github: "avo-hq/ransack", branch: "fix/rails-8/delegate-alias-tracker-to-relation"
133
+ gem "ransack", ">= 4.2.0"
137
134
 
138
135
  gem 'friendly_id', '~> 5.5.1'
139
136
 
@@ -175,6 +172,8 @@ gem "mapkick-rb", "~> 0.1.4"
175
172
 
176
173
  gem "pluggy", path: "./pluggy"
177
174
 
175
+ gem "hashid-rails", "~> 1.4", ">= 1.4.1"
176
+
178
177
  # Avo money field
179
178
  # gem "avo-money_field", path: "./../avo-money_field"
180
179
  gem "money-rails", "~> 1.12"
data/Gemfile.lock CHANGED
@@ -1,23 +1,13 @@
1
1
  GIT
2
2
  remote: https://github.com/avo-hq/acts-as-taggable-on.git
3
- revision: faa91e0ed2947f25a08a5e03a7eea1d391bc72ac
3
+ revision: 8f497b819632a2aceeec7f02144269b773c3588c
4
4
  specs:
5
5
  acts-as-taggable-on (10.0.0)
6
6
  activerecord (>= 6.1)
7
7
 
8
- GIT
9
- remote: https://github.com/avo-hq/ransack.git
10
- revision: 0af36d53a784e19b5a56f3b112f433c54f4d709f
11
- branch: fix/rails-8/delegate-alias-tracker-to-relation
12
- specs:
13
- ransack (4.1.1)
14
- activerecord (>= 6.1.5)
15
- activesupport (>= 6.1.5)
16
- i18n
17
-
18
8
  GIT
19
9
  remote: https://github.com/rails/rails.git
20
- revision: 69d904e60f78300270ecbb01e4cf68e78074b30d
10
+ revision: 7a0bf93b9dd291c7f61121a41b3a813ac8857e6a
21
11
  branch: main
22
12
  specs:
23
13
  actioncable (8.0.0.alpha)
@@ -88,6 +78,7 @@ GIT
88
78
  i18n (>= 1.6, < 2)
89
79
  logger (>= 1.4.2)
90
80
  minitest (>= 5.1)
81
+ securerandom (>= 0.3)
91
82
  tzinfo (~> 2.0, >= 2.0.5)
92
83
  rails (8.0.0.alpha)
93
84
  actioncable (= 8.0.0.alpha)
@@ -115,7 +106,7 @@ GIT
115
106
  PATH
116
107
  remote: .
117
108
  specs:
118
- avo (3.10.10)
109
+ avo (3.11.0)
119
110
  actionview (>= 6.1)
120
111
  active_link_to
121
112
  activerecord (>= 6.1)
@@ -144,12 +135,12 @@ GEM
144
135
  addressable
145
136
  active_median (0.4.1)
146
137
  activesupport (>= 6.1)
147
- acts_as_list (1.2.1)
138
+ acts_as_list (1.2.2)
148
139
  activerecord (>= 6.1)
149
140
  activesupport (>= 6.1)
150
- actual_db_schema (0.7.5)
151
- activerecord (>= 6.0.0)
152
- activesupport (>= 6.0.0)
141
+ actual_db_schema (0.7.7)
142
+ activerecord
143
+ activesupport
153
144
  csv
154
145
  addressable (2.8.7)
155
146
  public_suffix (>= 2.0.2, < 7.0)
@@ -166,8 +157,8 @@ GEM
166
157
  avo-record_link_field (0.0.1)
167
158
  awesome_print (1.9.2)
168
159
  aws-eventstream (1.3.0)
169
- aws-partitions (1.955.0)
170
- aws-sdk-core (3.201.1)
160
+ aws-partitions (1.961.0)
161
+ aws-sdk-core (3.201.3)
171
162
  aws-eventstream (~> 1, >= 1.3.0)
172
163
  aws-partitions (~> 1, >= 1.651.0)
173
164
  aws-sigv4 (~> 1.8)
@@ -175,11 +166,11 @@ GEM
175
166
  aws-sdk-kms (1.88.0)
176
167
  aws-sdk-core (~> 3, >= 3.201.0)
177
168
  aws-sigv4 (~> 1.5)
178
- aws-sdk-s3 (1.156.0)
169
+ aws-sdk-s3 (1.157.0)
179
170
  aws-sdk-core (~> 3, >= 3.201.0)
180
171
  aws-sdk-kms (~> 1)
181
172
  aws-sigv4 (~> 1.5)
182
- aws-sigv4 (1.8.0)
173
+ aws-sigv4 (1.9.1)
183
174
  aws-eventstream (~> 1, >= 1.0.2)
184
175
  axiom-types (0.1.1)
185
176
  descendants_tracker (~> 0.0.4)
@@ -225,13 +216,13 @@ GEM
225
216
  bigdecimal
226
217
  rexml
227
218
  crass (1.0.6)
228
- cssbundling-rails (1.4.0)
219
+ cssbundling-rails (1.4.1)
229
220
  railties (>= 6.0.0)
230
221
  csv (3.3.0)
231
222
  cuprite (0.15.1)
232
223
  capybara (~> 3.0)
233
224
  ferrum (~> 0.15.0)
234
- database_cleaner-active_record (2.1.0)
225
+ database_cleaner-active_record (2.2.0)
235
226
  activerecord (>= 5.a)
236
227
  database_cleaner-core (~> 2.0.0)
237
228
  database_cleaner-core (2.0.1)
@@ -245,7 +236,7 @@ GEM
245
236
  responders
246
237
  warden (~> 1.2.3)
247
238
  diff-lcs (1.5.1)
248
- docile (1.4.0)
239
+ docile (1.4.1)
249
240
  dotenv (3.1.2)
250
241
  dotenv-rails (3.1.2)
251
242
  dotenv (= 3.1.2)
@@ -281,12 +272,12 @@ GEM
281
272
  e2mmap (0.1.0)
282
273
  erb-formatter (0.7.3)
283
274
  syntax_tree (~> 6.0)
284
- erb_lint (0.5.0)
275
+ erb_lint (0.6.0)
285
276
  activesupport
286
277
  better_html (>= 2.0.1)
287
278
  parser (>= 2.7.1.4)
288
279
  rainbow
289
- rubocop
280
+ rubocop (>= 1)
290
281
  smart_properties
291
282
  erubi (1.13.0)
292
283
  factory_bot (6.4.6)
@@ -294,7 +285,7 @@ GEM
294
285
  factory_bot_rails (6.4.3)
295
286
  factory_bot (~> 6.4)
296
287
  railties (>= 5.0.0)
297
- faker (3.4.1)
288
+ faker (3.4.2)
298
289
  i18n (>= 1.8.11, < 2)
299
290
  ferrum (0.15)
300
291
  addressable (~> 2.5)
@@ -322,9 +313,13 @@ GEM
322
313
  activesupport (>= 6.1)
323
314
  groupdate (6.4.0)
324
315
  activesupport (>= 6.1)
325
- hashdiff (1.1.0)
316
+ hashdiff (1.1.1)
317
+ hashid-rails (1.4.1)
318
+ activerecord (>= 4.0)
319
+ hashids (~> 1.0)
326
320
  hashids (1.0.6)
327
- highline (3.0.1)
321
+ highline (3.1.0)
322
+ reline
328
323
  hightop (0.4.0)
329
324
  activesupport (>= 6.1)
330
325
  hotwire-livereload (1.3.2)
@@ -345,7 +340,7 @@ GEM
345
340
  rainbow (>= 2.2.2, < 4.0)
346
341
  terminal-table (>= 1.5.1)
347
342
  ice_nine (0.11.2)
348
- image_processing (1.12.2)
343
+ image_processing (1.13.0)
349
344
  mini_magick (>= 4.9.5, < 5)
350
345
  ruby-vips (>= 2.0.17, < 3)
351
346
  inline_svg (1.9.0)
@@ -359,7 +354,7 @@ GEM
359
354
  i18n
360
355
  jaro_winkler (1.6.0)
361
356
  jmespath (1.6.2)
362
- jsbundling-rails (1.3.0)
357
+ jsbundling-rails (1.3.1)
363
358
  railties (>= 6.0.0)
364
359
  json (2.7.2)
365
360
  kramdown (2.4.0)
@@ -387,8 +382,8 @@ GEM
387
382
  mapkick-rb (0.1.5)
388
383
  marcel (1.0.4)
389
384
  matrix (0.4.2)
390
- meta-tags (2.2.0)
391
- actionpack (>= 3.2.0)
385
+ meta-tags (2.22.0)
386
+ actionpack (>= 6.0.0, < 8.1)
392
387
  method_source (1.1.0)
393
388
  mini_magick (4.13.2)
394
389
  mini_mime (1.1.5)
@@ -414,29 +409,29 @@ GEM
414
409
  net-smtp (0.5.0)
415
410
  net-protocol
416
411
  nio4r (2.7.3)
417
- nokogiri (1.16.6)
412
+ nokogiri (1.16.7)
418
413
  mini_portile2 (~> 2.8.2)
419
414
  racc (~> 1.4)
420
- nokogiri (1.16.6-x86_64-linux)
415
+ nokogiri (1.16.7-x86_64-linux)
421
416
  racc (~> 1.4)
422
417
  orm_adapter (0.5.0)
423
- pagy (8.6.3)
418
+ pagy (9.0.5)
424
419
  parallel (1.25.1)
425
420
  parser (3.3.4.0)
426
421
  ast (~> 2.4.1)
427
422
  racc
428
- path_expander (1.1.1)
429
- pg (1.5.6)
430
- prefixed_ids (1.7.1)
423
+ path_expander (1.1.2)
424
+ pg (1.5.7)
425
+ prefixed_ids (1.8.1)
431
426
  hashids (>= 1.0.0, < 2.0.0)
432
427
  rails (>= 6.0.0)
433
428
  prettier_print (1.2.1)
434
429
  psych (5.1.2)
435
430
  stringio
436
- public_suffix (6.0.0)
431
+ public_suffix (6.0.1)
437
432
  puma (6.4.2)
438
433
  nio4r (~> 2.0)
439
- racc (1.8.0)
434
+ racc (1.8.1)
440
435
  rack (3.1.7)
441
436
  rack-session (2.0.0)
442
437
  rack (>= 3.0.0)
@@ -461,6 +456,10 @@ GEM
461
456
  railties (>= 6.0.0, < 8)
462
457
  rainbow (3.1.1)
463
458
  rake (13.2.1)
459
+ ransack (4.2.0)
460
+ activerecord (>= 6.1.5)
461
+ activesupport (>= 6.1.5)
462
+ i18n
464
463
  rb-fsevent (0.11.2)
465
464
  rb-inotify (0.11.1)
466
465
  ffi (~> 1.0)
@@ -484,7 +483,7 @@ GEM
484
483
  railties (>= 5.2)
485
484
  reverse_markdown (2.1.1)
486
485
  nokogiri
487
- rexml (3.3.2)
486
+ rexml (3.3.4)
488
487
  strscan
489
488
  ripper-tags (1.0.2)
490
489
  rspec-core (3.13.0)
@@ -525,8 +524,9 @@ GEM
525
524
  rubocop-shopify (2.15.1)
526
525
  rubocop (~> 1.51)
527
526
  ruby-progressbar (1.13.0)
528
- ruby-vips (2.2.1)
527
+ ruby-vips (2.2.2)
529
528
  ffi (~> 1.12)
529
+ logger
530
530
  ruby_parser (3.21.1)
531
531
  racc (~> 1.5)
532
532
  sexp_processor (~> 4.16)
@@ -542,6 +542,7 @@ GEM
542
542
  simplecov (>= 0.22.0)
543
543
  tty-which (~> 0.5.0)
544
544
  virtus (~> 2.0)
545
+ securerandom (0.3.1)
545
546
  sexp_processor (4.17.2)
546
547
  simplecov (0.22.0)
547
548
  docile (~> 1.1)
@@ -579,11 +580,11 @@ GEM
579
580
  sprockets (4.2.1)
580
581
  concurrent-ruby (~> 1.0)
581
582
  rack (>= 2.2.4, < 4)
582
- sprockets-rails (3.5.1)
583
+ sprockets-rails (3.5.2)
583
584
  actionpack (>= 6.1)
584
585
  activesupport (>= 6.1)
585
586
  sprockets (>= 3.0.0)
586
- standard (1.39.1)
587
+ standard (1.39.2)
587
588
  language_server-protocol (~> 3.17.0.2)
588
589
  lint_roller (~> 1.0)
589
590
  rubocop (~> 1.64.0)
@@ -607,7 +608,7 @@ GEM
607
608
  tilt (2.4.0)
608
609
  timeout (0.4.1)
609
610
  tty-which (0.5.0)
610
- turbo-rails (2.0.5)
611
+ turbo-rails (2.0.6)
611
612
  actionpack (>= 6.0.0)
612
613
  activejob (>= 6.0.0)
613
614
  railties (>= 6.0.0)
@@ -618,7 +619,7 @@ GEM
618
619
  unaccent (0.4.0)
619
620
  unicode-display_width (2.5.0)
620
621
  useragent (0.16.10)
621
- view_component (3.12.1)
622
+ view_component (3.13.0)
622
623
  activesupport (>= 5.2.0, < 8.0)
623
624
  concurrent-ruby (~> 1.0)
624
625
  method_source (~> 1.0)
@@ -644,7 +645,7 @@ GEM
644
645
  xpath (3.2.0)
645
646
  nokogiri (~> 1.8)
646
647
  yard (0.9.36)
647
- zeitwerk (2.6.16)
648
+ zeitwerk (2.6.17)
648
649
 
649
650
  PLATFORMS
650
651
  ruby
@@ -686,6 +687,7 @@ DEPENDENCIES
686
687
  fuubar
687
688
  gem-release
688
689
  groupdate
690
+ hashid-rails (~> 1.4, >= 1.4.1)
689
691
  hightop
690
692
  hotwire-livereload (~> 1.3.0)
691
693
  htmlbeautifier
@@ -706,7 +708,7 @@ DEPENDENCIES
706
708
  puma (~> 6.4)
707
709
  rails!
708
710
  rails-controller-testing
709
- ransack!
711
+ ransack (>= 4.2.0)
710
712
  redis (~> 5.0)
711
713
  ripper-tags
712
714
  rspec-rails (~> 6.0, >= 6.0.3)
@@ -4,17 +4,21 @@
4
4
  data-actions-picker-enabled-class="text-black hover:bg-primary-500 hover:text-white"
5
5
  data-actions-picker-disabled-class="cursor-wait text-gray-500"
6
6
  data-resource-name="<%= @resource.class.to_s %>"
7
- <% if @resource.record.present? %> data-record-id="<%= @resource.record.id %>" <% end %>
7
+ <% if @resource.record.present? %> data-record-id="<%= @resource.record_param %>" <% end %>
8
8
  >
9
9
  <%= a_button style: @style,
10
10
  type: :button,
11
11
  color: @color,
12
- size: size,
12
+ size: @size,
13
13
  class: "focus:outline-none",
14
14
  icon: @icon,
15
- 'data-action': "click->toggle#togglePanel",
16
- 'data-actions-dropdown-button': @resource.model_key do %>
17
- <%= label %>
15
+ data: {
16
+ action: "click->toggle#togglePanel",
17
+ actions_dropdown_button: @resource.model_key,
18
+ tippy: "tooltip",
19
+ tippy_content: @title
20
+ } do %>
21
+ <%= @label %>
18
22
  <% end %>
19
23
  <div
20
24
  class="absolute flex inset-auto xl:right-0 top-full bg-white w-full sm:w-auto sm:min-w-[300px] mt-2 z-40 shadow-modal rounded overflow-hidden hidden"
@@ -30,7 +34,7 @@
30
34
  data-transition-leave-end="transform opacity-0 -translate-y-1"
31
35
  >
32
36
  <div data-target="actions-list" class="w-full space divide-y">
33
- <% actions.each do |action| %>
37
+ <% @actions.each do |action| %>
34
38
  <%= render_item(action)%>
35
39
  <% end %>
36
40
  </div>
@@ -2,52 +2,53 @@
2
2
 
3
3
  class Avo::ActionsComponent < Avo::BaseComponent
4
4
  include Avo::ApplicationHelper
5
- attr_reader :label, :size, :as_row_control
6
-
7
- def initialize(actions: [], resource: nil, view: nil, exclude: [], include: [], style: :outline, color: :primary, label: nil, size: :md, as_row_control: false, icon: nil)
8
- @actions = actions || []
9
- @resource = resource
10
- @view = view
11
- @exclude = Array(exclude)
12
- @include = include
13
- @color = color
14
- @style = style
15
- @label = label || I18n.t("avo.actions")
16
- @size = size
17
- @icon = icon
18
- @as_row_control = as_row_control
5
+
6
+ ACTION_FILTER = _Set(_Class(Avo::BaseAction))
7
+
8
+ prop :as_row_control, _Boolean, default: false
9
+ prop :icon, _Nilable(String)
10
+ prop :size, Avo::ButtonComponent::SIZE, default: :md
11
+ prop :title, _Nilable(String)
12
+ prop :color, Symbol, default: :primary
13
+ prop :include, _Nilable(ACTION_FILTER), default: [].freeze do |include|
14
+ Array(include).to_set
15
+ end
16
+ prop :label, String do |label|
17
+ label || I18n.t("avo.actions")
18
+ end
19
+ prop :style, Avo::ButtonComponent::STYLE, default: :outline
20
+ prop :actions, _Array(Avo::BaseAction), default: [].freeze
21
+ prop :exclude, _Nilable(ACTION_FILTER), default: [].freeze do |exclude|
22
+ Array(exclude).to_set
23
+ end
24
+ prop :resource, _Nilable(Avo::BaseResource)
25
+ prop :view, _Nilable(Symbol) do |view|
26
+ view&.to_sym
19
27
  end
20
28
 
21
- def render?
22
- actions.present?
29
+ def after_initialize
30
+ filter_actions
23
31
  end
24
32
 
25
- def actions
26
- if @exclude.present?
27
- @actions.reject { |action| action.class.in?(@exclude) }
28
- elsif @include.present?
29
- @actions.select { |action| action.class.in?(@include) }
30
- else
31
- @actions
32
- end
33
+ def render?
34
+ @actions.present?
33
35
  end
34
36
 
35
- # When running an action for one record we should do it on a special path.
36
- # We do that so we get the `record` param inside the action so we can prefill fields.
37
- def action_path(action)
38
- return single_record_path(action) if as_row_control
39
- return many_records_path(action) unless @resource.has_record_id?
37
+ def filter_actions
38
+ @actions = @actions.dup
40
39
 
41
- if on_record_page?
42
- single_record_path action
43
- else
44
- many_records_path action
40
+ if @exclude.any?
41
+ @actions.reject! { |action| @exclude.include?(action.class) }
42
+ end
43
+
44
+ if @include.any?
45
+ @actions.select! { |action| @include.include?(action.class) }
45
46
  end
46
47
  end
47
48
 
48
49
  # How should the action be displayed by default
49
50
  def is_disabled?(action)
50
- return false if action.standalone || as_row_control
51
+ return false if action.standalone || @as_row_control
51
52
 
52
53
  on_index_page?
53
54
  end
@@ -55,32 +56,13 @@ class Avo::ActionsComponent < Avo::BaseComponent
55
56
  private
56
57
 
57
58
  def on_record_page?
58
- @view.in?(%w[show edit new])
59
+ @view.in?([:show, :edit, :new])
59
60
  end
60
61
 
61
62
  def on_index_page?
62
63
  !on_record_page?
63
64
  end
64
65
 
65
- def single_record_path(action)
66
- action_url(action, @resource.record_path)
67
- end
68
-
69
- def many_records_path(action)
70
- action_url(action, @resource.records_path)
71
- end
72
-
73
- def action_url(action, path)
74
- Avo::Services::URIService.parse(path)
75
- .append_paths("actions")
76
- .append_query(
77
- {
78
- action_id: action.to_param,
79
- arguments: Avo::BaseAction.encode_arguments(action.arguments)
80
- }.compact
81
- ).to_s
82
- end
83
-
84
66
  def icon(action)
85
67
  svg action.icon, class: "h-5 shrink-0 mr-1 inline pointer-events-none"
86
68
  end
@@ -102,7 +84,7 @@ class Avo::ActionsComponent < Avo::BaseComponent
102
84
  end
103
85
 
104
86
  def render_action_link(action)
105
- link_to action_path(action),
87
+ link_to action.link_arguments(resource: @resource).first,
106
88
  data: action_data_attributes(action),
107
89
  title: action.action_name,
108
90
  class: action_css_class(action) do
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # A button/link can have the following settings:
4
- # style: primary/outline/text
5
- # size: :xs :sm, :md, :lg
6
3
  class Avo::ButtonComponent < Avo::BaseComponent
4
+ SIZE = _Union(:xs, :sm, :md, :lg, :xl)
5
+ STYLE = _Union(:primary, :outline, :text, :icon)
6
+
7
7
  def initialize(path = nil, size: :md, style: :outline, color: :gray, icon: nil, icon_class: "", is_link: false, rounded: true, compact: false, aria: {}, **args)
8
8
  # Main settings
9
9
  @size = size
@@ -48,9 +48,13 @@
48
48
  %>
49
49
  <% else %>
50
50
  <%= @form.select @field.id_input_foreign_key,
51
- options_for_select(@field.values_for_type(type), @resource.present? && @resource.record.present? && @field.value.class == type ? @resource.record[@field.id_input_foreign_key] : nil),
51
+ options_for_select(
52
+ # Options
53
+ @field.values_for_type(type),
54
+ # Selected
55
+ @field.value.is_a?(type) ? @field.value.to_param : nil
56
+ ),
52
57
  {
53
- value: @field.value.class == type ? @resource.record[@field.id_input_foreign_key].to_s : nil,
54
58
  include_blank: @field.placeholder,
55
59
  },
56
60
  {
@@ -98,10 +102,10 @@
98
102
  style: @field.get_html(:style, view: view, element: :input)
99
103
  %>
100
104
  <% else %>
101
- <%= @form.select @field.id_input_foreign_key, @field.options,
105
+ <%= @form.select @field.id_input_foreign_key,
106
+ options_for_select(@field.options, @field.value.to_param),
102
107
  {
103
108
  include_blank: @field.placeholder,
104
- value: @field.value
105
109
  },
106
110
  {
107
111
  class: classes("w-full"),
@@ -6,7 +6,7 @@ class Avo::Fields::BelongsToField::ShowComponent < Avo::Fields::ShowComponent
6
6
  record: @field.value,
7
7
  resource: @field.target_resource,
8
8
  via_resource_class: @resource.class.to_s,
9
- via_record_id: @resource.record.to_param
9
+ via_record_id: @resource.record_param
10
10
  )
11
11
  end
12
12
  end
@@ -11,7 +11,7 @@ class Avo::Fields::Common::Files::ListViewerComponent < Avo::BaseComponent
11
11
  end
12
12
 
13
13
  def classes
14
- base_classes = "py-4 rounded-xl max-w-full"
14
+ base_classes = "py-4 rounded-2xl max-w-full"
15
15
 
16
16
  view_type_classes = if view_type == :list
17
17
  "flex flex-col space-y-2"
@@ -24,7 +24,7 @@ class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
24
24
  def attach_path
25
25
  helpers.avo.resources_associations_new_path(
26
26
  @resource.singular_model_key,
27
- @resource.record.to_param,
27
+ @resource.record_param,
28
28
  @field.id,
29
29
  for_attribute: @field.for_attribute
30
30
  )
@@ -42,13 +42,13 @@ class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
42
42
  end
43
43
 
44
44
  def create_path
45
- association_id = @field.resource.model_class._reflections.with_indifferent_access[@field.association_name].inverse_of.name
45
+ association_id = @field.resource.model_class.reflect_on_association(@field.association_name).inverse_of.name
46
46
 
47
47
  args = {
48
48
  via_relation: association_id,
49
49
  via_relation_class: @resource.model_class.to_s,
50
50
  via_resource_class: @resource.class,
51
- via_record_id: @resource.record.to_param,
51
+ via_record_id: @resource.record_param,
52
52
  via_association_type: :has_one
53
53
  }
54
54
 
@@ -65,7 +65,11 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
65
65
  end
66
66
 
67
67
  def is_has_many_association?
68
- @reflection.is_a?(::ActiveRecord::Reflection::HasManyReflection) || @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
68
+ @reflection.class.in? [
69
+ ActiveRecord::Reflection::HasManyReflection,
70
+ ActiveRecord::Reflection::HasAndBelongsToManyReflection,
71
+ ActiveRecord::Reflection::ThroughReflection
72
+ ]
69
73
  end
70
74
 
71
75
  def referrer_path
@@ -85,7 +89,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
85
89
  data: {
86
90
  target: "control:edit",
87
91
  control: :edit,
88
- "resource-id": @resource.record.id,
92
+ "resource-id": @resource.record_param,
89
93
  tippy: "tooltip",
90
94
  }
91
95
  end
@@ -129,14 +133,14 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
129
133
  target: "control:destroy",
130
134
  control: :destroy,
131
135
  tippy: control.title ? :tooltip : nil,
132
- "resource-id": @resource.record.id,
136
+ "resource-id": @resource.record_param,
133
137
  }
134
138
  end
135
139
 
136
140
  def render_detach_button(control)
137
141
  return unless can_detach?
138
142
 
139
- a_button url: helpers.resource_detach_path(params[:resource_name], params[:id], params[:related_name], @resource.record.id),
143
+ a_button url: helpers.resource_detach_path(params[:resource_name], params[:id], params[:related_name], @resource.record_param),
140
144
  style: :icon,
141
145
  color: :gray,
142
146
  icon: "avo/detach",
@@ -150,7 +154,7 @@ class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
150
154
  turbo_confirm: control.confirmation_message,
151
155
  target: "control:detach",
152
156
  control: :detach,
153
- "resource-id": @resource.record.id,
157
+ "resource-id": @resource.record_param,
154
158
  tippy: :tooltip,
155
159
  }
156
160
  end
@@ -1,4 +1,4 @@
1
- <div class="flex flex-col sm:flex-row items-center justify-between aborder-t aborder-slate-200 rounded-xl space-y-2 sm:space-y-0">
1
+ <div class="flex flex-col sm:flex-row items-center justify-between aborder-t aborder-slate-200 rounded-2xl space-y-2 sm:space-y-0">
2
2
  <div class="flex-2 sm:flex sm:items-center sm:justify-between">
3
3
  <div>
4
4
  <div class="text-sm leading-5 text-slate-600 flex items-center">
@@ -28,7 +28,7 @@ class Avo::PaginatorComponent < Avo::BaseComponent
28
28
  def render?
29
29
  return false if discreet_pagination && pagy.pages <= 1
30
30
 
31
- if ::Pagy::VERSION > ::Gem::Version.new("9.0")
31
+ if ::Pagy::VERSION >= ::Gem::Version.new("9.0")
32
32
  @pagy.limit > 0
33
33
  else
34
34
  @pagy.items > 0