From a35ad4327fd5a933f428f42540d280a75139be53 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 12:01:51 +0200 Subject: [PATCH 01/35] Inherit from resources controller --- .../solidus_admin/option_types_controller.rb | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/admin/app/controllers/solidus_admin/option_types_controller.rb b/admin/app/controllers/solidus_admin/option_types_controller.rb index 444f1bbbafa..5ffaa0bb41e 100644 --- a/admin/app/controllers/solidus_admin/option_types_controller.rb +++ b/admin/app/controllers/solidus_admin/option_types_controller.rb @@ -1,24 +1,9 @@ # frozen_string_literal: true module SolidusAdmin - class OptionTypesController < SolidusAdmin::BaseController - include SolidusAdmin::ControllerHelpers::Search - + class OptionTypesController < SolidusAdmin::ResourcesController before_action :load_option_type, only: [:move] - def index - option_types = apply_search_to( - Spree::OptionType.all, - param: :q, - ) - - set_page_and_extract_portion_from(option_types) - - respond_to do |format| - format.html { render component('option_types/index').new(page: @page) } - end - end - def move @option_type.insert_at(params[:position].to_i) @@ -27,16 +12,15 @@ def move end end - def destroy - @option_types = Spree::OptionType.where(id: params[:id]) + private - Spree::OptionType.transaction { @option_types.destroy_all } + def resource_class = Spree::OptionType - flash[:notice] = t('.success') - redirect_back_or_to option_types_path, status: :see_other + def permitted_resource_params + params.require(:option_type).permit(:name, :presentation) end - private + def resources_collection = Spree::OptionType.unscoped def load_option_type @option_type = Spree::OptionType.find(params[:id]) From 1829357e9ca51477c033f6c0f586125f1ae65398 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 8 May 2025 15:41:46 +0200 Subject: [PATCH 02/35] Rename resource form turbo frame Since forms might be not only in modals, change the turbo frame name to be more general :resource_form --- .../adjustment_reasons/edit/component.html.erb | 2 +- .../adjustment_reasons/index/component.rb | 8 ++++---- .../adjustment_reasons/new/component.html.erb | 2 +- .../solidus_admin/properties/edit/component.html.erb | 2 +- .../solidus_admin/properties/index/component.rb | 8 ++++---- .../solidus_admin/properties/new/component.html.erb | 2 +- .../refund_reasons/edit/component.html.erb | 2 +- .../solidus_admin/refund_reasons/index/component.rb | 8 ++++---- .../refund_reasons/new/component.html.erb | 2 +- .../return_reasons/edit/component.html.erb | 2 +- .../solidus_admin/return_reasons/index/component.rb | 6 +++--- .../return_reasons/new/component.html.erb | 2 +- .../solidus_admin/roles/edit/component.html.erb | 2 +- .../components/solidus_admin/roles/index/component.rb | 8 ++++---- .../solidus_admin/roles/new/component.html.erb | 2 +- .../shipping_categories/edit/component.html.erb | 2 +- .../shipping_categories/index/component.rb | 6 +++--- .../shipping_categories/new/component.html.erb | 2 +- .../solidus_admin/stock_items/edit/component.html.erb | 2 +- .../solidus_admin/stock_items/index/component.rb | 6 +++--- .../store_credit_reasons/edit/component.html.erb | 2 +- .../store_credit_reasons/index/component.rb | 6 +++--- .../store_credit_reasons/new/component.html.erb | 2 +- .../tax_categories/edit/component.html.erb | 2 +- .../solidus_admin/tax_categories/index/component.rb | 10 +++++----- .../tax_categories/new/component.html.erb | 2 +- .../users/store_credits/edit_amount/component.html.erb | 2 +- .../users/store_credits/edit_memo/component.html.erb | 2 +- .../store_credits/edit_validity/component.html.erb | 2 +- .../users/store_credits/index/component.html.erb | 6 +++--- .../users/store_credits/new/component.html.erb | 2 +- .../users/store_credits/show/component.html.erb | 8 ++++---- .../solidus_admin/zones/form/component.html.erb | 2 +- .../components/solidus_admin/zones/index/component.rb | 8 ++++---- .../controllers/solidus_admin/resources_controller.rb | 6 +++++- .../promotion_categories/edit/component.html.erb | 2 +- .../promotion_categories/index/component.rb | 8 ++++---- .../promotion_categories/new/component.html.erb | 2 +- .../promotion_categories/edit/component.html.erb | 2 +- .../promotion_categories/index/component.rb | 8 ++++---- .../promotion_categories/new/component.html.erb | 2 +- 41 files changed, 83 insertions(+), 79 deletions(-) diff --git a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb index 8cc79b783f2..f1bd76aeb54 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb index a7ae5b6b6db..520007d4a0b 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -18,7 +18,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_adjustment_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -26,7 +26,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -52,7 +52,7 @@ def columns data: ->(adjustment_reason) do link_to adjustment_reason.name, edit_path(adjustment_reason), class: 'body-link', - data: { turbo_frame: :resource_modal } + data: { turbo_frame: :resource_form } end }, { @@ -60,7 +60,7 @@ def columns data: ->(adjustment_reason) do link_to adjustment_reason.code, edit_path(adjustment_reason), class: 'body-link', - data: { turbo_frame: :resource_modal } + data: { turbo_frame: :resource_form } end }, { diff --git a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb index 8cc79b783f2..f1bd76aeb54 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/adjustment_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @adjustment_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/properties/edit/component.html.erb b/admin/app/components/solidus_admin/properties/edit/component.html.erb index b2a90586684..cf56ae99a60 100644 --- a/admin/app/components/solidus_admin/properties/edit/component.html.erb +++ b/admin/app/components/solidus_admin/properties/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/properties/index/component.rb b/admin/app/components/solidus_admin/properties/index/component.rb index 9782ba2e624..e902f80aa16 100644 --- a/admin/app/components/solidus_admin/properties/index/component.rb +++ b/admin/app/components/solidus_admin/properties/index/component.rb @@ -22,7 +22,7 @@ def edit_path(property) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -30,7 +30,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_property_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -58,7 +58,7 @@ def name_column header: :name, data: ->(property) do link_to property.name, edit_path(property), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -69,7 +69,7 @@ def presentation_column header: :presentation, data: ->(property) do link_to property.presentation, edit_path(property), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/admin/app/components/solidus_admin/properties/new/component.html.erb b/admin/app/components/solidus_admin/properties/new/component.html.erb index b2a90586684..cf56ae99a60 100644 --- a/admin/app/components/solidus_admin/properties/new/component.html.erb +++ b/admin/app/components/solidus_admin/properties/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @property, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb index 630f10dfd16..e66db8f069c 100644 --- a/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/refund_reasons/index/component.rb b/admin/app/components/solidus_admin/refund_reasons/index/component.rb index 62d4f6b9d06..01c4046fd0a 100644 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -19,7 +19,7 @@ def edit_path(refund_reason) def turbo_frames %w[ - resource_modal + resource_form ] end @@ -28,7 +28,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_refund_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -51,7 +51,7 @@ def columns header: :name, data: ->(refund_reason) do link_to refund_reason.name, edit_path(refund_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -59,7 +59,7 @@ def columns header: :code, data: ->(refund_reason) do link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb index 72a6b996d7c..85482d1dec2 100644 --- a/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/refund_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @refund_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb index e1c6af09dc0..ade96525347 100644 --- a/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/return_reasons/index/component.rb b/admin/app/components/solidus_admin/return_reasons/index/component.rb index 594eac21696..e8fb147dd7a 100644 --- a/admin/app/components/solidus_admin/return_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb @@ -19,7 +19,7 @@ def edit_path(return_reason) def turbo_frames %w[ - resource_modal + resource_form ] end @@ -28,7 +28,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_return_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -51,7 +51,7 @@ def columns header: :name, data: ->(return_reason) do link_to return_reason.name, edit_path(return_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/return_reasons/new/component.html.erb b/admin/app/components/solidus_admin/return_reasons/new/component.html.erb index e1c6af09dc0..ade96525347 100644 --- a/admin/app/components/solidus_admin/return_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/return_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @return_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/roles/edit/component.html.erb b/admin/app/components/solidus_admin/roles/edit/component.html.erb index ff14e0363df..481132339aa 100644 --- a/admin/app/components/solidus_admin/roles/edit/component.html.erb +++ b/admin/app/components/solidus_admin/roles/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @role, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/roles/index/component.rb b/admin/app/components/solidus_admin/roles/index/component.rb index 97ce166278a..4a8f513301e 100644 --- a/admin/app/components/solidus_admin/roles/index/component.rb +++ b/admin/app/components/solidus_admin/roles/index/component.rb @@ -22,14 +22,14 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_role_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end def turbo_frames %w[ - resource_modal + resource_form ] end @@ -61,7 +61,7 @@ def columns header: :role, data: ->(role) do link_to role.name, edit_path(role), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end, }, @@ -69,7 +69,7 @@ def columns header: :description, data: ->(role) do link_to_if role.description, role.description, edit_path(role), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end } diff --git a/admin/app/components/solidus_admin/roles/new/component.html.erb b/admin/app/components/solidus_admin/roles/new/component.html.erb index 3216408ea58..a921f2e2d27 100644 --- a/admin/app/components/solidus_admin/roles/new/component.html.erb +++ b/admin/app/components/solidus_admin/roles/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @role, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb index b3e1b61981a..69b2ee08f8e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb +++ b/admin/app/components/solidus_admin/shipping_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @shipping_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/shipping_categories/index/component.rb b/admin/app/components/solidus_admin/shipping_categories/index/component.rb index 2302b16417e..2c303296914 100644 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/index/component.rb @@ -10,7 +10,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_shipping_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -18,7 +18,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(shipping_category) do link_to shipping_category.name, edit_url(shipping_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: "body-link" end }, diff --git a/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb b/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb index b3e1b61981a..69b2ee08f8e 100644 --- a/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb +++ b/admin/app/components/solidus_admin/shipping_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @shipping_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/stock_items/edit/component.html.erb b/admin/app/components/solidus_admin/stock_items/edit/component.html.erb index a0faf887296..c6d9725b49f 100644 --- a/admin/app/components/solidus_admin/stock_items/edit/component.html.erb +++ b/admin/app/components/solidus_admin/stock_items/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @stock_item, url: form_url, html: { id: form_id } do |f| %>
(stock_item) do link_to stock_item.variant.name, edit_path(stock_item), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -102,7 +102,7 @@ def sku_column header: :sku, data: ->(stock_item) do link_to stock_item.variant.sku, edit_path(stock_item), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -172,6 +172,6 @@ def count_on_hand_column end def turbo_frames - %w[resource_modal] + %w[resource_form] end end diff --git a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb index 432322ba69a..db080fb6831 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +++ b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb index 632c314147d..c1186925d28 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/store_credit_reasons/index/component.rb @@ -10,7 +10,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_store_credit_reason_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -18,7 +18,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(store_credit_reason) do link_to store_credit_reason.name, edit_path(store_credit_reason), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb b/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb index 432322ba69a..db080fb6831 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +++ b/admin/app/components/solidus_admin/store_credit_reasons/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit_reason, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb index d5b8b25115b..4fd0f5f25fa 100644 --- a/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb +++ b/admin/app/components/solidus_admin/tax_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/tax_categories/index/component.rb b/admin/app/components/solidus_admin/tax_categories/index/component.rb index 2937b3b2942..d7d2f40567c 100644 --- a/admin/app/components/solidus_admin/tax_categories/index/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/index/component.rb @@ -18,7 +18,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_tax_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -26,7 +26,7 @@ def page_actions def turbo_frames %w[ - resource_modal + resource_form ] end @@ -51,7 +51,7 @@ def columns header: :name, data: ->(tax_category) do link_to tax_category.name, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -59,7 +59,7 @@ def columns header: :tax_code, data: ->(tax_category) do link_to_if tax_category.tax_code, tax_category.tax_code, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, @@ -67,7 +67,7 @@ def columns header: :description, data: ->(tax_category) do link_to_if tax_category.description, tax_category.description, edit_path(tax_category), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end }, diff --git a/admin/app/components/solidus_admin/tax_categories/new/component.html.erb b/admin/app/components/solidus_admin/tax_categories/new/component.html.erb index d5b8b25115b..4fd0f5f25fa 100644 --- a/admin/app/components/solidus_admin/tax_categories/new/component.html.erb +++ b/admin/app/components/solidus_admin/tax_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @tax_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb index 61ff2d48d82..7a1327d4854 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb index 54ce226b3a4..e283df9bd7f 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb index fd91a48fb88..c838809b383 100644 --- a/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :put, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb index 06e06e1a1bd..ea58963369a 100644 --- a/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/index/component.html.erb @@ -8,7 +8,7 @@ tag: :a, href: new_store_credit_path, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, text: t(".add_store_credit"), icon: "add-line" @@ -47,7 +47,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: new_store_credit_path, text: t(".create_one"), @@ -61,5 +61,5 @@ <% end %> <% end %> - <%= turbo_frame_tag :resource_modal, target: "_top" %> + <%= turbo_frame_tag :resource_form, target: "_top" %> <% end %> diff --git a/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb index df37ce9b238..6e517fa6be1 100644 --- a/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @store_credit, url: form_url, method: :post, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb b/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb index 239faac3233..9d7fcde977b 100644 --- a/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb +++ b/admin/app/components/solidus_admin/users/store_credits/show/component.html.erb @@ -31,7 +31,7 @@ tag: :a, scheme: :danger, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_validity_url, text: t(".invalidate"), @@ -41,7 +41,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_memo_url, text: t(".edit_memo"), @@ -51,7 +51,7 @@ <%= render component("ui/button").new( tag: :a, data: { - turbo_frame: :resource_modal + turbo_frame: :resource_form }, href: edit_amount_url, text: t(".edit_amount"), @@ -79,5 +79,5 @@ <% end %> <% end %> - <%= turbo_frame_tag :resource_modal, target: "_top" %> + <%= turbo_frame_tag :resource_form, target: "_top" %> <% end %> diff --git a/admin/app/components/solidus_admin/zones/form/component.html.erb b/admin/app/components/solidus_admin/zones/form/component.html.erb index 3fdfecb436b..c96c26a1075 100644 --- a/admin/app/components/solidus_admin/zones/form/component.html.erb +++ b/admin/app/components/solidus_admin/zones/form/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title:) do |modal| %> <%= form_for @zone, url: @form_url, html: { id: @form_id, **stimulus_controller, **stimulus_value(name: :kind, value: @zone.kind) } do |f| %>
diff --git a/admin/app/components/solidus_admin/zones/index/component.rb b/admin/app/components/solidus_admin/zones/index/component.rb index 33390df6bea..747bf3399d1 100644 --- a/admin/app/components/solidus_admin/zones/index/component.rb +++ b/admin/app/components/solidus_admin/zones/index/component.rb @@ -22,7 +22,7 @@ def edit_path(zone) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -30,7 +30,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_zone_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", class: "align-self-end w-full", ) @@ -69,7 +69,7 @@ def name_column header: :name, data: ->(zone) do link_to zone.name, edit_path(zone), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -80,7 +80,7 @@ def description_column header: :description, data: ->(zone) do link_to zone.description, edit_path(zone), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index 7ebc49c7eaa..8c4161e63ca 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -129,7 +129,7 @@ def render_resource_form_with_errors(page_component) render page_component, status: :unprocessable_entity end format.turbo_stream do - render turbo_stream: turbo_stream.replace(:resource_modal, page_component), + render turbo_stream: turbo_stream.replace(resource_form_frame, page_component), status: :unprocessable_entity end end @@ -151,5 +151,9 @@ def after_update_path def after_destroy_path solidus_admin.send("#{plural_resource_name}_path", **search_filter_params) end + + def resource_form_frame + :resource_form + end end end diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb index 35f8574f999..e8d0fa6ea81 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/index/component.rb @@ -14,7 +14,7 @@ def edit_path(record) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -22,7 +22,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_promotion_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -50,7 +50,7 @@ def name_column header: :name, data: ->(record) do link_to record.name, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -61,7 +61,7 @@ def code_column header: :code, data: ->(record) do link_to record.code, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb +++ b/legacy_promotions/lib/components/admin/solidus_admin/promotion_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/edit/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb index d908005d267..9ff6b534244 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/index/component.rb @@ -14,7 +14,7 @@ def edit_path(record) end def turbo_frames - %w[resource_modal] + %w[resource_form] end def page_actions @@ -22,7 +22,7 @@ def page_actions tag: :a, text: t(".add"), href: solidus_promotions.new_promotion_category_path(**search_filter_params), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, icon: "add-line" ) end @@ -50,7 +50,7 @@ def name_column header: :name, data: ->(record) do link_to record.name, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } @@ -61,7 +61,7 @@ def code_column header: :code, data: ->(record) do link_to record.code, edit_path(record), - data: { turbo_frame: :resource_modal }, + data: { turbo_frame: :resource_form }, class: 'body-link' end } diff --git a/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb b/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb index f0f59dc8548..6bb6300c329 100644 --- a/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb +++ b/promotions/lib/components/admin/solidus_promotions/promotion_categories/new/component.html.erb @@ -1,4 +1,4 @@ -<%= turbo_frame_tag :resource_modal, target: "_top" do %> +<%= turbo_frame_tag :resource_form, target: "_top" do %> <%= render component("ui/modal").new(title: t(".title")) do |modal| %> <%= form_for @promotion_category, url: form_url, html: { id: form_id } do |f| %>
From 74f3ceb39ebbd8bfaa2a162cdc8cf2bef1cbf4e5 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 12:04:25 +0200 Subject: [PATCH 03/35] Add modal to create new option type --- .../option_types/index/component.rb | 12 ++++++++++-- .../option_types/new/component.html.erb | 16 ++++++++++++++++ .../solidus_admin/option_types/new/component.rb | 4 ++++ .../solidus_admin/option_types/new/component.yml | 4 ++++ admin/config/locales/option_types.en.yml | 4 +++- admin/config/routes.rb | 2 +- admin/spec/features/option_types_spec.rb | 2 +- 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 admin/app/components/solidus_admin/option_types/new/component.html.erb create mode 100644 admin/app/components/solidus_admin/option_types/new/component.rb create mode 100644 admin/app/components/solidus_admin/option_types/new/component.yml diff --git a/admin/app/components/solidus_admin/option_types/index/component.rb b/admin/app/components/solidus_admin/option_types/index/component.rb index 288931a0fd2..f00e0fc38d6 100644 --- a/admin/app/components/solidus_admin/option_types/index/component.rb +++ b/admin/app/components/solidus_admin/option_types/index/component.rb @@ -12,11 +12,16 @@ def sortable_options } end + def turbo_frames + %w[resource_form] + end + def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: spree.new_admin_option_type_path, + href: solidus_admin.new_option_type_path, + data: { turbo_frame: :resource_form }, icon: "add-line", ) end @@ -60,7 +65,10 @@ def name_column def presentation_column { header: :presentation, - data: ->(option_type) { option_type.presentation } + data: ->(option_type) do + link_to option_type.presentation, edit_path(option_type), + class: 'body-link' + end } end diff --git a/admin/app/components/solidus_admin/option_types/new/component.html.erb b/admin/app/components/solidus_admin/option_types/new/component.html.erb new file mode 100644 index 00000000000..6e4dacb5b89 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/new/component.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :resource_form, target: "_top" do %> + <%= render component("ui/modal").new(title: t(".title")) do |modal| %> + <%= form_for @option_type, url: form_url, html: { id: form_id } do |f| %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% modal.with_actions do %> +
+ <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> +
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_types/new/component.rb b/admin/app/components/solidus_admin/option_types/new/component.rb new file mode 100644 index 00000000000..fc791bdebc2 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/new/component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionTypes::New::Component < SolidusAdmin::Resources::New::Component +end diff --git a/admin/app/components/solidus_admin/option_types/new/component.yml b/admin/app/components/solidus_admin/option_types/new/component.yml new file mode 100644 index 00000000000..6b233d44a0c --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/new/component.yml @@ -0,0 +1,4 @@ +en: + title: "New Option Type" + cancel: "Cancel" + submit: "Add Option Type" diff --git a/admin/config/locales/option_types.en.yml b/admin/config/locales/option_types.en.yml index fb439e8d07b..3e127771321 100644 --- a/admin/config/locales/option_types.en.yml +++ b/admin/config/locales/option_types.en.yml @@ -2,5 +2,7 @@ en: solidus_admin: option_types: title: "Option Types" + create: + success: "Option type was successfully created." destroy: - success: "Option Types were successfully removed." + success: "Option types were successfully removed." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index ec215522965..53f9ba9a653 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -69,7 +69,7 @@ admin_resources :promotions, only: [:index, :destroy] admin_resources :properties, except: [:show] - admin_resources :option_types, only: [:index, :destroy], sortable: true + admin_resources :option_types, only: [:index, :destroy, :new, :create], sortable: true admin_resources :taxonomies, only: [:index, :destroy], sortable: true admin_resources :promotion_categories, only: [:index, :destroy] admin_resources :tax_categories, except: [:show] diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index 10181e7d009..e50f2d75876 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -17,7 +17,7 @@ select_row("color") click_on "Delete" - expect(page).to have_content("Option Types were successfully removed.") + expect(page).to have_content("Option types were successfully removed.") expect(page).not_to have_content("color") expect(Spree::OptionType.count).to eq(1) end From 79910a2485be3955dfa3367597bca2b2c66a7b85 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 13:03:15 +0200 Subject: [PATCH 04/35] Allow option types sorting Sortable URL parameter, which is required for sorting to work properly, was not present for option types table after changing the index table to use explicit links rather than `row_url`s, due to condition in the table component template. Here we move `data-sortable-url` attribute out of the condition, so it's applicable to any index page that defines `sortable_options`. --- .../app/components/solidus_admin/ui/table/component.html.erb | 2 +- .../app/controllers/solidus_admin/option_types_controller.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/admin/app/components/solidus_admin/ui/table/component.html.erb b/admin/app/components/solidus_admin/ui/table/component.html.erb index 9cbdb312ade..ecc1ef1d69e 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -144,8 +144,8 @@ <% if row_url %> data-action="click-><%= stimulus_id %>#rowClicked" data-<%= stimulus_id %>-url-param="<%= row_url %>" - <%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %> <% end %> + <%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %> > <% @data.columns.each do |column| %> <%= render_data_cell(column, row) %> diff --git a/admin/app/controllers/solidus_admin/option_types_controller.rb b/admin/app/controllers/solidus_admin/option_types_controller.rb index 5ffaa0bb41e..d9a9700b1e7 100644 --- a/admin/app/controllers/solidus_admin/option_types_controller.rb +++ b/admin/app/controllers/solidus_admin/option_types_controller.rb @@ -22,6 +22,10 @@ def permitted_resource_params def resources_collection = Spree::OptionType.unscoped + def resources_sorting_options + { position: :asc } + end + def load_option_type @option_type = Spree::OptionType.find(params[:id]) authorize! action_name, @option_type From 825fc6eeed0dec2c49432ebd9369ca8b9c0f8bfd Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 17:54:59 +0200 Subject: [PATCH 05/35] Require confirmation on batch delete --- .../components/solidus_admin/option_types/index/component.rb | 1 + admin/spec/features/option_types_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/app/components/solidus_admin/option_types/index/component.rb b/admin/app/components/solidus_admin/option_types/index/component.rb index f00e0fc38d6..a30968d1f9d 100644 --- a/admin/app/components/solidus_admin/option_types/index/component.rb +++ b/admin/app/components/solidus_admin/option_types/index/component.rb @@ -41,6 +41,7 @@ def batch_actions action: solidus_admin.option_types_path, method: :delete, icon: 'delete-bin-7-line', + require_confirmation: true, }, ] end diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index e50f2d75876..f98f4763a41 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -16,7 +16,7 @@ expect(page).to be_axe_clean select_row("color") - click_on "Delete" + accept_confirm("Are you sure you want to delete 1 option type?") { click_on "Delete" } expect(page).to have_content("Option types were successfully removed.") expect(page).not_to have_content("color") expect(Spree::OptionType.count).to eq(1) From 96d88d8507954f2b405f7e1381f94fcc637ff449 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 16 May 2025 14:41:55 +0200 Subject: [PATCH 06/35] Allow UI table to be embedded If embedded, table container won't have a border, this will allow for a table to be rendered inside a panel section without unnecessary spacing. --- .../app/components/solidus_admin/ui/table/component.html.erb | 4 +--- admin/app/components/solidus_admin/ui/table/component.rb | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/table/component.html.erb b/admin/app/components/solidus_admin/ui/table/component.html.erb index ecc1ef1d69e..400c745ace1 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -1,8 +1,6 @@
Date: Thu, 15 May 2025 18:14:25 +0200 Subject: [PATCH 07/35] Use `href` in `` `xlink:href` is deprecated per https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/xlink:href, recommendation is to use `href` attribute instead. Leaving `xlink:href` as a fallback option just in case. --- admin/app/components/solidus_admin/ui/icon/component.rb | 2 +- admin/spec/components/solidus_admin/base_component_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/app/components/solidus_admin/ui/icon/component.rb b/admin/app/components/solidus_admin/ui/icon/component.rb index d2736e6afd6..b66e13ea061 100644 --- a/admin/app/components/solidus_admin/ui/icon/component.rb +++ b/admin/app/components/solidus_admin/ui/icon/component.rb @@ -26,6 +26,6 @@ def call # bypass the asset_host configuration to avoid CORS issues with CDNs: # https://github.com/solidusio/solidus/issues/5657 href = asset_path("solidus_admin/remixicon.symbol.svg#ri-#{@name}", host: "") - tag.svg(tag.use("xlink:href": href), **@attrs) + tag.svg(tag.use("xlink:href": href, href:), **@attrs) end end diff --git a/admin/spec/components/solidus_admin/base_component_spec.rb b/admin/spec/components/solidus_admin/base_component_spec.rb index 6794d308022..5a9cec439ce 100644 --- a/admin/spec/components/solidus_admin/base_component_spec.rb +++ b/admin/spec/components/solidus_admin/base_component_spec.rb @@ -13,7 +13,7 @@ def call render_inline(component) - svg = page.find("svg use")["xlink:href"] + svg = page.find("svg use")["href"] expect(svg).to match(/#ri-user-line/) end end From a65d5996d1082dd46967dff6762370dc2907e169 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 18:45:42 +0200 Subject: [PATCH 08/35] Add option types edit component with simple fields --- .../option_types/edit/component.html.erb | 26 +++++++++++++++++++ .../option_types/edit/component.rb | 5 ++++ .../option_types/edit/component.yml | 10 +++++++ .../option_types/index/component.rb | 2 +- admin/config/locales/option_types.en.yml | 2 ++ admin/config/routes.rb | 2 +- 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 admin/app/components/solidus_admin/option_types/edit/component.html.erb create mode 100644 admin/app/components/solidus_admin/option_types/edit/component.rb create mode 100644 admin/app/components/solidus_admin/option_types/edit/component.yml diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb new file mode 100644 index 00000000000..4e496dc1ff2 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -0,0 +1,26 @@ +<%= turbo_frame_tag :resource_form, target: "_top" do %> + <%= page do %> + <%= page_header do %> + <%= page_header_back(back_url) %> + <%= page_header_title(t('.title')) %> + <%= page_header_actions do %> + <%= render component("ui/button").new(text: t(".save"),form: form_id) %> + <% end %> + <% end %> + + <%= form_for @option_type, url: form_url, html: { id: form_id } do |f| %> + <%= render component('ui/panel').new(title: t(".panels.option_type.title")) do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% end %> + <% end %> + <% end %> + + <%= page_footer do %> + <%= render component("ui/button").new(text: t(".save"), form: form_id) %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_types/edit/component.rb b/admin/app/components/solidus_admin/option_types/edit/component.rb new file mode 100644 index 00000000000..ec40c3e2fd0 --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/edit/component.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionTypes::Edit::Component < SolidusAdmin::Resources::Edit::Component + include SolidusAdmin::Layout::PageHelpers +end diff --git a/admin/app/components/solidus_admin/option_types/edit/component.yml b/admin/app/components/solidus_admin/option_types/edit/component.yml new file mode 100644 index 00000000000..108d8f6fa7f --- /dev/null +++ b/admin/app/components/solidus_admin/option_types/edit/component.yml @@ -0,0 +1,10 @@ +en: + back: "Back" + panels: + option_type: + title: "Option Type" + option_values: + title: "Option Values" + add: "Add new" + save: "Save" + title: "Edit Option Type" diff --git a/admin/app/components/solidus_admin/option_types/index/component.rb b/admin/app/components/solidus_admin/option_types/index/component.rb index a30968d1f9d..86993d22df1 100644 --- a/admin/app/components/solidus_admin/option_types/index/component.rb +++ b/admin/app/components/solidus_admin/option_types/index/component.rb @@ -74,6 +74,6 @@ def presentation_column end def edit_path(option_type) - spree.edit_admin_option_type_path(option_type) + solidus_admin.edit_option_type_path(option_type) end end diff --git a/admin/config/locales/option_types.en.yml b/admin/config/locales/option_types.en.yml index 3e127771321..df3e4da4eb1 100644 --- a/admin/config/locales/option_types.en.yml +++ b/admin/config/locales/option_types.en.yml @@ -6,3 +6,5 @@ en: success: "Option type was successfully created." destroy: success: "Option types were successfully removed." + update: + success: "Option type was successfully updated." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 53f9ba9a653..816e0b08eff 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -69,7 +69,7 @@ admin_resources :promotions, only: [:index, :destroy] admin_resources :properties, except: [:show] - admin_resources :option_types, only: [:index, :destroy, :new, :create], sortable: true + admin_resources :option_types, except: [:show], sortable: true admin_resources :taxonomies, only: [:index, :destroy], sortable: true admin_resources :promotion_categories, only: [:index, :destroy] admin_resources :tax_categories, except: [:show] From f9288fe2baa9e6b1c3c26dce99da362bc03e5b2d Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 19:13:32 +0200 Subject: [PATCH 09/35] Redirect to edit page after creation This replicates legacy admin flow where newly created option type is shown with ability to add option values. --- .../app/controllers/solidus_admin/option_types_controller.rb | 4 ++++ admin/app/controllers/solidus_admin/resources_controller.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/admin/app/controllers/solidus_admin/option_types_controller.rb b/admin/app/controllers/solidus_admin/option_types_controller.rb index d9a9700b1e7..a2255e65b76 100644 --- a/admin/app/controllers/solidus_admin/option_types_controller.rb +++ b/admin/app/controllers/solidus_admin/option_types_controller.rb @@ -14,6 +14,10 @@ def move private + def after_create_path + solidus_admin.edit_option_type_path(@resource) + end + def resource_class = Spree::OptionType def permitted_resource_params diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index 8c4161e63ca..9867d420e10 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -43,7 +43,9 @@ def create end def edit - render edit_component.new(@resource) + respond_to do |format| + format.html { render edit_component.new(@resource) } + end end def update From ff8e66910d52e21c11ccf8111f3709c84abfce65 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 15 May 2025 19:45:48 +0200 Subject: [PATCH 10/35] Add panel container for option values table --- .../option_types/edit/component.html.erb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb index 4e496dc1ff2..8c2be13192c 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.html.erb +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -8,8 +8,8 @@ <% end %> <% end %> - <%= form_for @option_type, url: form_url, html: { id: form_id } do |f| %> - <%= render component('ui/panel').new(title: t(".panels.option_type.title")) do |panel| %> + <%= form_for @option_type, url: form_url, html: { id: form_id, class: "flex flex-col gap-4" } do |f| %> + <%= render component("ui/panel").new(title: t(".panels.option_type.title")) do |panel| %> <% panel.with_section(class: "flex flex-col gap-4") do %>
<%= render component("ui/forms/field").text_field(f, :name, class: "required") %> @@ -17,6 +17,13 @@
<% end %> <% end %> + + <%= render component("ui/panel").new(title: t(".panels.option_values.title")) do |panel| %> + <% panel.with_section(wide: true, high: true, class: "flex flex-col gap-4") do %> + <% end %> + + <% panel.with_action(name: t(".panels.option_values.add"), href: "#") %> + <% end %> <% end %> <%= page_footer do %> From 7a8820f14530ee4178e8f8a1b3565dcb050d93cc Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 16 May 2025 14:52:13 +0200 Subject: [PATCH 11/35] Add table for option values --- .../option_types/edit/component.html.erb | 1 + .../option_types/edit/component.rb | 44 +++++++++++++++++++ .../option_types/edit/component.yml | 2 + 3 files changed, 47 insertions(+) diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb index 8c2be13192c..81b51d3ea2e 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.html.erb +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -20,6 +20,7 @@ <%= render component("ui/panel").new(title: t(".panels.option_values.title")) do |panel| %> <% panel.with_section(wide: true, high: true, class: "flex flex-col gap-4") do %> + <%= render_option_values %> <% end %> <% panel.with_action(name: t(".panels.option_values.add"), href: "#") %> diff --git a/admin/app/components/solidus_admin/option_types/edit/component.rb b/admin/app/components/solidus_admin/option_types/edit/component.rb index ec40c3e2fd0..fc9d86f3ccd 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.rb +++ b/admin/app/components/solidus_admin/option_types/edit/component.rb @@ -2,4 +2,48 @@ class SolidusAdmin::OptionTypes::Edit::Component < SolidusAdmin::Resources::Edit::Component include SolidusAdmin::Layout::PageHelpers + + def render_option_values + render component("ui/table").new( + id: stimulus_id, + data: { + class: Spree::OptionValue, + rows: @option_type.option_values, + columns: option_value_columns, + batch_actions: [ + { + label: t('.panels.option_values.batch_actions.delete'), + action: solidus_admin.option_values_path, + method: :delete, + icon: 'delete-bin-7-line', + require_confirmation: true, + }, + ] + }, + sortable: { + url: ->(option_value) { solidus_admin.move_option_value_path(option_value) }, + param: "position", + }, + embedded: true, + ) + end + + def option_value_columns + [ + { + header: :name, + data: ->(option_value) do + link_to option_value.name, "#", + class: 'body-link' + end + }, + { + header: :presentation, + data: ->(option_value) do + link_to option_value.presentation, "#", + class: 'body-link' + end + }, + ] + end end diff --git a/admin/app/components/solidus_admin/option_types/edit/component.yml b/admin/app/components/solidus_admin/option_types/edit/component.yml index 108d8f6fa7f..e6232d8fd5d 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.yml +++ b/admin/app/components/solidus_admin/option_types/edit/component.yml @@ -6,5 +6,7 @@ en: option_values: title: "Option Values" add: "Add new" + batch_actions: + delete: "Delete" save: "Save" title: "Edit Option Type" From ba2f16936244acd2929baf003113e355a929e633 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Wed, 21 May 2025 14:12:04 +0200 Subject: [PATCH 12/35] Add batch delete functionality for option values --- .../solidus_admin/option_values_controller.rb | 10 ++++++++++ admin/config/locales/option_values.en.yml | 5 +++++ admin/config/routes.rb | 1 + 3 files changed, 16 insertions(+) create mode 100644 admin/app/controllers/solidus_admin/option_values_controller.rb create mode 100644 admin/config/locales/option_values.en.yml diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb new file mode 100644 index 00000000000..48d829cd0b9 --- /dev/null +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module SolidusAdmin + class OptionValuesController < SolidusAdmin::ResourcesController + + private + + def resource_class = Spree::OptionValue + end +end diff --git a/admin/config/locales/option_values.en.yml b/admin/config/locales/option_values.en.yml new file mode 100644 index 00000000000..3b7845e46c7 --- /dev/null +++ b/admin/config/locales/option_values.en.yml @@ -0,0 +1,5 @@ +en: + solidus_admin: + option_values: + destroy: + success: "Option values were successfully removed." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 816e0b08eff..6271225f11a 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -70,6 +70,7 @@ admin_resources :promotions, only: [:index, :destroy] admin_resources :properties, except: [:show] admin_resources :option_types, except: [:show], sortable: true + admin_resources :option_values, only: [:destroy], sortable: true admin_resources :taxonomies, only: [:index, :destroy], sortable: true admin_resources :promotion_categories, only: [:index, :destroy] admin_resources :tax_categories, except: [:show] From 983c22cfbfa44d19cc79ee00bb96bf1be7d42a35 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Wed, 21 May 2025 15:01:53 +0200 Subject: [PATCH 13/35] Enable sorting of existing option values --- .../solidus_admin/option_values_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index 48d829cd0b9..4c17cf8592e 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -2,9 +2,23 @@ module SolidusAdmin class OptionValuesController < SolidusAdmin::ResourcesController + before_action :load_option_value, only: [:move] + + def move + @option_value.insert_at(params[:position].to_i) + + respond_to do |format| + format.js { head :no_content } + end + end private def resource_class = Spree::OptionValue + + def load_option_value + @option_value = Spree::OptionValue.find(params[:id]) + authorize! action_name, @option_value + end end end From 5572bd66cbfa74158a15cfa6e6acfc0adccbe18d Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Wed, 21 May 2025 15:30:13 +0200 Subject: [PATCH 14/35] Create controller concern for `move` action --- .../concerns/solidus_admin/moveable.rb | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 admin/app/controllers/concerns/solidus_admin/moveable.rb diff --git a/admin/app/controllers/concerns/solidus_admin/moveable.rb b/admin/app/controllers/concerns/solidus_admin/moveable.rb new file mode 100644 index 00000000000..a1f3756d0de --- /dev/null +++ b/admin/app/controllers/concerns/solidus_admin/moveable.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module SolidusAdmin::Moveable + extend ActiveSupport::Concern + + included do + before_action :load_moveable, only: [:move] + end + + def move + @moveable.insert_at(params.require(:position).to_i) + + respond_to do |format| + format.js { head :no_content } + end + end + + private + + def load_moveable + @moveable = moveable_class.find(params.require(:id)) + authorize! action_name, @moveable + end + + def moveable_class + "Spree::#{self.class.name.demodulize.remove('Controller').singularize}".constantize + rescue NameError + raise NameError, + "could not infer model class from #{self.class.name}. Please override `moveable_class` to specify it explicitly." + end +end From bd470e11d08768be54ce24b0078c783255a869b4 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Wed, 21 May 2025 15:35:28 +0200 Subject: [PATCH 15/35] Cleanup controllers with moveable concern --- .../solidus_admin/option_types_controller.rb | 15 +-------------- .../solidus_admin/option_values_controller.rb | 15 +-------------- .../payment_methods_controller.rb | 18 +----------------- .../solidus_admin/taxonomies_controller.rb | 18 +----------------- 4 files changed, 4 insertions(+), 62 deletions(-) diff --git a/admin/app/controllers/solidus_admin/option_types_controller.rb b/admin/app/controllers/solidus_admin/option_types_controller.rb index a2255e65b76..08b2e45a32c 100644 --- a/admin/app/controllers/solidus_admin/option_types_controller.rb +++ b/admin/app/controllers/solidus_admin/option_types_controller.rb @@ -2,15 +2,7 @@ module SolidusAdmin class OptionTypesController < SolidusAdmin::ResourcesController - before_action :load_option_type, only: [:move] - - def move - @option_type.insert_at(params[:position].to_i) - - respond_to do |format| - format.js { head :no_content } - end - end + include SolidusAdmin::Moveable private @@ -29,10 +21,5 @@ def resources_collection = Spree::OptionType.unscoped def resources_sorting_options { position: :asc } end - - def load_option_type - @option_type = Spree::OptionType.find(params[:id]) - authorize! action_name, @option_type - end end end diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index 4c17cf8592e..6d3e8d82bc9 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -2,23 +2,10 @@ module SolidusAdmin class OptionValuesController < SolidusAdmin::ResourcesController - before_action :load_option_value, only: [:move] - - def move - @option_value.insert_at(params[:position].to_i) - - respond_to do |format| - format.js { head :no_content } - end - end + include SolidusAdmin::Moveable private def resource_class = Spree::OptionValue - - def load_option_value - @option_value = Spree::OptionValue.find(params[:id]) - authorize! action_name, @option_value - end end end diff --git a/admin/app/controllers/solidus_admin/payment_methods_controller.rb b/admin/app/controllers/solidus_admin/payment_methods_controller.rb index 684eb7381f3..fc3ce0316dd 100644 --- a/admin/app/controllers/solidus_admin/payment_methods_controller.rb +++ b/admin/app/controllers/solidus_admin/payment_methods_controller.rb @@ -3,8 +3,7 @@ module SolidusAdmin class PaymentMethodsController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - - before_action :load_payment_method, only: [:move] + include SolidusAdmin::Moveable search_scope(:all) search_scope(:active, default: true, &:active) @@ -25,14 +24,6 @@ def index end end - def move - @payment_method.insert_at(params[:position].to_i) - - respond_to do |format| - format.js { head :no_content } - end - end - def destroy @payment_methods = Spree::PaymentMethod.where(id: params[:id]) @@ -41,12 +32,5 @@ def destroy flash[:notice] = t('.success') redirect_back_or_to payment_methods_path, status: :see_other end - - private - - def load_payment_method - @payment_method = Spree::PaymentMethod.find_by!(id: params[:id]) - authorize! action_name, @payment_method - end end end diff --git a/admin/app/controllers/solidus_admin/taxonomies_controller.rb b/admin/app/controllers/solidus_admin/taxonomies_controller.rb index fb0387d075a..3c6b4cdc2db 100644 --- a/admin/app/controllers/solidus_admin/taxonomies_controller.rb +++ b/admin/app/controllers/solidus_admin/taxonomies_controller.rb @@ -3,8 +3,7 @@ module SolidusAdmin class TaxonomiesController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - - before_action :load_taxonomy, only: [:move] + include SolidusAdmin::Moveable def index taxonomies = apply_search_to( @@ -19,14 +18,6 @@ def index end end - def move - @taxonomy.insert_at(params[:position].to_i) - - respond_to do |format| - format.js { head :no_content } - end - end - def destroy @taxonomies = Spree::Taxonomy.where(id: params[:id]) @@ -35,12 +26,5 @@ def destroy flash[:notice] = t('.success') redirect_back_or_to taxonomies_path, status: :see_other end - - private - - def load_taxonomy - @taxonomy = Spree::Taxonomy.find(params[:id]) - authorize! action_name, @taxonomy - end end end From aafe0b0daa0020d9f611d40664780da5d27929b9 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 22 May 2025 20:48:28 +0200 Subject: [PATCH 16/35] Update elements nesting Option values table was not meant to be nested inside the form. --- .../option_types/edit/component.html.erb | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb index 81b51d3ea2e..504859e6eb5 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.html.erb +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -8,13 +8,15 @@ <% end %> <% end %> - <%= form_for @option_type, url: form_url, html: { id: form_id, class: "flex flex-col gap-4" } do |f| %> - <%= render component("ui/panel").new(title: t(".panels.option_type.title")) do |panel| %> - <% panel.with_section(class: "flex flex-col gap-4") do %> -
- <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> - <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> -
+
+ <%= form_for @option_type, url: form_url, html: { id: form_id } do |f| %> + <%= render component("ui/panel").new(title: t(".panels.option_type.title")) do |panel| %> + <% panel.with_section(class: "flex flex-col gap-4") do %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% end %> <% end %> <% end %> @@ -25,10 +27,10 @@ <% panel.with_action(name: t(".panels.option_values.add"), href: "#") %> <% end %> - <% end %> - <%= page_footer do %> - <%= render component("ui/button").new(text: t(".save"), form: form_id) %> - <% end %> + <%= page_footer do %> + <%= render component("ui/button").new(text: t(".save"), form: form_id) %> + <% end %> +
<% end %> <% end %> From 1a65817d78fcab0d469d4f2735b26e022fbdf762 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 22 May 2025 23:43:57 +0200 Subject: [PATCH 17/35] Update CRUD for option values Adds modals for option value add/edit --- .../option_types/edit/component.html.erb | 8 ++++- .../option_types/edit/component.rb | 10 +++--- .../option_values/edit/component.html.erb | 16 ++++++++++ .../option_values/edit/component.rb | 4 +++ .../option_values/edit/component.yml | 4 +++ .../option_values/new/component.html.erb | 16 ++++++++++ .../option_values/new/component.rb | 7 ++++ .../option_values/new/component.yml | 4 +++ .../solidus_admin/option_values_controller.rb | 32 +++++++++++++++++++ .../solidus_admin/resources_controller.rb | 4 +-- admin/config/locales/option_values.en.yml | 4 +++ admin/config/routes.rb | 6 ++-- 12 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 admin/app/components/solidus_admin/option_values/edit/component.html.erb create mode 100644 admin/app/components/solidus_admin/option_values/edit/component.rb create mode 100644 admin/app/components/solidus_admin/option_values/edit/component.yml create mode 100644 admin/app/components/solidus_admin/option_values/new/component.html.erb create mode 100644 admin/app/components/solidus_admin/option_values/new/component.rb create mode 100644 admin/app/components/solidus_admin/option_values/new/component.yml diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb index 504859e6eb5..79a812d8fae 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.html.erb +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -25,12 +25,18 @@ <%= render_option_values %> <% end %> - <% panel.with_action(name: t(".panels.option_values.add"), href: "#") %> + <% panel.with_action( + name: t(".panels.option_values.add"), + href: solidus_admin.new_option_type_option_value_path(@option_type), + data: { turbo_frame: :option_value_modal } + ) %> <% end %> <%= page_footer do %> <%= render component("ui/button").new(text: t(".save"), form: form_id) %> <% end %>
+ + <%= turbo_frame_tag :option_value_modal, target: "_top" %> <% end %> <% end %> diff --git a/admin/app/components/solidus_admin/option_types/edit/component.rb b/admin/app/components/solidus_admin/option_types/edit/component.rb index fc9d86f3ccd..accc5577267 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.rb +++ b/admin/app/components/solidus_admin/option_types/edit/component.rb @@ -33,15 +33,17 @@ def option_value_columns { header: :name, data: ->(option_value) do - link_to option_value.name, "#", - class: 'body-link' + link_to option_value.name, solidus_admin.edit_option_value_path(option_value), + class: 'body-link', + data: { turbo_frame: :option_value_modal } end }, { header: :presentation, data: ->(option_value) do - link_to option_value.presentation, "#", - class: 'body-link' + link_to option_value.presentation, solidus_admin.edit_option_value_path(option_value), + class: 'body-link', + data: { turbo_frame: :option_value_modal } end }, ] diff --git a/admin/app/components/solidus_admin/option_values/edit/component.html.erb b/admin/app/components/solidus_admin/option_values/edit/component.html.erb new file mode 100644 index 00000000000..90d343ce8a1 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/edit/component.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :option_value_modal, target: "_top" do %> + <%= render component("ui/modal").new(title: t(".title")) do |modal| %> + <%= form_for @option_value, url: form_url, html: { id: form_id } do |f| %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% modal.with_actions do %> +
+ <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> +
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_values/edit/component.rb b/admin/app/components/solidus_admin/option_values/edit/component.rb new file mode 100644 index 00000000000..3dd3368e98a --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/edit/component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionValues::Edit::Component < SolidusAdmin::Resources::Edit::Component +end diff --git a/admin/app/components/solidus_admin/option_values/edit/component.yml b/admin/app/components/solidus_admin/option_values/edit/component.yml new file mode 100644 index 00000000000..399dfe74216 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/edit/component.yml @@ -0,0 +1,4 @@ +en: + title: "Edit Option Value" + cancel: "Cancel" + submit: "Update Option Value" diff --git a/admin/app/components/solidus_admin/option_values/new/component.html.erb b/admin/app/components/solidus_admin/option_values/new/component.html.erb new file mode 100644 index 00000000000..90d343ce8a1 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/new/component.html.erb @@ -0,0 +1,16 @@ +<%= turbo_frame_tag :option_value_modal, target: "_top" do %> + <%= render component("ui/modal").new(title: t(".title")) do |modal| %> + <%= form_for @option_value, url: form_url, html: { id: form_id } do |f| %> +
+ <%= render component("ui/forms/field").text_field(f, :name, class: "required") %> + <%= render component("ui/forms/field").text_field(f, :presentation, class: "required") %> +
+ <% modal.with_actions do %> +
+ <%= render component("ui/button").new(scheme: :secondary, text: t('.cancel')) %> +
+ <%= render component("ui/button").new(form: form_id, type: :submit, text: t('.submit')) %> + <% end %> + <% end %> + <% end %> +<% end %> diff --git a/admin/app/components/solidus_admin/option_values/new/component.rb b/admin/app/components/solidus_admin/option_values/new/component.rb new file mode 100644 index 00000000000..9d48574c110 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/new/component.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionValues::New::Component < SolidusAdmin::Resources::New::Component + def form_url + solidus_admin.option_type_option_values_path(@option_value.option_type) + end +end diff --git a/admin/app/components/solidus_admin/option_values/new/component.yml b/admin/app/components/solidus_admin/option_values/new/component.yml new file mode 100644 index 00000000000..11043a335d2 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/new/component.yml @@ -0,0 +1,4 @@ +en: + title: "New Option Value" + cancel: "Cancel" + submit: "Add Option Value" diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index 6d3e8d82bc9..b95235296ba 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -4,8 +4,40 @@ module SolidusAdmin class OptionValuesController < SolidusAdmin::ResourcesController include SolidusAdmin::Moveable + before_action :set_option_type, only: [:new, :create] + + def new + @resource = @option_type.option_values.build + super + end + + def create + @resource = @option_type.option_values.build(permitted_resource_params) + super + end + private def resource_class = Spree::OptionValue + + def permitted_resource_params + params.require(:option_value).permit(:name, :presentation) + end + + def resource_form_frame + :option_value_modal + end + + def after_create_path + solidus_admin.edit_option_type_path(@option_type) + end + + def after_update_path + solidus_admin.edit_option_type_path(@option_value.option_type) + end + + def set_option_type + @option_type = Spree::OptionType.find(params[:option_type_id]) + end end end diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index 9867d420e10..56af918a2e9 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -26,12 +26,12 @@ def index end def new - @resource = resource_class.new + @resource ||= resource_class.new render new_component.new(@resource) end def create - @resource = resource_class.new(permitted_resource_params) + @resource ||= resource_class.new(permitted_resource_params) if @resource.save flash[:notice] = t('.success') diff --git a/admin/config/locales/option_values.en.yml b/admin/config/locales/option_values.en.yml index 3b7845e46c7..247aff91121 100644 --- a/admin/config/locales/option_values.en.yml +++ b/admin/config/locales/option_values.en.yml @@ -1,5 +1,9 @@ en: solidus_admin: option_values: + create: + success: "Option value was successfully created." destroy: success: "Option values were successfully removed." + update: + success: "Option value was successfully updated." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 6271225f11a..14e34b6fc32 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -69,8 +69,10 @@ admin_resources :promotions, only: [:index, :destroy] admin_resources :properties, except: [:show] - admin_resources :option_types, except: [:show], sortable: true - admin_resources :option_values, only: [:destroy], sortable: true + admin_resources :option_types, except: [:show], sortable: true do + resources :option_values, only: [:new, :create], controller: "option_values" + end + admin_resources :option_values, only: [:edit, :update, :destroy], sortable: true admin_resources :taxonomies, only: [:index, :destroy], sortable: true admin_resources :promotion_categories, only: [:index, :destroy] admin_resources :tax_categories, except: [:show] From 99521958bda841db53047aa85b74aac7df8ffe07 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 13:06:10 +0200 Subject: [PATCH 18/35] Add feature tests --- admin/spec/features/option_types_spec.rb | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index f98f4763a41..790b3dd8b33 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -21,4 +21,69 @@ expect(page).not_to have_content("color") expect(Spree::OptionType.count).to eq(1) end + + it "allows to create option types/values" do + visit "/admin/option_types" + click_on "Add new" + + fill_in "Name", with: "clothing-color" + fill_in "Presentation", with: "Color" + click_on "Add Option Type" + + expect(page).to have_current_path(/\/admin\/option_types\/\d+\/edit/) + click_on "Add new" + + within("dialog") do + fill_in "Name", with: "blue" + fill_in "Presentation", with: "Blue" + click_on "Add Option Value" + end + + expect(page).to have_content("Option value was successfully created.") + end + + it "allows to update option types" do + create(:option_type, name: "color", presentation: "Color") + visit "/admin/option_types" + click_on "Color" + + fill_in "Name", with: "clt-colour" + fill_in "Presentation", with: "Colour" + within("header") { click_on "Save" } + + expect(page).to have_current_path("/admin/option_types") + expect(page).to have_content("Option type was successfully updated.") + expect(page).to have_content("clt-colour") + expect(page).to have_content("Colour") + expect(page).not_to have_content("color") + expect(page).not_to have_content("Color") + end + + it "allows to edit and destroy option values" do + create(:option_type, name: "color", presentation: "Color").tap do |option_type| + option_type.option_values = [ + create(:option_value, name: "blue", presentation: "Blue"), + create(:option_value, name: "green", presentation: "Green"), + ] + end + + visit "/admin/option_types" + click_on "Color" + + click_on "Blue" + within("dialog") do + fill_in "Name", with: "sky-blue" + fill_in "Presentation", with: "Sky Blue" + end + + click_on "Update Option Value" + expect(page).to have_content("Option value was successfully updated.") + expect(find("table")).to have_content("sky-blue") + expect(find("table")).to have_content("Sky Blue") + + select_row("green") + accept_confirm("Are you sure you want to delete 1 option value?") { click_on "Delete" } + expect(page).to have_content("Option values were successfully removed.") + expect(page).not_to have_content("green") + end end From 25a54e7a7a6b73fde08a5d63f2e0aac71dafb05b Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 13:30:30 +0200 Subject: [PATCH 19/35] Move option values table to its own component --- .../option_types/edit/component.html.erb | 4 +- .../option_types/edit/component.rb | 46 ---------------- .../option_types/edit/component.yml | 2 - .../option_values/table/component.rb | 53 +++++++++++++++++++ .../option_values/table/component.yml | 3 ++ 5 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 admin/app/components/solidus_admin/option_values/table/component.rb create mode 100644 admin/app/components/solidus_admin/option_values/table/component.yml diff --git a/admin/app/components/solidus_admin/option_types/edit/component.html.erb b/admin/app/components/solidus_admin/option_types/edit/component.html.erb index 79a812d8fae..a2ef821ac09 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.html.erb +++ b/admin/app/components/solidus_admin/option_types/edit/component.html.erb @@ -22,7 +22,9 @@ <%= render component("ui/panel").new(title: t(".panels.option_values.title")) do |panel| %> <% panel.with_section(wide: true, high: true, class: "flex flex-col gap-4") do %> - <%= render_option_values %> +
+ <%= render component("option_values/table").new(@option_type) %> +
<% end %> <% panel.with_action( diff --git a/admin/app/components/solidus_admin/option_types/edit/component.rb b/admin/app/components/solidus_admin/option_types/edit/component.rb index accc5577267..ec40c3e2fd0 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.rb +++ b/admin/app/components/solidus_admin/option_types/edit/component.rb @@ -2,50 +2,4 @@ class SolidusAdmin::OptionTypes::Edit::Component < SolidusAdmin::Resources::Edit::Component include SolidusAdmin::Layout::PageHelpers - - def render_option_values - render component("ui/table").new( - id: stimulus_id, - data: { - class: Spree::OptionValue, - rows: @option_type.option_values, - columns: option_value_columns, - batch_actions: [ - { - label: t('.panels.option_values.batch_actions.delete'), - action: solidus_admin.option_values_path, - method: :delete, - icon: 'delete-bin-7-line', - require_confirmation: true, - }, - ] - }, - sortable: { - url: ->(option_value) { solidus_admin.move_option_value_path(option_value) }, - param: "position", - }, - embedded: true, - ) - end - - def option_value_columns - [ - { - header: :name, - data: ->(option_value) do - link_to option_value.name, solidus_admin.edit_option_value_path(option_value), - class: 'body-link', - data: { turbo_frame: :option_value_modal } - end - }, - { - header: :presentation, - data: ->(option_value) do - link_to option_value.presentation, solidus_admin.edit_option_value_path(option_value), - class: 'body-link', - data: { turbo_frame: :option_value_modal } - end - }, - ] - end end diff --git a/admin/app/components/solidus_admin/option_types/edit/component.yml b/admin/app/components/solidus_admin/option_types/edit/component.yml index e6232d8fd5d..108d8f6fa7f 100644 --- a/admin/app/components/solidus_admin/option_types/edit/component.yml +++ b/admin/app/components/solidus_admin/option_types/edit/component.yml @@ -6,7 +6,5 @@ en: option_values: title: "Option Values" add: "Add new" - batch_actions: - delete: "Delete" save: "Save" title: "Edit Option Type" diff --git a/admin/app/components/solidus_admin/option_values/table/component.rb b/admin/app/components/solidus_admin/option_values/table/component.rb new file mode 100644 index 00000000000..73af70a8268 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/table/component.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +class SolidusAdmin::OptionValues::Table::Component < SolidusAdmin::BaseComponent + def initialize(option_type) + @option_type = option_type + end + + def call + render component("ui/table").new( + id: stimulus_id, + data: { + class: Spree::OptionValue, + rows: @option_type.option_values, + columns: option_value_columns, + batch_actions: [ + { + label: t('.batch_actions.delete'), + action: solidus_admin.option_values_path, + method: :delete, + icon: 'delete-bin-7-line', + require_confirmation: true, + }, + ] + }, + sortable: { + url: ->(option_value) { solidus_admin.move_option_value_path(option_value) }, + param: "position", + }, + embedded: true, + ) + end + + def option_value_columns + [ + { + header: :name, + data: ->(option_value) do + link_to option_value.name, solidus_admin.edit_option_value_path(option_value), + class: 'body-link', + data: { turbo_frame: :option_value_modal } + end + }, + { + header: :presentation, + data: ->(option_value) do + link_to option_value.presentation, solidus_admin.edit_option_value_path(option_value), + class: 'body-link', + data: { turbo_frame: :option_value_modal } + end + }, + ] + end +end diff --git a/admin/app/components/solidus_admin/option_values/table/component.yml b/admin/app/components/solidus_admin/option_values/table/component.yml new file mode 100644 index 00000000000..d6429972d90 --- /dev/null +++ b/admin/app/components/solidus_admin/option_values/table/component.yml @@ -0,0 +1,3 @@ +en: + batch_actions: + delete: "Delete" From 29fa2bd6af3493d8b9d48224117c9a08f8f0a1fa Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 14:02:37 +0200 Subject: [PATCH 20/35] Move flash toasts to a component This will help turbo stream responses to render flashes correctly. --- .../solidus_admin/layout/flashes/component.html.erb | 5 +++++ .../components/solidus_admin/layout/flashes/component.rb | 4 ++++ admin/app/views/layouts/solidus_admin/application.html.erb | 6 +----- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 admin/app/components/solidus_admin/layout/flashes/component.html.erb create mode 100644 admin/app/components/solidus_admin/layout/flashes/component.rb diff --git a/admin/app/components/solidus_admin/layout/flashes/component.html.erb b/admin/app/components/solidus_admin/layout/flashes/component.html.erb new file mode 100644 index 00000000000..b909471733f --- /dev/null +++ b/admin/app/components/solidus_admin/layout/flashes/component.html.erb @@ -0,0 +1,5 @@ + diff --git a/admin/app/components/solidus_admin/layout/flashes/component.rb b/admin/app/components/solidus_admin/layout/flashes/component.rb new file mode 100644 index 00000000000..1105b1405fb --- /dev/null +++ b/admin/app/components/solidus_admin/layout/flashes/component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class SolidusAdmin::Layout::Flashes::Component < SolidusAdmin::BaseComponent +end diff --git a/admin/app/views/layouts/solidus_admin/application.html.erb b/admin/app/views/layouts/solidus_admin/application.html.erb index 6755eea3c1d..8bc30dfadf4 100644 --- a/admin/app/views/layouts/solidus_admin/application.html.erb +++ b/admin/app/views/layouts/solidus_admin/application.html.erb @@ -31,10 +31,6 @@
- + <%= render component("layout/flashes").new %> From 6e909d9c0d845d38c0b12da0f24b0a695d13e997 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 14:21:59 +0200 Subject: [PATCH 21/35] Make `resource_form_frame` available in views --- admin/app/controllers/solidus_admin/resources_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index 56af918a2e9..4398451eae2 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -4,7 +4,7 @@ module SolidusAdmin class ResourcesController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - helper_method :search_filter_params + helper_method :search_filter_params, :resource_form_frame before_action :set_paginated_resources, only: %i[index] before_action :set_resource, only: %i[edit update] From a059185ea4d1454b3c374e8b43bb217727784c83 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 14:30:16 +0200 Subject: [PATCH 22/35] Make #create action respond with turbo-stream Since we have a form for option type above the option values table, and users might have unsaved changes in that form, it's a good idea to not do a full page re-render on create and only target the table that was changed (plus clearing the modal frame and showing appropriate flash). --- .../solidus_admin/option_values_controller.rb | 10 +++++++++- .../option_values/create.turbo_stream.erb | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 admin/app/views/solidus_admin/option_values/create.turbo_stream.erb diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index b95235296ba..4350a32dda6 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -13,7 +13,15 @@ def new def create @resource = @option_type.option_values.build(permitted_resource_params) - super + if @resource.save + flash[:notice] = t('.success') + respond_to do |format| + format.turbo_stream + format.html { redirect_to after_create_path, status: :see_other } + end + else + render_resource_form_with_errors(new_component.new(@resource)) + end end private diff --git a/admin/app/views/solidus_admin/option_values/create.turbo_stream.erb b/admin/app/views/solidus_admin/option_values/create.turbo_stream.erb new file mode 100644 index 00000000000..6c5de598916 --- /dev/null +++ b/admin/app/views/solidus_admin/option_values/create.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update("option_values_table", component("option_values/table").new(@option_type)) %> +<%= turbo_stream.update(resource_form_frame, nil) %> +<%= turbo_stream.replace("flash_toasts", component("layout/flashes").new) %> From fb1d32ed3cefd7a44d9dd2d93841e7048e5e993d Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 14:38:20 +0200 Subject: [PATCH 23/35] Make #update action respond with turbo-stream --- .../solidus_admin/option_values_controller.rb | 13 +++++++++++++ .../option_values/update.turbo_stream.erb | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 admin/app/views/solidus_admin/option_values/update.turbo_stream.erb diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index 4350a32dda6..0ca23a08e79 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -24,6 +24,19 @@ def create end end + def update + if @resource.update(permitted_resource_params) + flash[:notice] = t('.success') + respond_to do |format| + format.turbo_stream + format.html { redirect_to after_update_path, status: :see_other } + end + else + page_component = edit_component.new(@resource) + render_resource_form_with_errors(page_component) + end + end + private def resource_class = Spree::OptionValue diff --git a/admin/app/views/solidus_admin/option_values/update.turbo_stream.erb b/admin/app/views/solidus_admin/option_values/update.turbo_stream.erb new file mode 100644 index 00000000000..9e897aafba0 --- /dev/null +++ b/admin/app/views/solidus_admin/option_values/update.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update("option_values_table", component("option_values/table").new(@option_value.option_type)) %> +<%= turbo_stream.update(resource_form_frame, nil) %> +<%= turbo_stream.replace("flash_toasts", component("layout/flashes").new) %> From c4e198d96bbca2a06457ca01b28b74499de4ad50 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 17:29:52 +0200 Subject: [PATCH 24/35] Make #destroy action respond with turbo-stream --- .../option_values/table/component.rb | 2 +- .../solidus_admin/option_values_controller.rb | 18 +++++++++++++++++- .../option_values/destroy.turbo_stream.erb | 3 +++ admin/config/routes.rb | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb diff --git a/admin/app/components/solidus_admin/option_values/table/component.rb b/admin/app/components/solidus_admin/option_values/table/component.rb index 73af70a8268..0380d187671 100644 --- a/admin/app/components/solidus_admin/option_values/table/component.rb +++ b/admin/app/components/solidus_admin/option_values/table/component.rb @@ -15,7 +15,7 @@ def call batch_actions: [ { label: t('.batch_actions.delete'), - action: solidus_admin.option_values_path, + action: solidus_admin.option_type_option_values_path(@option_type), method: :delete, icon: 'delete-bin-7-line', require_confirmation: true, diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index 0ca23a08e79..2caad9cb7ee 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -4,7 +4,7 @@ module SolidusAdmin class OptionValuesController < SolidusAdmin::ResourcesController include SolidusAdmin::Moveable - before_action :set_option_type, only: [:new, :create] + before_action :set_option_type, only: [:new, :create, :destroy] def new @resource = @option_type.option_values.build @@ -37,6 +37,18 @@ def update end end + def destroy + @resource = resource_class.where(id: params[:id]) + + resource_class.transaction { @resource.destroy_all } + + flash[:notice] = t('.success') + respond_to do |format| + format.turbo_stream + format.html { redirect_back_or_to after_destroy_path, status: :see_other } + end + end + private def resource_class = Spree::OptionValue @@ -57,6 +69,10 @@ def after_update_path solidus_admin.edit_option_type_path(@option_value.option_type) end + def after_destroy_path + solidus_admin.edit_option_type_path(@option_type) + end + def set_option_type @option_type = Spree::OptionType.find(params[:option_type_id]) end diff --git a/admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb b/admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb new file mode 100644 index 00000000000..6c5de598916 --- /dev/null +++ b/admin/app/views/solidus_admin/option_values/destroy.turbo_stream.erb @@ -0,0 +1,3 @@ +<%= turbo_stream.update("option_values_table", component("option_values/table").new(@option_type)) %> +<%= turbo_stream.update(resource_form_frame, nil) %> +<%= turbo_stream.replace("flash_toasts", component("layout/flashes").new) %> diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 14e34b6fc32..a2164764bd1 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -70,9 +70,9 @@ admin_resources :promotions, only: [:index, :destroy] admin_resources :properties, except: [:show] admin_resources :option_types, except: [:show], sortable: true do - resources :option_values, only: [:new, :create], controller: "option_values" + admin_resources :option_values, only: [:new, :create, :destroy], controller: "option_values", sortable: false end - admin_resources :option_values, only: [:edit, :update, :destroy], sortable: true + admin_resources :option_values, only: [:edit, :update], sortable: true admin_resources :taxonomies, only: [:index, :destroy], sortable: true admin_resources :promotion_categories, only: [:index, :destroy] admin_resources :tax_categories, except: [:show] From 97268d8e8e8bb141fe98df09cc87794f4d70ca1f Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 19:17:11 +0200 Subject: [PATCH 25/35] Cleanup option_values_controller.rb DRY actions, resources_controller.rb can now respond to turbo stream if inheriting controller opts in with #prefer_turbo_stream? override. --- .../solidus_admin/option_values_controller.rb | 38 +++---------------- .../solidus_admin/resources_controller.rb | 17 +++++++-- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/admin/app/controllers/solidus_admin/option_values_controller.rb b/admin/app/controllers/solidus_admin/option_values_controller.rb index 2caad9cb7ee..a5513f0d641 100644 --- a/admin/app/controllers/solidus_admin/option_values_controller.rb +++ b/admin/app/controllers/solidus_admin/option_values_controller.rb @@ -13,44 +13,18 @@ def new def create @resource = @option_type.option_values.build(permitted_resource_params) - if @resource.save - flash[:notice] = t('.success') - respond_to do |format| - format.turbo_stream - format.html { redirect_to after_create_path, status: :see_other } - end - else - render_resource_form_with_errors(new_component.new(@resource)) - end - end - - def update - if @resource.update(permitted_resource_params) - flash[:notice] = t('.success') - respond_to do |format| - format.turbo_stream - format.html { redirect_to after_update_path, status: :see_other } - end - else - page_component = edit_component.new(@resource) - render_resource_form_with_errors(page_component) - end + super end - def destroy - @resource = resource_class.where(id: params[:id]) - - resource_class.transaction { @resource.destroy_all } + private - flash[:notice] = t('.success') - respond_to do |format| - format.turbo_stream - format.html { redirect_back_or_to after_destroy_path, status: :see_other } + def prefer_turbo_stream? + case params[:action] + when "create", "update", "destroy" then true + else false end end - private - def resource_class = Spree::OptionValue def permitted_resource_params diff --git a/admin/app/controllers/solidus_admin/resources_controller.rb b/admin/app/controllers/solidus_admin/resources_controller.rb index 4398451eae2..a636c34d24a 100644 --- a/admin/app/controllers/solidus_admin/resources_controller.rb +++ b/admin/app/controllers/solidus_admin/resources_controller.rb @@ -35,7 +35,10 @@ def create if @resource.save flash[:notice] = t('.success') - redirect_to after_create_path, status: :see_other + respond_to do |format| + format.html { redirect_to after_create_path, status: :see_other } + format.turbo_stream if prefer_turbo_stream? + end else page_component = new_component.new(@resource) render_resource_form_with_errors(page_component) @@ -51,7 +54,10 @@ def edit def update if @resource.update(permitted_resource_params) flash[:notice] = t('.success') - redirect_to after_update_path, status: :see_other + respond_to do |format| + format.html { redirect_to after_update_path, status: :see_other } + format.turbo_stream if prefer_turbo_stream? + end else page_component = edit_component.new(@resource) render_resource_form_with_errors(page_component) @@ -64,7 +70,10 @@ def destroy resource_class.transaction { @resource.destroy_all } flash[:notice] = t('.success') - redirect_back_or_to after_destroy_path, status: :see_other + respond_to do |format| + format.html { redirect_back_or_to after_destroy_path, status: :see_other } + format.turbo_stream if prefer_turbo_stream? + end end private @@ -157,5 +166,7 @@ def after_destroy_path def resource_form_frame :resource_form end + + def prefer_turbo_stream? = false end end From 2b38410600d1c8ea772a1ddedf3bb61d90bcf908 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 23 May 2025 23:05:35 +0200 Subject: [PATCH 26/35] Add feature tests --- admin/spec/features/option_types_spec.rb | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index 790b3dd8b33..9548697ef68 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -86,4 +86,69 @@ expect(page).to have_content("Option values were successfully removed.") expect(page).not_to have_content("green") end + + it "preserves user input" do + create(:option_type, name: "color", presentation: "Color") + + visit "/admin/option_types" + click_on "Color" + + fill_in "Name", with: "clothing-colour" + fill_in "Presentation", with: "Colour" + + click_on "Add new" + within("dialog") do + fill_in "Name", with: "blue" + fill_in "Presentation", with: "Blue" + click_on "Add Option Value" + end + + expect(find_field("Name").value).to eq("clothing-colour") + expect(find_field("Presentation").value).to eq("Colour") + end + + context "with invalid attributes" do + context "on option type create" do + it "shows errors" do + visit "/admin/option_types" + click_on "Add new" + click_on "Add Option Type" + expect(page).to have_content("can't be blank") + end + end + + context "on option type update" do + it "shows errors" do + option_type = create(:option_type, name: "color", presentation: "Color") + visit "/admin/option_types/#{option_type.id}/edit" + fill_in "Name", with: "" + within("header") { click_on "Save" } + expect(page).to have_content("can't be blank") + end + end + + context "on option value create" do + it "shows errors" do + option_type = create(:option_type, name: "color", presentation: "Color") + visit "/admin/option_types/#{option_type.id}/edit" + click_on "Add new" + click_on "Add Option Value" + expect(page).to have_content("can't be blank") + end + end + + context "on option value update" do + it "shows errors" do + option_type = create(:option_type, name: "color", presentation: "Color").tap do |option_type| + option_type.option_values = [create(:option_value, name: "blue")] + end + + visit "/admin/option_types/#{option_type.id}/edit" + click_on "blue" + within("dialog") { fill_in "Name", with: "" } + click_on "Update Option Value" + expect(page).to have_content("can't be blank") + end + end + end end From 6ddcccde26d12cdee18ef9c4c42a7f714db300b7 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 14:30:31 +0200 Subject: [PATCH 27/35] Update CRUD resources shared examples Allows for more customization, with ability to override resources paths, expected redirection paths, and specify endpoints to skip (e.g. if route is not defined). --- .../shared_examples/crud_resource_requests.rb | 75 ++++++++++--------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb b/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb index 8049a450da2..3c4311bfbdf 100644 --- a/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb +++ b/admin/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_examples_for 'CRUD resource requests' do |resource_name| +RSpec.shared_examples_for 'CRUD resource requests' do |resource_name, except: []| let(:admin_user) { create(:admin_user) } let(:resource) { create(factory) } @@ -8,40 +8,49 @@ let(:factory) { resource_name.to_sym } let(:url_helpers) { solidus_admin } + let(:resources_path) { url_helpers.public_send("#{resource_name.pluralize}_path") } + let(:new_resource_path) { url_helpers.public_send("new_#{resource_name}_path") } + let(:edit_resource_path) { url_helpers.public_send("edit_#{resource_name}_path", resource) } + let(:resource_path) { url_helpers.public_send("#{resource_name}_path", resource) } + + let(:expected_after_create_path) { resources_path } + let(:expected_after_update_path) { resources_path } + let(:expected_after_destroy_path) { resources_path } + before do allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(admin_user) end - describe "GET /index" do + describe "GET /index", skip: :index.in?(except) && "not applicable" do it "renders the index template with a 200 OK status" do - get url_helpers.public_send("#{resource_name.pluralize}_path") + get resources_path expect(response).to have_http_status(:ok) end end - describe "GET /new" do + describe "GET /new", skip: :new.in?(except) && "not applicable" do it "renders the new template with a 200 OK status" do - get url_helpers.public_send("new_#{resource_name}_path") + get new_resource_path expect(response).to have_http_status(:ok) end end - describe "POST /create" do + describe "POST /create", skip: :create.in?(except) && "not applicable" do context "with valid parameters" do it "creates a new #{resource_name.humanize}" do expect { - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => valid_attributes } + post resources_path, params: { resource_name => valid_attributes } }.to change(resource_class, :count).by(1) end - it "redirects to the index page with a 303 See Other status" do - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => valid_attributes } - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + it "redirects with a 303 See Other status" do + post resources_path, params: { resource_name => valid_attributes } + expect(response).to redirect_to(expected_after_create_path) expect(response).to have_http_status(:see_other) end it "displays a success flash message" do - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => valid_attributes } + post resources_path, params: { resource_name => valid_attributes } follow_redirect! expect(response.body).to include("#{resource_name.humanize} was successfully created.") end @@ -52,42 +61,42 @@ it "does not create a new #{resource_name.humanize}" do expect { - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => invalid_attributes } + post resources_path, params: { resource_name => invalid_attributes } }.not_to change(resource_class, :count) end it "renders the new template with unprocessable_entity status" do - post url_helpers.public_send("#{resource_name.pluralize}_path"), params: { resource_name => invalid_attributes } + post resources_path, params: { resource_name => invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end end end - describe "GET /edit" do + describe "GET /edit", skip: :edit.in?(except) && "not applicable" do it "renders the edit template with a 200 OK status" do - get url_helpers.public_send("edit_#{resource_name}_path", resource) + get edit_resource_path expect(response).to have_http_status(:ok) end end - describe "PATCH /update" do + describe "PATCH /update", skip: :update.in?(except) && "not applicable" do context "with valid parameters" do it "updates the #{resource_name.humanize}" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => valid_attributes } + patch resource_path, params: { resource_name => valid_attributes } resource.reload valid_attributes.each do |attr, value| expect(resource.public_send(attr)).to eq(value) end end - it "redirects to the index page with a 303 See Other status" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => valid_attributes } - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + it "redirects with a 303 See Other status" do + patch resource_path, params: { resource_name => valid_attributes } + expect(response).to redirect_to(expected_after_update_path) expect(response).to have_http_status(:see_other) end it "displays a success flash message" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => valid_attributes } + patch resource_path, params: { resource_name => valid_attributes } follow_redirect! expect(response.body).to include("#{resource_name.humanize} was successfully updated.") end @@ -96,42 +105,40 @@ context "with invalid parameters" do it "does not update the #{resource_name.humanize}" do expect { - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => invalid_attributes } + patch resource_path, params: { resource_name => invalid_attributes } }.not_to change { resource.reload } end it "renders the edit template with unprocessable_entity status" do - patch url_helpers.public_send("#{resource_name}_path", resource), params: { resource_name => invalid_attributes } + patch resource_path, params: { resource_name => invalid_attributes } expect(response).to have_http_status(:unprocessable_entity) end end end - describe "DELETE /destroy" do - it "deletes the #{resource_name.humanize} and redirects to the index page with a 303 See Other status" do + describe "DELETE /destroy single", skip: :destroy_single.in?(except) && "not applicable" do + it "deletes the #{resource_name.humanize} and redirects with a 303 See Other status" do # This ensures resource exists prior to deletion. resource - expect { - delete url_helpers.public_send("#{resource_name}_path", resource) - }.to change(resource_class, :count).by(-1) + expect { delete resource_path }.to change(resource_class, :count).by(-1) - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + expect(response).to redirect_to(expected_after_destroy_path) expect(response).to have_http_status(:see_other) end it "displays a success flash message after deletion" do - delete url_helpers.public_send("#{resource_name}_path", resource) + delete resource_path follow_redirect! expect(response.body).to include("#{resource_name.humanize.pluralize} were successfully removed.") end + end + describe "DELETE /destroy bulk", skip: :destroy_bulk.in?(except) && "not applicable" do it 'allows to bulk delete resources' do ids = [create(factory), create(factory)].map(&:id) - expect { - delete url_helpers.public_send("#{resource_name.pluralize}_path", id: ids) - }.to change { resource_class.count }.by(-ids.size) + expect { delete resources_path, params: { id: ids } }.to change { resource_class.count }.by(-ids.size) - expect(response).to redirect_to(url_helpers.public_send("#{resource_name.pluralize}_path")) + expect(response).to redirect_to(expected_after_destroy_path) expect(response).to have_http_status(:see_other) end end From d1917a53d9cd6d7b1d51935dad2212a5fbad285d Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 14:30:44 +0200 Subject: [PATCH 28/35] Add request tests --- .../solidus_admin/option_types_spec.rb | 13 +++++ .../solidus_admin/option_values_spec.rb | 52 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 admin/spec/requests/solidus_admin/option_types_spec.rb create mode 100644 admin/spec/requests/solidus_admin/option_values_spec.rb diff --git a/admin/spec/requests/solidus_admin/option_types_spec.rb b/admin/spec/requests/solidus_admin/option_types_spec.rb new file mode 100644 index 00000000000..cd9aac25a72 --- /dev/null +++ b/admin/spec/requests/solidus_admin/option_types_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require "spec_helper" +require 'solidus_admin/testing_support/shared_examples/crud_resource_requests' + +RSpec.describe "SolidusAdmin::OptionTypesController", type: :request do + include_examples "CRUD resource requests", "option_type" do + let(:resource_class) { Spree::OptionType } + let(:valid_attributes) { { name: "color", presentation: "Color" } } + let(:invalid_attributes) { { name: "" } } + let(:expected_after_create_path) { %r(/admin/option_types/\d+/edit) } + end +end diff --git a/admin/spec/requests/solidus_admin/option_values_spec.rb b/admin/spec/requests/solidus_admin/option_values_spec.rb new file mode 100644 index 00000000000..5c91480d02f --- /dev/null +++ b/admin/spec/requests/solidus_admin/option_values_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require "spec_helper" +require "solidus_admin/testing_support/shared_examples/crud_resource_requests" + +RSpec.describe "SolidusAdmin::OptionValuesController", type: :request do + include_examples "CRUD resource requests", "option_value", except: %i[index destroy_single] do + let(:resource_class) { Spree::OptionValue } + let(:valid_attributes) { { name: "yellow", presentation: "Yellow" } } + let(:invalid_attributes) { { name: "" } } + + let!(:resources_path) { solidus_admin.option_type_option_values_path(resource.option_type, format:) } + let!(:new_resource_path) { solidus_admin.new_option_type_option_value_path(resource.option_type) } + let!(:edit_resource_path) { solidus_admin.edit_option_value_path(resource) } + let!(:resource_path) { solidus_admin.option_value_path(resource, format:) } + + let(:format) { :html } + + let(:expected_after_create_path) { %r(/admin/option_types/\d+/edit) } + let(:expected_after_update_path) { %r(/admin/option_types/\d+/edit) } + let(:expected_after_destroy_path) { %r(/admin/option_types/\d+/edit) } + + context "when format is turbo_stream" do + let(:format) { :turbo_stream } + + shared_examples_for "responds with turbo stream" do + it "responds with turbo stream" do + expect(response.content_type).to include("text/vnd.turbo-stream.html") + expect(response).to have_http_status(:ok) + end + end + + context "#create" do + include_examples "responds with turbo stream" do + before { post resources_path, params: { option_value: valid_attributes } } + end + end + + context "#update" do + include_examples "responds with turbo stream" do + before { patch resource_path, params: { option_value: valid_attributes } } + end + end + + context "#destroy" do + include_examples "responds with turbo stream" do + before { delete resources_path, params: { ids: [resource.id] } } + end + end + end + end +end From 4c425ed6b1784ed034065e3e2cee4a4517c9a334 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 15:32:15 +0200 Subject: [PATCH 29/35] Delete redundant shared example Following 38c5b69389e4288cf9d81aa2b07759840e55a719 this file is obsolete and can be deleted. --- .../shared_examples/bulk_delete_resources.rb | 20 ------------------- .../promotion_categories_features.rb | 2 -- .../spec/features/adjustment_reasons_spec.rb | 1 - admin/spec/features/properties_spec.rb | 1 - admin/spec/features/refund_reasons_spec.rb | 1 - admin/spec/features/return_reasons_spec.rb | 1 - admin/spec/features/roles_spec.rb | 1 - .../spec/features/shipping_categories_spec.rb | 1 - .../features/store_credit_reasons_spec.rb | 1 - admin/spec/features/tax_categories_spec.rb | 1 - 10 files changed, 30 deletions(-) delete mode 100644 admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb b/admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb deleted file mode 100644 index 5a64c3fd47f..00000000000 --- a/admin/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_examples_for 'feature: bulk delete resources' do - it 'allows to bulk delete resources' do - create(resource_factory, name: 'Bulk delete item 1') - create(resource_factory, name: 'Bulk delete item 2') - - visit index_path - expect(page).to have_content('Bulk delete item 1') - expect(page).to have_content('Bulk delete item 2') - - select_row('Bulk delete item 1') - select_row('Bulk delete item 2') - click_on 'Delete' - - expect(page).to have_content('were successfully removed.') - expect(page).not_to have_content('Bulk delete item 1') - expect(page).not_to have_content('Bulk delete item 2') - end -end diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb b/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb index 88a676f1e77..5033bbd2e7b 100644 --- a/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb +++ b/admin/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' - RSpec.shared_examples_for 'promotion categories features' do before { sign_in create(:admin_user, email: "admin@example.com") } diff --git a/admin/spec/features/adjustment_reasons_spec.rb b/admin/spec/features/adjustment_reasons_spec.rb index 782fadc99ac..0588f1836a6 100644 --- a/admin/spec/features/adjustment_reasons_spec.rb +++ b/admin/spec/features/adjustment_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Adjustment Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/properties_spec.rb b/admin/spec/features/properties_spec.rb index dda90f87642..28e04c95b3b 100644 --- a/admin/spec/features/properties_spec.rb +++ b/admin/spec/features/properties_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Properties", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/refund_reasons_spec.rb b/admin/spec/features/refund_reasons_spec.rb index 60aa1c0765c..9857007345b 100644 --- a/admin/spec/features/refund_reasons_spec.rb +++ b/admin/spec/features/refund_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Refund Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/return_reasons_spec.rb b/admin/spec/features/return_reasons_spec.rb index 68f30dc2a31..0cb474b23a3 100644 --- a/admin/spec/features/return_reasons_spec.rb +++ b/admin/spec/features/return_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Return Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/roles_spec.rb b/admin/spec/features/roles_spec.rb index a35b58978a3..08572087034 100644 --- a/admin/spec/features/roles_spec.rb +++ b/admin/spec/features/roles_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Roles", type: :feature do before do diff --git a/admin/spec/features/shipping_categories_spec.rb b/admin/spec/features/shipping_categories_spec.rb index 8a4e362f8c4..d953146925f 100644 --- a/admin/spec/features/shipping_categories_spec.rb +++ b/admin/spec/features/shipping_categories_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Shipping Categories", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/store_credit_reasons_spec.rb b/admin/spec/features/store_credit_reasons_spec.rb index 85ef3fb1ff5..1fa6e5006bb 100644 --- a/admin/spec/features/store_credit_reasons_spec.rb +++ b/admin/spec/features/store_credit_reasons_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Store Credit Reasons", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } diff --git a/admin/spec/features/tax_categories_spec.rb b/admin/spec/features/tax_categories_spec.rb index 69c267db8e2..c056e689b55 100644 --- a/admin/spec/features/tax_categories_spec.rb +++ b/admin/spec/features/tax_categories_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'spec_helper' -require 'solidus_admin/testing_support/shared_examples/bulk_delete_resources' describe "Tax categories", type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } From 4e67cba9af977d644d18a54130d4ae743b34e745 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 19:49:25 +0200 Subject: [PATCH 30/35] Add shared examples for sorting --- .../shared_examples/moveable.rb | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb diff --git a/admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb b/admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb new file mode 100644 index 00000000000..8c942242c15 --- /dev/null +++ b/admin/lib/solidus_admin/testing_support/shared_examples/moveable.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +RSpec.shared_examples_for "requests: moveable" do + let(:admin_user) { create(:admin_user) } + let(:record) { create(factory, position: 1) } + let(:request_path) do + solidus_admin.send("move_#{record.model_name.singular_route_key}_path", record, format: :js) + end + + before do + allow_any_instance_of(SolidusAdmin::BaseController).to receive(:spree_current_user).and_return(admin_user) + end + + describe "PATCH /move" do + it "updates record's position" do + expect { patch request_path, params: { position: 2 } }.to change { record.reload.position }.from(1).to(2) + expect(response).to have_http_status(:no_content) + end + end +end + +RSpec.shared_examples_for "features: sortable" do + let(:factory_attrs) { {} } + + before do + create(factory, displayed_attribute => "First", position: 1, **factory_attrs) + create(factory, displayed_attribute => "Second", position: 2, **factory_attrs) + visit path + end + + it "allows sorting via drag and drop" do + row_1 = find_row("First") + row_2 = find_row("Second") + + row_2.drag_to row_1 + + expect(find("table tbody tr:first-child")).to have_text("Second") + expect(find("table tbody tr:last-child")).to have_text("First") + end +end From e5d44ed41958388cdc876f5d29650bd32fb72314 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 19:51:47 +0200 Subject: [PATCH 31/35] Add sorting tests for option types --- admin/spec/features/option_types_spec.rb | 9 +++++++++ admin/spec/requests/solidus_admin/option_types_spec.rb | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index 9548697ef68..6edc6d67174 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require "solidus_admin/testing_support/shared_examples/moveable" describe "Option Types", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } @@ -151,4 +152,12 @@ end end end + + describe "sorting option types" do + include_examples "features: sortable" do + let(:factory) { :option_type } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.option_types_path } + end + end end diff --git a/admin/spec/requests/solidus_admin/option_types_spec.rb b/admin/spec/requests/solidus_admin/option_types_spec.rb index cd9aac25a72..bc73210fcb8 100644 --- a/admin/spec/requests/solidus_admin/option_types_spec.rb +++ b/admin/spec/requests/solidus_admin/option_types_spec.rb @@ -2,6 +2,7 @@ require "spec_helper" require 'solidus_admin/testing_support/shared_examples/crud_resource_requests' +require "solidus_admin/testing_support/shared_examples/moveable" RSpec.describe "SolidusAdmin::OptionTypesController", type: :request do include_examples "CRUD resource requests", "option_type" do @@ -10,4 +11,8 @@ let(:invalid_attributes) { { name: "" } } let(:expected_after_create_path) { %r(/admin/option_types/\d+/edit) } end + + include_examples "requests: moveable" do + let(:factory) { :option_type } + end end From cb02414316d82ab76390780989888143c9fa839c Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 20:37:52 +0200 Subject: [PATCH 32/35] Add sorting tests for option values --- admin/spec/features/option_types_spec.rb | 10 ++++++++++ .../spec/requests/solidus_admin/option_values_spec.rb | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/admin/spec/features/option_types_spec.rb b/admin/spec/features/option_types_spec.rb index 6edc6d67174..8427fac87ae 100644 --- a/admin/spec/features/option_types_spec.rb +++ b/admin/spec/features/option_types_spec.rb @@ -160,4 +160,14 @@ let(:path) { solidus_admin.option_types_path } end end + + describe "sorting option values" do + include_examples "features: sortable" do + let!(:option_type) { create(:option_type) } + let(:factory) { :option_value } + let(:factory_attrs) { { option_type: } } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.edit_option_type_path(option_type) } + end + end end diff --git a/admin/spec/requests/solidus_admin/option_values_spec.rb b/admin/spec/requests/solidus_admin/option_values_spec.rb index 5c91480d02f..ef813c3eabb 100644 --- a/admin/spec/requests/solidus_admin/option_values_spec.rb +++ b/admin/spec/requests/solidus_admin/option_values_spec.rb @@ -2,6 +2,7 @@ require "spec_helper" require "solidus_admin/testing_support/shared_examples/crud_resource_requests" +require "solidus_admin/testing_support/shared_examples/moveable" RSpec.describe "SolidusAdmin::OptionValuesController", type: :request do include_examples "CRUD resource requests", "option_value", except: %i[index destroy_single] do @@ -49,4 +50,8 @@ end end end + + include_examples "requests: moveable" do + let(:factory) { :option_value } + end end From 0db93444cf2ab8769b2e189ba20a51b42663fe01 Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Mon, 26 May 2025 20:42:21 +0200 Subject: [PATCH 33/35] Use it_behaves_like instead of include_examples To create separate nested groups, so that different shared examples don't share same context. --- admin/spec/requests/solidus_admin/option_types_spec.rb | 4 ++-- admin/spec/requests/solidus_admin/option_values_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/admin/spec/requests/solidus_admin/option_types_spec.rb b/admin/spec/requests/solidus_admin/option_types_spec.rb index bc73210fcb8..3cfe16b148b 100644 --- a/admin/spec/requests/solidus_admin/option_types_spec.rb +++ b/admin/spec/requests/solidus_admin/option_types_spec.rb @@ -5,14 +5,14 @@ require "solidus_admin/testing_support/shared_examples/moveable" RSpec.describe "SolidusAdmin::OptionTypesController", type: :request do - include_examples "CRUD resource requests", "option_type" do + it_behaves_like "CRUD resource requests", "option_type" do let(:resource_class) { Spree::OptionType } let(:valid_attributes) { { name: "color", presentation: "Color" } } let(:invalid_attributes) { { name: "" } } let(:expected_after_create_path) { %r(/admin/option_types/\d+/edit) } end - include_examples "requests: moveable" do + it_behaves_like "requests: moveable" do let(:factory) { :option_type } end end diff --git a/admin/spec/requests/solidus_admin/option_values_spec.rb b/admin/spec/requests/solidus_admin/option_values_spec.rb index ef813c3eabb..a89a84d4eca 100644 --- a/admin/spec/requests/solidus_admin/option_values_spec.rb +++ b/admin/spec/requests/solidus_admin/option_values_spec.rb @@ -5,7 +5,7 @@ require "solidus_admin/testing_support/shared_examples/moveable" RSpec.describe "SolidusAdmin::OptionValuesController", type: :request do - include_examples "CRUD resource requests", "option_value", except: %i[index destroy_single] do + it_behaves_like "CRUD resource requests", "option_value", except: %i[index destroy_single] do let(:resource_class) { Spree::OptionValue } let(:valid_attributes) { { name: "yellow", presentation: "Yellow" } } let(:invalid_attributes) { { name: "" } } @@ -51,7 +51,7 @@ end end - include_examples "requests: moveable" do + it_behaves_like "requests: moveable" do let(:factory) { :option_value } end end From 041637783bb7ffdb4cd41555ebd76c6cf3619fab Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Tue, 27 May 2025 10:25:07 +0200 Subject: [PATCH 34/35] Add missing specs for other sortables --- admin/spec/features/payment_methods_spec.rb | 7 +++++++ admin/spec/features/taxonomies_spec.rb | 7 +++++++ .../requests/solidus_admin/payment_methods_spec.rb | 11 +++++++++++ admin/spec/requests/solidus_admin/taxonomies_spec.rb | 10 ++++++++++ 4 files changed, 35 insertions(+) create mode 100644 admin/spec/requests/solidus_admin/payment_methods_spec.rb create mode 100644 admin/spec/requests/solidus_admin/taxonomies_spec.rb diff --git a/admin/spec/features/payment_methods_spec.rb b/admin/spec/features/payment_methods_spec.rb index 55ebf3ec74b..06b4dc0f3ab 100644 --- a/admin/spec/features/payment_methods_spec.rb +++ b/admin/spec/features/payment_methods_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require "solidus_admin/testing_support/shared_examples/moveable" describe "Payment Methods", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } @@ -45,4 +46,10 @@ expect(page).not_to have_content("Check") expect(Spree::PaymentMethod.count).to eq(3) end + + it_behaves_like "features: sortable" do + let(:factory) { :payment_method } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.payment_methods_path } + end end diff --git a/admin/spec/features/taxonomies_spec.rb b/admin/spec/features/taxonomies_spec.rb index 88cb0ec782a..33fab23194e 100644 --- a/admin/spec/features/taxonomies_spec.rb +++ b/admin/spec/features/taxonomies_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'spec_helper' +require "solidus_admin/testing_support/shared_examples/moveable" describe "Taxonomies", :js, type: :feature do before { sign_in create(:admin_user, email: 'admin@example.com') } @@ -21,4 +22,10 @@ expect(page).not_to have_content("Categories") expect(Spree::Taxonomy.count).to eq(1) end + + it_behaves_like "features: sortable" do + let(:factory) { :taxonomy } + let(:displayed_attribute) { :name } + let(:path) { solidus_admin.taxonomies_path } + end end diff --git a/admin/spec/requests/solidus_admin/payment_methods_spec.rb b/admin/spec/requests/solidus_admin/payment_methods_spec.rb new file mode 100644 index 00000000000..5cc99dae2ab --- /dev/null +++ b/admin/spec/requests/solidus_admin/payment_methods_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "spec_helper" +require "solidus_admin/testing_support/shared_examples/moveable" + +RSpec.describe "SolidusAdmin::PaymentMethodsController", type: :request do + it_behaves_like "requests: moveable" do + let(:factory) { :payment_method } + let(:request_path) { solidus_admin.move_payment_method_path(record, format: :js) } + end +end diff --git a/admin/spec/requests/solidus_admin/taxonomies_spec.rb b/admin/spec/requests/solidus_admin/taxonomies_spec.rb new file mode 100644 index 00000000000..0c93d5551c1 --- /dev/null +++ b/admin/spec/requests/solidus_admin/taxonomies_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "spec_helper" +require "solidus_admin/testing_support/shared_examples/moveable" + +RSpec.describe "SolidusAdmin::TaxonomiesController", type: :request do + it_behaves_like "requests: moveable" do + let(:factory) { :taxonomy } + end +end From 988b9a188aa9fa8047c662d2bb0fc80bf250532a Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Fri, 30 May 2025 18:47:13 +0200 Subject: [PATCH 35/35] Disable Rails/LexicallyScopedActionFilter cop This just doesn't seem to be sensible to have since resources_controller defines all the CRUD actions, and as soon as all our controllers inherit from resources_controller, they won't be rubocop compliant because of this. --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index a69446c98b4..9bfa2df3a5c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -352,3 +352,6 @@ Rails/FindEach: # tasks should load the rails environment loaded. Rails/RakeEnvironment: Enabled: false + +Rails/LexicallyScopedActionFilter: + Enabled: false