solidus_admin 0.3.1 → 0.4.0

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/.prettierrc +4 -0
  3. data/app/assets/builds/solidus_admin/tailwind.css +164 -132
  4. data/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +2 -3
  5. data/app/components/solidus_admin/adjustment_reasons/edit/component.rb +1 -9
  6. data/app/components/solidus_admin/adjustment_reasons/index/component.rb +22 -8
  7. data/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +2 -4
  8. data/app/components/solidus_admin/adjustment_reasons/new/component.rb +1 -9
  9. data/app/components/solidus_admin/base_component.rb +7 -9
  10. data/app/components/solidus_admin/layout/navigation/account/component.rb +2 -2
  11. data/app/components/solidus_admin/layout/navigation/component.js +1 -1
  12. data/app/components/solidus_admin/layout/navigation/component.rb +1 -1
  13. data/app/components/solidus_admin/layout/navigation/item/component.html.erb +2 -2
  14. data/app/components/solidus_admin/layout/navigation/item/component.rb +3 -6
  15. data/app/components/solidus_admin/orders/index/component.rb +3 -3
  16. data/app/components/solidus_admin/orders/show/address/component.js +2 -2
  17. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/component.rb +1 -1
  18. data/app/components/solidus_admin/orders/show/adjustments/index/source/component.rb +1 -1
  19. data/app/components/solidus_admin/orders/show/component.js +2 -2
  20. data/app/components/solidus_admin/orders/show/customer_search/component.js +5 -4
  21. data/app/components/solidus_admin/orders/show/summary/component.html.erb +6 -6
  22. data/app/components/solidus_admin/products/show/component.html.erb +7 -1
  23. data/app/components/solidus_admin/products/show/component.rb +6 -0
  24. data/app/components/solidus_admin/products/status/component.rb +1 -1
  25. data/app/components/solidus_admin/properties/edit/component.html.erb +16 -0
  26. data/app/components/solidus_admin/properties/edit/component.rb +4 -0
  27. data/app/components/solidus_admin/properties/edit/component.yml +4 -0
  28. data/app/components/solidus_admin/properties/index/component.rb +19 -6
  29. data/app/components/solidus_admin/properties/new/component.html.erb +16 -0
  30. data/app/components/solidus_admin/properties/new/component.rb +4 -0
  31. data/app/components/solidus_admin/properties/new/component.yml +4 -0
  32. data/app/components/solidus_admin/refund_reasons/edit/component.html.erb +2 -3
  33. data/app/components/solidus_admin/refund_reasons/edit/component.rb +1 -9
  34. data/app/components/solidus_admin/refund_reasons/index/component.rb +22 -8
  35. data/app/components/solidus_admin/refund_reasons/new/component.html.erb +2 -4
  36. data/app/components/solidus_admin/refund_reasons/new/component.rb +1 -9
  37. data/app/components/solidus_admin/resources/base_component.rb +20 -0
  38. data/app/components/solidus_admin/resources/edit/component.rb +11 -0
  39. data/app/components/solidus_admin/resources/new/component.rb +11 -0
  40. data/app/components/solidus_admin/return_reasons/edit/component.html.erb +2 -3
  41. data/app/components/solidus_admin/return_reasons/edit/component.rb +1 -9
  42. data/app/components/solidus_admin/return_reasons/index/component.rb +13 -7
  43. data/app/components/solidus_admin/return_reasons/new/component.html.erb +2 -4
  44. data/app/components/solidus_admin/return_reasons/new/component.rb +1 -9
  45. data/app/components/solidus_admin/roles/edit/component.html.erb +2 -4
  46. data/app/components/solidus_admin/roles/edit/component.rb +1 -10
  47. data/app/components/solidus_admin/roles/index/component.rb +16 -8
  48. data/app/components/solidus_admin/roles/new/component.html.erb +2 -4
  49. data/app/components/solidus_admin/roles/new/component.rb +1 -10
  50. data/app/components/solidus_admin/shipping_categories/edit/component.html.erb +2 -3
  51. data/app/components/solidus_admin/shipping_categories/edit/component.rb +1 -9
  52. data/app/components/solidus_admin/shipping_categories/index/component.rb +14 -17
  53. data/app/components/solidus_admin/shipping_categories/new/component.html.erb +2 -4
  54. data/app/components/solidus_admin/shipping_categories/new/component.rb +1 -9
  55. data/app/components/solidus_admin/stock_items/edit/component.html.erb +74 -73
  56. data/app/components/solidus_admin/stock_items/edit/component.js +4 -3
  57. data/app/components/solidus_admin/stock_items/edit/component.rb +1 -10
  58. data/app/components/solidus_admin/stock_items/index/component.rb +10 -6
  59. data/app/components/solidus_admin/stock_locations/index/component.rb +2 -2
  60. data/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +2 -3
  61. data/app/components/solidus_admin/store_credit_reasons/edit/component.rb +1 -9
  62. data/app/components/solidus_admin/store_credit_reasons/index/component.rb +14 -7
  63. data/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +2 -4
  64. data/app/components/solidus_admin/store_credit_reasons/new/component.rb +1 -9
  65. data/app/components/solidus_admin/tax_categories/edit/component.html.erb +2 -4
  66. data/app/components/solidus_admin/tax_categories/edit/component.rb +1 -9
  67. data/app/components/solidus_admin/tax_categories/index/component.rb +30 -9
  68. data/app/components/solidus_admin/tax_categories/new/component.html.erb +2 -4
  69. data/app/components/solidus_admin/tax_categories/new/component.rb +1 -9
  70. data/app/components/solidus_admin/ui/dropdown/component.js +3 -3
  71. data/app/components/solidus_admin/ui/forms/address/component.js +5 -6
  72. data/app/components/solidus_admin/ui/forms/field/component.rb +18 -18
  73. data/app/components/solidus_admin/ui/forms/input/component.js +3 -4
  74. data/app/components/solidus_admin/ui/forms/input/component.rb +15 -4
  75. data/app/components/solidus_admin/ui/icon/component.rb +3 -1
  76. data/app/components/solidus_admin/ui/modal/component.js +2 -2
  77. data/app/components/solidus_admin/ui/pages/index/component.html.erb +3 -3
  78. data/app/components/solidus_admin/ui/pages/index/component.rb +11 -6
  79. data/app/components/solidus_admin/ui/table/component.html.erb +4 -3
  80. data/app/components/solidus_admin/ui/table/component.js +13 -17
  81. data/app/components/solidus_admin/ui/table/component.rb +1 -1
  82. data/app/components/solidus_admin/ui/table/ransack_filter/component.js +18 -16
  83. data/app/components/solidus_admin/ui/thumbnail_with_caption/component.rb +1 -1
  84. data/app/components/solidus_admin/ui/toast/component.html.erb +1 -1
  85. data/app/components/solidus_admin/ui/toast/component.js +3 -3
  86. data/app/components/solidus_admin/ui/toggletip/component.js +14 -12
  87. data/app/components/solidus_admin/users/index/component.rb +1 -1
  88. data/app/components/solidus_admin/users/orders/component.rb +1 -1
  89. data/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb +22 -0
  90. data/app/components/solidus_admin/users/store_credits/edit_amount/component.rb +22 -0
  91. data/app/components/solidus_admin/users/store_credits/edit_amount/component.yml +5 -0
  92. data/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb +15 -0
  93. data/app/components/solidus_admin/users/store_credits/edit_memo/component.rb +16 -0
  94. data/app/components/solidus_admin/users/store_credits/edit_memo/component.yml +4 -0
  95. data/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb +21 -0
  96. data/app/components/solidus_admin/users/store_credits/edit_validity/component.rb +22 -0
  97. data/app/components/solidus_admin/users/store_credits/edit_validity/component.yml +5 -0
  98. data/app/components/solidus_admin/users/store_credits/index/component.html.erb +65 -0
  99. data/app/components/solidus_admin/users/store_credits/index/component.rb +114 -0
  100. data/app/components/solidus_admin/users/store_credits/index/component.yml +12 -0
  101. data/app/components/solidus_admin/users/store_credits/new/component.html.erb +30 -0
  102. data/app/components/solidus_admin/users/store_credits/new/component.rb +22 -0
  103. data/app/components/solidus_admin/users/store_credits/new/component.yml +5 -0
  104. data/app/components/solidus_admin/users/store_credits/show/component.html.erb +83 -0
  105. data/app/components/solidus_admin/users/store_credits/show/component.rb +120 -0
  106. data/app/components/solidus_admin/users/store_credits/show/component.yml +18 -0
  107. data/app/controllers/solidus_admin/adjustment_reasons_controller.rb +3 -105
  108. data/app/controllers/solidus_admin/authentication_adapters/backend.rb +1 -1
  109. data/app/controllers/solidus_admin/base_controller.rb +12 -1
  110. data/app/controllers/solidus_admin/controller_helpers/search.rb +4 -4
  111. data/app/controllers/solidus_admin/properties_controller.rb +6 -24
  112. data/app/controllers/solidus_admin/refund_reasons_controller.rb +5 -105
  113. data/app/controllers/solidus_admin/resources_controller.rb +152 -0
  114. data/app/controllers/solidus_admin/return_reasons_controller.rb +4 -104
  115. data/app/controllers/solidus_admin/roles_controller.rb +3 -105
  116. data/app/controllers/solidus_admin/shipping_categories_controller.rb +3 -107
  117. data/app/controllers/solidus_admin/stock_items_controller.rb +12 -29
  118. data/app/controllers/solidus_admin/store_credit_reasons_controller.rb +5 -105
  119. data/app/controllers/solidus_admin/store_credits_controller.rb +231 -0
  120. data/app/controllers/solidus_admin/tax_categories_controller.rb +3 -109
  121. data/app/helpers/solidus_admin/void_elements_helper.rb +13 -0
  122. data/app/views/layouts/solidus_admin/application.html.erb +3 -0
  123. data/config/locales/menu_item.en.yml +0 -1
  124. data/config/locales/properties.en.yml +4 -0
  125. data/config/locales/store_credits.en.yml +16 -0
  126. data/config/routes.rb +12 -1
  127. data/lib/generators/solidus_admin/install/install_generator.rb +2 -0
  128. data/lib/solidus_admin/component_registry.rb +1 -1
  129. data/lib/solidus_admin/configuration.rb +3 -8
  130. data/lib/solidus_admin/engine.rb +6 -0
  131. data/lib/solidus_admin/install_tailwindcss.rb +1 -1
  132. data/lib/solidus_admin/testing_support/component_helpers.rb +3 -9
  133. data/lib/solidus_admin/testing_support/feature_helpers.rb +1 -1
  134. data/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb +20 -0
  135. data/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb +138 -0
  136. data/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb +72 -0
  137. data/lib/solidus_admin/version.rb +1 -1
  138. data/solidus_admin.gemspec +2 -2
  139. metadata +39 -8
  140. data/bin/rails +0 -13
@@ -57,7 +57,7 @@ class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::Shipping::C
57
57
  color = _1.active? ? :green : :graphite_light
58
58
  text = _1.active? ? t('.active') : t('.inactive')
59
59
 
60
- component('ui/badge').new(name: text, color: color)
60
+ component('ui/badge').new(name: text, color:)
61
61
  },
62
62
  },
63
63
  {
@@ -78,7 +78,7 @@ class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::Shipping::C
78
78
  count = _1.stock_movements.count
79
79
 
80
80
  link_to(
81
- "#{count} #{Spree::StockMovement.model_name.human(count: count).downcase}",
81
+ "#{count} #{Spree::StockMovement.model_name.human(count:).downcase}",
82
82
  spree.admin_stock_location_stock_movements_path(_1),
83
83
  class: 'body-link'
84
84
  )
@@ -1,6 +1,6 @@
1
- <%= turbo_frame_tag :edit_store_credit_reason_modal do %>
1
+ <%= turbo_frame_tag :resource_modal, target: "_top" do %>
2
2
  <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3
- <%= form_for @store_credit_reason, url: solidus_admin.store_credit_reason_path(@store_credit_reason), html: { id: form_id } do |f| %>
3
+ <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
4
4
  <div class="flex flex-col gap-6 pb-4">
5
5
  <%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6
6
  <label class="flex gap-2 items-center">
@@ -23,4 +23,3 @@
23
23
  <% end %>
24
24
  <% end %>
25
25
  <% end %>
26
- <%= render component("store_credit_reasons/index").new(page: @page) %>
@@ -1,12 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class SolidusAdmin::StoreCreditReasons::Edit::Component < SolidusAdmin::BaseComponent
4
- def initialize(page:, store_credit_reason:)
5
- @page = page
6
- @store_credit_reason = store_credit_reason
7
- end
8
-
9
- def form_id
10
- dom_id(@store_credit_reason, "#{stimulus_id}_edit_store_credit_reason_form")
11
- end
3
+ class SolidusAdmin::StoreCreditReasons::Edit::Component < SolidusAdmin::Resources::Edit::Component
12
4
  end
@@ -9,7 +9,8 @@ class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::Refunds
9
9
  render component("ui/button").new(
10
10
  tag: :a,
11
11
  text: t('.add'),
12
- href: solidus_admin.new_store_credit_reason_path, data: { turbo_frame: :new_store_credit_reason_modal },
12
+ href: solidus_admin.new_store_credit_reason_path(**search_filter_params),
13
+ data: { turbo_frame: :resource_modal },
13
14
  icon: "add-line",
14
15
  class: "align-self-end w-full",
15
16
  )
@@ -17,13 +18,12 @@ class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::Refunds
17
18
 
18
19
  def turbo_frames
19
20
  %w[
20
- new_store_credit_reason_modal
21
- edit_store_credit_reason_modal
21
+ resource_modal
22
22
  ]
23
23
  end
24
24
 
25
- def row_url(store_credit_reason)
26
- spree.edit_admin_store_credit_reason_path(store_credit_reason, _turbo_frame: :edit_store_credit_reason_modal)
25
+ def edit_path(store_credit_reason)
26
+ spree.edit_admin_store_credit_reason_path(store_credit_reason, **search_filter_params)
27
27
  end
28
28
 
29
29
  def search_url
@@ -38,7 +38,7 @@ class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::Refunds
38
38
  [
39
39
  {
40
40
  label: t('.batch_actions.delete'),
41
- action: solidus_admin.store_credit_reasons_path,
41
+ action: solidus_admin.store_credit_reasons_path(**search_filter_params),
42
42
  method: :delete,
43
43
  icon: 'delete-bin-7-line',
44
44
  },
@@ -47,7 +47,14 @@ class SolidusAdmin::StoreCreditReasons::Index::Component < SolidusAdmin::Refunds
47
47
 
48
48
  def columns
49
49
  [
50
- :name,
50
+ {
51
+ header: :name,
52
+ data: ->(store_credit_reason) do
53
+ link_to store_credit_reason.name, edit_path(store_credit_reason),
54
+ data: { turbo_frame: :resource_modal },
55
+ class: 'body-link'
56
+ end
57
+ },
51
58
  {
52
59
  header: :active,
53
60
  data: ->(store_credit_reason) do
@@ -1,6 +1,6 @@
1
- <%= turbo_frame_tag :new_store_credit_reason_modal do %>
1
+ <%= turbo_frame_tag :resource_modal, target: "_top" do %>
2
2
  <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3
- <%= form_for @store_credit_reason, url: solidus_admin.store_credit_reasons_path, html: { id: form_id } do |f| %>
3
+ <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
4
4
  <div class="flex flex-col gap-6 pb-4">
5
5
  <%= render component("ui/forms/field").text_field(f, :name, class: "required") %>
6
6
  <label class="flex gap-2 items-center">
@@ -23,5 +23,3 @@
23
23
  <% end %>
24
24
  <% end %>
25
25
  <% end %>
26
-
27
- <%= render component("store_credit_reasons/index").new(page: @page) %>
@@ -1,12 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class SolidusAdmin::StoreCreditReasons::New::Component < SolidusAdmin::BaseComponent
4
- def initialize(page:, store_credit_reason:)
5
- @page = page
6
- @store_credit_reason = store_credit_reason
7
- end
8
-
9
- def form_id
10
- dom_id(@store_credit_reason, "#{stimulus_id}_new_store_credit_reason_form")
11
- end
3
+ class SolidusAdmin::StoreCreditReasons::New::Component < SolidusAdmin::Resources::New::Component
12
4
  end
@@ -1,6 +1,6 @@
1
- <%= turbo_frame_tag :edit_tax_category_modal do %>
1
+ <%= turbo_frame_tag :resource_modal, target: "_top" do %>
2
2
  <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3
- <%= form_for @tax_category, url: solidus_admin.tax_category_path(@tax_category), html: { id: form_id } do |f| %>
3
+ <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
4
4
  <div class="flex flex-col gap-6 pb-4">
5
5
  <%= render component("ui/forms/field").text_field(f, :name) %>
6
6
  <%= render component("ui/forms/field").text_field(f, :tax_code) %>
@@ -24,5 +24,3 @@
24
24
  <% end %>
25
25
  <% end %>
26
26
  <% end %>
27
-
28
- <%= render component("tax_categories/index").new(page: @page) %>
@@ -1,12 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class SolidusAdmin::TaxCategories::Edit::Component < SolidusAdmin::TaxCategories::Index::Component
4
- def initialize(page:, tax_category:)
5
- @page = page
6
- @tax_category = tax_category
7
- end
8
-
9
- def form_id
10
- dom_id(@tax_category, "#{stimulus_id}_edit_tax_category_form")
11
- end
3
+ class SolidusAdmin::TaxCategories::Edit::Component < SolidusAdmin::Resources::Edit::Component
12
4
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Component
4
- def row_url(tax_category)
5
- spree.edit_admin_tax_category_path(tax_category, _turbo_frame: :edit_tax_category_modal)
4
+ def edit_path(tax_category)
5
+ spree.edit_admin_tax_category_path(tax_category, **search_filter_params)
6
6
  end
7
7
 
8
8
  def model_class
@@ -17,7 +17,8 @@ class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Compo
17
17
  render component("ui/button").new(
18
18
  tag: :a,
19
19
  text: t('.add'),
20
- href: solidus_admin.new_tax_category_path, data: { turbo_frame: :new_tax_category_modal },
20
+ href: solidus_admin.new_tax_category_path(**search_filter_params),
21
+ data: { turbo_frame: :resource_modal },
21
22
  icon: "add-line",
22
23
  class: "align-self-end w-full",
23
24
  )
@@ -25,8 +26,7 @@ class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Compo
25
26
 
26
27
  def turbo_frames
27
28
  %w[
28
- new_tax_category_modal
29
- edit_tax_category_modal
29
+ resource_modal
30
30
  ]
31
31
  end
32
32
 
@@ -38,7 +38,7 @@ class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Compo
38
38
  [
39
39
  {
40
40
  label: t('.batch_actions.delete'),
41
- action: solidus_admin.tax_categories_path,
41
+ action: solidus_admin.tax_categories_path(**search_filter_params),
42
42
  method: :delete,
43
43
  icon: 'delete-bin-7-line',
44
44
  },
@@ -47,9 +47,30 @@ class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Compo
47
47
 
48
48
  def columns
49
49
  [
50
- :name,
51
- :tax_code,
52
- :description,
50
+ {
51
+ header: :name,
52
+ data: ->(tax_category) do
53
+ link_to tax_category.name, edit_path(tax_category),
54
+ data: { turbo_frame: :resource_modal },
55
+ class: 'body-link'
56
+ end
57
+ },
58
+ {
59
+ header: :tax_code,
60
+ data: ->(tax_category) do
61
+ link_to_if tax_category.tax_code, tax_category.tax_code, edit_path(tax_category),
62
+ data: { turbo_frame: :resource_modal },
63
+ class: 'body-link'
64
+ end
65
+ },
66
+ {
67
+ header: :description,
68
+ data: ->(tax_category) do
69
+ link_to_if tax_category.description, tax_category.description, edit_path(tax_category),
70
+ data: { turbo_frame: :resource_modal },
71
+ class: 'body-link'
72
+ end
73
+ },
53
74
  {
54
75
  header: :is_default,
55
76
  data: ->(tax_category) {
@@ -1,6 +1,6 @@
1
- <%= turbo_frame_tag :new_tax_category_modal do %>
1
+ <%= turbo_frame_tag :resource_modal, target: "_top" do %>
2
2
  <%= render component("ui/modal").new(title: t(".title")) do |modal| %>
3
- <%= form_for @tax_category, url: solidus_admin.tax_categories_path(page: params[:page], q: params[:q]), html: { id: form_id } do |f| %>
3
+ <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
4
4
  <div class="flex flex-col gap-6 pb-4">
5
5
  <%= render component("ui/forms/field").text_field(f, :name) %>
6
6
  <%= render component("ui/forms/field").text_field(f, :tax_code) %>
@@ -24,5 +24,3 @@
24
24
  <% end %>
25
25
  <% end %>
26
26
  <% end %>
27
-
28
- <%= render component("tax_categories/index").new(page: @page) %>
@@ -1,12 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class SolidusAdmin::TaxCategories::New::Component < SolidusAdmin::TaxCategories::Index::Component
4
- def initialize(page:, tax_category:)
5
- @page = page
6
- @tax_category = tax_category
7
- end
8
-
9
- def form_id
10
- dom_id(@tax_category, "#{stimulus_id}_new_tax_category_form")
11
- end
3
+ class SolidusAdmin::TaxCategories::New::Component < SolidusAdmin::Resources::New::Component
12
4
  end
@@ -1,5 +1,5 @@
1
- import { Controller } from '@hotwired/stimulus'
2
- import { useClickOutside } from 'stimulus-use'
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { useClickOutside } from "stimulus-use"
3
3
 
4
4
  export default class extends Controller {
5
5
  connect() {
@@ -11,6 +11,6 @@ export default class extends Controller {
11
11
  }
12
12
 
13
13
  close() {
14
- this.element.removeAttribute('open')
14
+ this.element.removeAttribute("open")
15
15
  }
16
16
  }
@@ -1,4 +1,4 @@
1
- import { Controller } from '@hotwired/stimulus'
1
+ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  static targets = ["country", "state", "stateName", "stateWrapper", "stateNameWrapper"]
@@ -7,8 +7,8 @@ export default class extends Controller {
7
7
  const countryId = this.countryTarget.value
8
8
 
9
9
  fetch(`/admin/countries/${countryId}/states`)
10
- .then(response => response.json())
11
- .then(data => {
10
+ .then((response) => response.json())
11
+ .then((data) => {
12
12
  this.updateStateOptions(data)
13
13
  })
14
14
  }
@@ -30,13 +30,12 @@ export default class extends Controller {
30
30
  const stateSelect = this.stateTarget
31
31
  const stateName = this.stateNameTarget
32
32
 
33
-
34
33
  if (showSelect) {
35
34
  // Show state select dropdown.
36
35
  stateSelect.disabled = false
37
36
  stateName.value = ""
38
- stateWrapper.classList.remove('hidden')
39
- stateNameWrapper.classList.add('hidden')
37
+ stateWrapper.classList.remove("hidden")
38
+ stateNameWrapper.classList.add("hidden")
40
39
  } else {
41
40
  // Show state name text input if no states to choose from.
42
41
  stateSelect.disabled = true
@@ -18,14 +18,14 @@ class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent
18
18
  object_name, object, label, errors = extract_form_details(form, object, method)
19
19
 
20
20
  new(
21
- label: label,
22
- hint: hint,
23
- tip: tip,
21
+ label:,
22
+ hint:,
23
+ tip:,
24
24
  error: errors,
25
25
  input_attributes: {
26
26
  name: "#{object_name}[#{method}]",
27
27
  tag: :input,
28
- size: size,
28
+ size:,
29
29
  value: object.public_send(method),
30
30
  error: (errors.to_sentence.capitalize if errors),
31
31
  **attributes,
@@ -37,16 +37,16 @@ class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent
37
37
  object_name, object, label, errors = extract_form_details(form, object, method)
38
38
 
39
39
  new(
40
- label: label,
41
- hint: hint,
42
- tip: tip,
40
+ label:,
41
+ hint:,
42
+ tip:,
43
43
  error: errors,
44
44
  input_attributes: {
45
45
  name: "#{object_name}[#{method}]",
46
46
  tag: :select,
47
- choices: choices,
48
- size: size,
49
- value: object.public_send(method),
47
+ choices:,
48
+ size:,
49
+ value: (object.public_send(method) if object.respond_to?(method)),
50
50
  error: (errors.to_sentence.capitalize if errors),
51
51
  **attributes,
52
52
  }
@@ -57,13 +57,13 @@ class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent
57
57
  object_name, object, label, errors = extract_form_details(form, object, method)
58
58
 
59
59
  new(
60
- label: label,
61
- hint: hint,
62
- tip: tip,
60
+ label:,
61
+ hint:,
62
+ tip:,
63
63
  error: errors,
64
64
  input_attributes: {
65
65
  name: "#{object_name}[#{method}]",
66
- size: size,
66
+ size:,
67
67
  tag: :textarea,
68
68
  value: object.public_send(method),
69
69
  error: (errors.to_sentence.capitalize if errors),
@@ -76,14 +76,14 @@ class SolidusAdmin::UI::Forms::Field::Component < SolidusAdmin::BaseComponent
76
76
  object_name, object, label, errors = extract_form_details(form, object, method)
77
77
 
78
78
  new(
79
- label: label,
80
- hint: hint,
81
- tip: tip,
79
+ label:,
80
+ hint:,
81
+ tip:,
82
82
  error: errors,
83
83
  ).with_content(
84
84
  component('ui/forms/switch').new(
85
85
  name: "#{object_name}[#{method}]",
86
- size: size,
86
+ size:,
87
87
  checked: object.public_send(method),
88
88
  include_hidden: true,
89
89
  **attributes,
@@ -1,4 +1,4 @@
1
- import { Controller } from '@hotwired/stimulus'
1
+ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  static values = {
@@ -6,11 +6,10 @@ export default class extends Controller {
6
6
  }
7
7
 
8
8
  connect() {
9
- if (this.customValidityValue)
10
- this.element.setCustomValidity(this.customValidityValue)
9
+ if (this.customValidityValue) this.element.setCustomValidity(this.customValidityValue)
11
10
  }
12
11
 
13
12
  clearCustomValidity() {
14
- this.element.setCustomValidity('')
13
+ this.element.setCustomValidity("")
15
14
  }
16
15
  }
@@ -93,13 +93,24 @@ class SolidusAdmin::UI::Forms::Input::Component < SolidusAdmin::BaseComponent
93
93
  with_content options_for_select(@attributes.delete(:choices), @attributes.delete(:value))
94
94
  end
95
95
 
96
- tag.public_send(
97
- @tag,
98
- content,
96
+ build_tag
97
+ end
98
+
99
+ private
100
+
101
+ def build_tag
102
+ args = [@tag]
103
+ args << content unless void_element?(@tag)
104
+
105
+ tag.public_send(*args, **tag_options)
106
+ end
107
+
108
+ def tag_options
109
+ @tag_options ||= {
99
110
  "data-controller": stimulus_id,
100
111
  "data-#{stimulus_id}-custom-validity-value": @error.presence,
101
112
  "data-action": "#{stimulus_id}#clearCustomValidity",
102
113
  **@attributes
103
- )
114
+ }
104
115
  end
105
116
  end
@@ -23,7 +23,9 @@ class SolidusAdmin::UI::Icon::Component < SolidusAdmin::BaseComponent
23
23
  end
24
24
 
25
25
  def call
26
- href = "#{image_path('solidus_admin/remixicon.symbol.svg')}#ri-#{@name}"
26
+ # bypass the asset_host configuration to avoid CORS issues with CDNs:
27
+ # https://github.com/solidusio/solidus/issues/5657
28
+ href = asset_path("solidus_admin/remixicon.symbol.svg#ri-#{@name}", host: "")
27
29
  tag.svg(tag.use("xlink:href": href), **@attrs)
28
30
  end
29
31
  end
@@ -1,7 +1,7 @@
1
- import { Controller } from "@hotwired/stimulus";
1
+ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class extends Controller {
4
4
  connect() {
5
- this.element.showModal();
5
+ this.element.showModal()
6
6
  }
7
7
  }
@@ -1,12 +1,12 @@
1
1
  <%= page do %>
2
- <% if @tabs %>
2
+ <% if tabs %>
3
3
  <%= page_header do %>
4
4
  <%= render_title %>
5
5
  <% end %>
6
6
 
7
7
  <%= page_header do %>
8
8
  <% rendered_tabs = capture do %>
9
- <% @tabs.each do %>
9
+ <% renderable_tabs.each do %>
10
10
  <%= render(component("ui/button").new(tag: :a, scheme: :ghost, text: _1.text, 'aria-current': _1.current, href: _1.href)) %>
11
11
  <% end %>
12
12
  <% end %>
@@ -39,6 +39,6 @@
39
39
  <% end %>
40
40
 
41
41
  <% turbo_frames.each do |frame| %>
42
- <%= turbo_frame_tag frame %>
42
+ <%= turbo_frame_tag frame, target: "_top" %>
43
43
  <% end %>
44
44
  <% end %>
@@ -22,13 +22,18 @@ class SolidusAdmin::UI::Pages::Index::Component < SolidusAdmin::BaseComponent
22
22
 
23
23
  def initialize(page:)
24
24
  @page = page
25
- @tabs = tabs&.map { |tab| Tab.new(**tab) }
26
25
  end
27
26
 
28
27
  def row_fade(_record)
29
28
  false
30
29
  end
31
30
 
31
+ def renderable_tabs
32
+ return unless tabs
33
+
34
+ tabs.map { |tab| Tab.new(**tab) }
35
+ end
36
+
32
37
  def title
33
38
  model_class.model_name.human.pluralize
34
39
  end
@@ -61,8 +66,8 @@ class SolidusAdmin::UI::Pages::Index::Component < SolidusAdmin::BaseComponent
61
66
  value: search_params,
62
67
  url: search_url,
63
68
  searchbar_key: search_key,
64
- filters: filters,
65
- scopes: scopes,
69
+ filters:,
70
+ scopes:,
66
71
  }
67
72
  end
68
73
 
@@ -80,12 +85,12 @@ class SolidusAdmin::UI::Pages::Index::Component < SolidusAdmin::BaseComponent
80
85
  id: stimulus_id,
81
86
  data: {
82
87
  class: model_class,
83
- rows: rows,
88
+ rows:,
84
89
  fade: -> { row_fade(_1) },
85
90
  prev: prev_page_path,
86
91
  next: next_page_path,
87
- columns: columns,
88
- batch_actions: batch_actions,
92
+ columns:,
93
+ batch_actions:,
89
94
  url: -> { row_url(_1) },
90
95
  },
91
96
  search: search_options,
@@ -137,11 +137,12 @@
137
137
  <%= "data-sortable-animation-value=#{@sortable.animation}" if @sortable&.animation %>
138
138
  >
139
139
  <% @data.rows.each do |row| %>
140
+ <% row_url = @data.url&.call(row) %>
140
141
  <tr
141
- class="border-b border-gray-100 last:border-0 hover:bg-gray-50 cursor-pointer <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>"
142
- <% if @data.url %>
142
+ class="border-b border-gray-100 last:border-0 <%= 'hover:bg-gray-50 cursor-pointer' if row_url %> <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>"
143
+ <% if row_url %>
143
144
  data-action="click-><%= stimulus_id %>#rowClicked"
144
- data-<%= stimulus_id %>-url-param="<%= @data.url.call(row) %>"
145
+ data-<%= stimulus_id %>-url-param="<%= row_url %>"
145
146
  <%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %>
146
147
  <% end %>
147
148
  >
@@ -36,9 +36,9 @@ export default class extends Controller {
36
36
  const shouldSetSortable = this.sortableValue && this.modeValue !== "batch" && this.modeValue !== "search"
37
37
 
38
38
  if (shouldSetSortable) {
39
- this.tableBodyTarget.setAttribute('data-controller', 'sortable')
39
+ this.tableBodyTarget.setAttribute("data-controller", "sortable")
40
40
  } else {
41
- this.tableBodyTarget.removeAttribute('data-controller')
41
+ this.tableBodyTarget.removeAttribute("data-controller")
42
42
  }
43
43
  }
44
44
 
@@ -54,13 +54,13 @@ export default class extends Controller {
54
54
  }
55
55
 
56
56
  clearSearch() {
57
- this.searchFieldTarget.value = ''
57
+ this.searchFieldTarget.value = ""
58
58
  this.search()
59
59
  }
60
60
 
61
61
  resetSearchAndFilters() {
62
62
  if (this.hasFilterToolbarTarget) {
63
- this.filterToolbarTarget.querySelectorAll('fieldset').forEach(fieldset => fieldset.disabled = true)
63
+ this.filterToolbarTarget.querySelectorAll("fieldset").forEach((fieldset) => (fieldset.disabled = true))
64
64
  }
65
65
 
66
66
  this.searchFieldTarget.disabled = true
@@ -70,7 +70,7 @@ export default class extends Controller {
70
70
  selectRow(event) {
71
71
  if (this.checkboxTargets.some((checkbox) => checkbox.checked)) {
72
72
  this.modeValue = "batch"
73
- } else if (this.hasSearchFieldTarget && (this.searchFieldTarget.value !== '')) {
73
+ } else if (this.hasSearchFieldTarget && this.searchFieldTarget.value !== "") {
74
74
  this.modeValue = "search"
75
75
  } else if (this.hasScopesToolbarTarget) {
76
76
  this.modeValue = "scopes"
@@ -84,7 +84,7 @@ export default class extends Controller {
84
84
  selectAllRows(event) {
85
85
  if (event.target.checked) {
86
86
  this.modeValue = "batch"
87
- } else if (this.hasSearchFieldTarget && (this.searchFieldTarget.value !== '')) {
87
+ } else if (this.hasSearchFieldTarget && this.searchFieldTarget.value !== "") {
88
88
  this.modeValue = "search"
89
89
  } else if (this.hasScopesToolbarTarget) {
90
90
  this.modeValue = "scopes"
@@ -103,13 +103,13 @@ export default class extends Controller {
103
103
 
104
104
  if (this.modeValue === "batch") {
105
105
  this.toggleCheckbox(event.currentTarget)
106
- } else {
106
+ } else if (event.params.url) {
107
107
  const url = new URL(event.params.url, "http://dummy.com")
108
108
  const params = new URLSearchParams(url.search)
109
- const frameId = params.get('_turbo_frame')
109
+ const frameId = params.get("_turbo_frame")
110
110
  const frame = frameId ? { frame: frameId } : {}
111
111
  // remove the custom _turbo_frame param from url search:
112
- params.delete('_turbo_frame')
112
+ params.delete("_turbo_frame")
113
113
  url.search = params.toString()
114
114
 
115
115
  window.Turbo.visit(url.pathname + url.search, frame)
@@ -117,7 +117,7 @@ export default class extends Controller {
117
117
  }
118
118
 
119
119
  toggleCheckbox(row) {
120
- const checkbox = this.checkboxTargets.find(selection => row.contains(selection))
120
+ const checkbox = this.checkboxTargets.find((selection) => row.contains(selection))
121
121
 
122
122
  if (checkbox) {
123
123
  checkbox.checked = !checkbox.checked
@@ -131,14 +131,10 @@ export default class extends Controller {
131
131
 
132
132
  confirmAction(event) {
133
133
  const message = event.params.message
134
+ .replace("${count}", this.selectedRows().length)
134
135
  .replace(
135
- "${count}",
136
- this.selectedRows().length
137
- ).replace(
138
136
  "${resource}",
139
- this.selectedRows().length > 1 ?
140
- event.params.resourcePlural :
141
- event.params.resourceSingular
137
+ this.selectedRows().length > 1 ? event.params.resourcePlural : event.params.resourceSingular
142
138
  )
143
139
 
144
140
  if (!confirm(message)) {
@@ -167,7 +163,7 @@ export default class extends Controller {
167
163
 
168
164
  // Update the rows background color
169
165
  this.checkboxTargets.filter((checkbox) =>
170
- checkbox.closest("tr").classList.toggle(this.selectedRowClass, checkbox.checked),
166
+ checkbox.closest("tr").classList.toggle(this.selectedRowClass, checkbox.checked)
171
167
  )
172
168
 
173
169
  // Update the selected rows count
@@ -138,7 +138,7 @@ class SolidusAdmin::UI::Table::Component < SolidusAdmin::BaseComponent
138
138
  predicate: filter.predicate,
139
139
  options: filter.options,
140
140
  form: search_form_id,
141
- index: index,
141
+ index:,
142
142
  )
143
143
  end
144
144