From e0da3857a20555f0705fabb117e33cb10692b197 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 15:39:40 +0100 Subject: [PATCH 01/12] Pin view_component to < 3.21.0 3.21.0 introduced a bug with testing view components. --- admin/solidus_admin.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/solidus_admin.gemspec b/admin/solidus_admin.gemspec index ce348c7b33d..0fd6ac6aff1 100644 --- a/admin/solidus_admin.gemspec +++ b/admin/solidus_admin.gemspec @@ -34,5 +34,5 @@ Gem::Specification.new do |s| s.add_dependency 'solidus_core', '> 4.2' s.add_dependency 'stimulus-rails', '~> 1.2' s.add_dependency 'turbo-rails', '~> 2.0' - s.add_dependency 'view_component', '~> 3.9' + s.add_dependency 'view_component', ['~> 3.9', '< 3.21.0'] end From e7cbb95eb2e12919932241f0c5f2913a8911e674 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 19 Dec 2024 18:56:02 +0100 Subject: [PATCH 02/12] fix(admin/table): Only add rowClicked action if rowUrl is present If a table has no rowUrl defined we currently redirect to root path. Which is not preferable. We should do nothing instead. --- .../components/solidus_admin/ui/table/component.html.erb | 7 ++++--- admin/app/components/solidus_admin/ui/table/component.js | 2 +- 2 files changed, 5 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 69a155cd66d..4d8cc5345c1 100644 --- a/admin/app/components/solidus_admin/ui/table/component.html.erb +++ b/admin/app/components/solidus_admin/ui/table/component.html.erb @@ -137,11 +137,12 @@ <%= "data-sortable-animation-value=#{@sortable.animation}" if @sortable&.animation %> > <% @data.rows.each do |row| %> + <% rowUrl = @data.url&.call(row) %> + class="border-b border-gray-100 last:border-0 <%= 'hover:bg-gray-50 cursor-pointer' if rowUrl %> <%= 'bg-gray-15 text-gray-700' if @data.fade&.call(row) %>" + <% if rowUrl %> data-action="click-><%= stimulus_id %>#rowClicked" - data-<%= stimulus_id %>-url-param="<%= @data.url.call(row) %>" + data-<%= stimulus_id %>-url-param="<%= rowUrl %>" <%= "data-sortable-url=#{@sortable.url.call(row)}" if @sortable&.url %> <% end %> > diff --git a/admin/app/components/solidus_admin/ui/table/component.js b/admin/app/components/solidus_admin/ui/table/component.js index 746c859f167..e98f4708554 100644 --- a/admin/app/components/solidus_admin/ui/table/component.js +++ b/admin/app/components/solidus_admin/ui/table/component.js @@ -103,7 +103,7 @@ export default class extends Controller { if (this.modeValue === "batch") { this.toggleCheckbox(event.currentTarget) - } else { + } else if (event.params.url) { const url = new URL(event.params.url, "http://dummy.com") const params = new URLSearchParams(url.search) const frameId = params.get("_turbo_frame") From 32aa6e73de7303efa2864aa945f0506d23a8649b Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 11:55:18 +0100 Subject: [PATCH 03/12] feat(admin): Skip layout if turbo frame request We do not want to render the whole layout if the request is a turbo frame request. We just want to render the component's html. --- .../solidus_admin/base_controller.rb | 13 +++++++++- .../solidus_admin/base_controller_spec.rb | 24 +++++++++++++++++++ admin/spec/spec_helper.rb | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/admin/app/controllers/solidus_admin/base_controller.rb b/admin/app/controllers/solidus_admin/base_controller.rb index 44665e05295..98905a1f603 100644 --- a/admin/app/controllers/solidus_admin/base_controller.rb +++ b/admin/app/controllers/solidus_admin/base_controller.rb @@ -15,8 +15,19 @@ class BaseController < ApplicationController include SolidusAdmin::ComponentsHelper include SolidusAdmin::AuthenticationAdapters::Backend if defined?(Spree::Backend) - layout 'solidus_admin/application' + layout :set_layout + helper 'solidus_admin/components' helper 'solidus_admin/layout' + + private + + def set_layout + if turbo_frame_request? + false + else + 'solidus_admin/application' + end + end end end diff --git a/admin/spec/controllers/solidus_admin/base_controller_spec.rb b/admin/spec/controllers/solidus_admin/base_controller_spec.rb index b7bb5f8fc52..75bca0d5aa2 100644 --- a/admin/spec/controllers/solidus_admin/base_controller_spec.rb +++ b/admin/spec/controllers/solidus_admin/base_controller_spec.rb @@ -44,4 +44,28 @@ def index expect(response.code).to eq "200" end end + + describe "layout rendering" do + subject { controller.send(:set_layout) } + + context "with turbo frame request" do + before do + allow_any_instance_of(described_class).to receive(:turbo_frame_request?).and_return(true) + end + + it "does not render a layout" do + is_expected.to be false + end + end + + context "without turbo frame request" do + before do + allow_any_instance_of(described_class).to receive(:turbo_frame_request?).and_return(false) + end + + it "renders the default layout" do + is_expected.to eq "solidus_admin/application" + end + end + end end diff --git a/admin/spec/spec_helper.rb b/admin/spec/spec_helper.rb index 70ecb0c11f7..3560cc13601 100644 --- a/admin/spec/spec_helper.rb +++ b/admin/spec/spec_helper.rb @@ -12,6 +12,7 @@ end require 'solidus_admin' +require 'rails-controller-testing' Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } From b84d6f9037ee32d57549a5b20176ecc578774f5e Mon Sep 17 00:00:00 2001 From: Eugene Chaikin Date: Thu, 19 Dec 2024 21:02:11 +0100 Subject: [PATCH 04/12] Admin adjustment reasons with turbo-frame link and turbo template --- .../edit/component.html.erb | 1 - .../adjustment_reasons/edit/component.rb | 3 +-- .../adjustment_reasons/index/component.rb | 27 +++++++++++++++---- .../adjustment_reasons/new/component.html.erb | 2 -- .../adjustment_reasons/new/component.rb | 3 +-- .../adjustment_reasons_controller.rb | 18 +++++-------- .../spec/features/adjustment_reasons_spec.rb | 2 +- 7 files changed, 31 insertions(+), 25 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 2ffda1726c3..e69772be33d 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 @@ -24,4 +24,3 @@ <% end %> <% end %> <% end %> -<%= render component("adjustment_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb index e2005a5fb23..fed30701a0d 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/edit/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::AdjustmentReasons::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, adjustment_reason:) - @page = page + def initialize(adjustment_reason:) @adjustment_reason = adjustment_reason end 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 647d97ecc82..35b91f5cda6 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb @@ -17,7 +17,10 @@ def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_adjustment_reason_path, data: { turbo_frame: :new_adjustment_reason_modal }, + href: solidus_admin.new_adjustment_reason_path, data: { + turbo_frame: :new_adjustment_reason_modal, + turbo_prefetch: false + }, icon: "add-line", class: "align-self-end w-full", ) @@ -30,8 +33,8 @@ def turbo_frames ] end - def row_url(adjustment_reason) - spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: :edit_adjustment_reason_modal) + def edit_path(adjustment_reason) + spree.edit_admin_adjustment_reason_path(adjustment_reason) end def batch_actions @@ -47,8 +50,22 @@ def batch_actions def columns [ - :name, - :code, + { + header: :name, + data: ->(adjustment_reason) do + link_to adjustment_reason.name, edit_path(adjustment_reason), + class: 'body-link', + data: { turbo_frame: :edit_adjustment_reason_modal, turbo_prefetch: false } + end + }, + { + header: :code, + data: ->(adjustment_reason) do + link_to adjustment_reason.code, edit_path(adjustment_reason), + class: 'body-link', + data: { turbo_frame: :edit_adjustment_reason_modal, turbo_prefetch: false } + end + }, { header: :active, data: ->(adjustment_reason) do 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 f30e26730cd..28759d32c4a 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 @@ -24,5 +24,3 @@ <% end %> <% end %> <% end %> - -<%= render component("adjustment_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb b/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb index dddf9ddb8a0..83239a00efa 100644 --- a/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb +++ b/admin/app/components/solidus_admin/adjustment_reasons/new/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::AdjustmentReasons::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, adjustment_reason:) - @page = page + def initialize(adjustment_reason:) @adjustment_reason = adjustment_reason end diff --git a/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb b/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb index 64793387604..a579cc216aa 100644 --- a/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb +++ b/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb @@ -17,10 +17,8 @@ def index def new @adjustment_reason = Spree::AdjustmentReason.new - set_index_page - respond_to do |format| - format.html { render component('adjustment_reasons/new').new(page: @page, adjustment_reason: @adjustment_reason) } + format.html { render component('adjustment_reasons/new').new(adjustment_reason: @adjustment_reason) } end end @@ -40,11 +38,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('adjustment_reasons/new').new(page: @page, adjustment_reason: @adjustment_reason) + page_component = component('adjustment_reasons/new').new(adjustment_reason: @adjustment_reason) render page_component, status: :unprocessable_entity end end @@ -52,10 +48,10 @@ def create end def edit - set_index_page - respond_to do |format| - format.html { render component('adjustment_reasons/edit').new(page: @page, adjustment_reason: @adjustment_reason) } + format.html do + render component('adjustment_reasons/edit').new(adjustment_reason: @adjustment_reason) + end end end @@ -73,11 +69,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('adjustment_reasons/edit').new(page: @page, adjustment_reason: @adjustment_reason) + page_component = component('adjustment_reasons/edit').new(adjustment_reason: @adjustment_reason) render page_component, status: :unprocessable_entity end end diff --git a/admin/spec/features/adjustment_reasons_spec.rb b/admin/spec/features/adjustment_reasons_spec.rb index 615dfa234fa..380ffae0f01 100644 --- a/admin/spec/features/adjustment_reasons_spec.rb +++ b/admin/spec/features/adjustment_reasons_spec.rb @@ -68,7 +68,7 @@ before do Spree::AdjustmentReason.create(name: "Good Reason", code: 5999) visit "/admin/adjustment_reasons#{query}" - find_row("Good Reason").click + click_on "Good Reason" expect(page).to have_selector("dialog", wait: 5) expect(page).to have_content("Edit Adjustment Reason") expect(page).to be_axe_clean From b3fcb7dbf994c54c264449fa921a80ccbd06e039 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 11:56:46 +0100 Subject: [PATCH 05/12] feat(admin/shipping_categories): Load modal remotely This is actual links to open the new and edit forms in the modal dialog remotely. --- .../edit/component.html.erb | 1 - .../shipping_categories/edit/component.rb | 3 +- .../shipping_categories/index/component.rb | 28 +++++++++---------- .../new/component.html.erb | 2 -- .../shipping_categories/new/component.rb | 3 +- .../shipping_categories_controller.rb | 16 +++-------- .../spec/features/shipping_categories_spec.rb | 6 ++-- 7 files changed, 23 insertions(+), 36 deletions(-) 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 88185925b39..84c7a2aef54 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 @@ -13,4 +13,3 @@ <% end %> <% end %> <% end %> -<%= render component("shipping_categories/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/shipping_categories/edit/component.rb b/admin/app/components/solidus_admin/shipping_categories/edit/component.rb index 6f2496e4af1..02ca53bfe93 100644 --- a/admin/app/components/solidus_admin/shipping_categories/edit/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/edit/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::ShippingCategories::Edit::Component < SolidusAdmin::ShippingCategories::Index::Component - def initialize(page:, shipping_category:) - @page = page + def initialize(shipping_category:) @shipping_category = shipping_category end 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 4253dcec01c..8b75bca012d 100644 --- a/admin/app/components/solidus_admin/shipping_categories/index/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/index/component.rb @@ -5,21 +5,14 @@ def model_class Spree::ShippingCategory end - def actions - render component("ui/button").new( - tag: :a, - text: t('.add'), - href: spree.new_admin_shipping_category_path, - icon: "add-line", - class: "align-self-end w-full", - ) - end - def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_shipping_category_path, data: { turbo_frame: :new_shipping_category_modal }, + href: solidus_admin.new_shipping_category_path, data: { + turbo_frame: :new_shipping_category_modal, + turbo_prefetch: false, + }, icon: "add-line", class: "align-self-end w-full", ) @@ -32,8 +25,8 @@ def turbo_frames ] end - def row_url(shipping_category) - spree.edit_admin_shipping_category_path(shipping_category, _turbo_frame: :edit_shipping_category_modal) + def edit_url(shipping_category) + spree.edit_admin_shipping_category_path(shipping_category) end def search_key @@ -57,7 +50,14 @@ def batch_actions def columns [ - :name + { + header: :name, + data: ->(shipping_category) do + link_to shipping_category.name, edit_url(shipping_category), + data: { turbo_frame: :edit_shipping_category_modal, turbo_prefetch: false }, + class: "body-link" + end + }, ] end 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 e3cf3a75937..19821f8c97f 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 @@ -13,5 +13,3 @@ <% end %> <% end %> <% end %> - -<%= render component("shipping_categories/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/shipping_categories/new/component.rb b/admin/app/components/solidus_admin/shipping_categories/new/component.rb index ec46b93ae3d..bdaf700111d 100644 --- a/admin/app/components/solidus_admin/shipping_categories/new/component.rb +++ b/admin/app/components/solidus_admin/shipping_categories/new/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::ShippingCategories::New::Component < SolidusAdmin::ShippingCategories::Index::Component - def initialize(page:, shipping_category:) - @page = page + def initialize(shipping_category:) @shipping_category = shipping_category end diff --git a/admin/app/controllers/solidus_admin/shipping_categories_controller.rb b/admin/app/controllers/solidus_admin/shipping_categories_controller.rb index a7a58686da7..d78cdeda227 100644 --- a/admin/app/controllers/solidus_admin/shipping_categories_controller.rb +++ b/admin/app/controllers/solidus_admin/shipping_categories_controller.rb @@ -9,10 +9,8 @@ class ShippingCategoriesController < SolidusAdmin::BaseController def new @shipping_category = Spree::ShippingCategory.new - set_index_page - respond_to do |format| - format.html { render component('shipping_categories/new').new(page: @page, shipping_category: @shipping_category) } + format.html { render component('shipping_categories/new').new(shipping_category: @shipping_category) } end end @@ -34,11 +32,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('shipping_categories/new').new(page: @page, shipping_category: @shipping_category) + page_component = component('shipping_categories/new').new(shipping_category: @shipping_category) render page_component, status: :unprocessable_entity end end @@ -54,10 +50,8 @@ def index end def edit - set_index_page - respond_to do |format| - format.html { render component('shipping_categories/edit').new(page: @page, shipping_category: @shipping_category) } + format.html { render component('shipping_categories/edit').new(shipping_category: @shipping_category) } end end @@ -75,11 +69,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('shipping_categories/edit').new(page: @page, shipping_category: @shipping_category) + page_component = component('shipping_categories/edit').new(shipping_category: @shipping_category) render page_component, status: :unprocessable_entity end end diff --git a/admin/spec/features/shipping_categories_spec.rb b/admin/spec/features/shipping_categories_spec.rb index 09ad72338fd..e91cb913469 100644 --- a/admin/spec/features/shipping_categories_spec.rb +++ b/admin/spec/features/shipping_categories_spec.rb @@ -65,15 +65,15 @@ before do Spree::ShippingCategory.create(name: "Letter Mail") visit "/admin/shipping_categories#{query}" - find_row("Letter Mail").click - expect(page).to have_css("dialog", wait: 5) + click_on "Letter Mail" + expect(page).to have_css("dialog") expect(page).to have_content("Edit Shipping Category") expect(page).to be_axe_clean end it "closing the modal keeps query params" do within("dialog") { click_on "Cancel" } - expect(page).not_to have_selector("dialog", wait: 5) + expect(page).not_to have_selector("dialog") expect(page.current_url).to include(query) end From 6612c4a0c61528158e2e0980355440c0f350427c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 21:17:53 +0100 Subject: [PATCH 06/12] Admin store credit reasons: Load modal with turbo frame --- .../edit/component.html.erb | 1 - .../store_credit_reasons/edit/component.rb | 3 +-- .../store_credit_reasons/index/component.rb | 18 ++++++++++++++---- .../new/component.html.erb | 2 -- .../store_credit_reasons/new/component.rb | 3 +-- .../store_credit_reasons_controller.rb | 16 ++++------------ .../spec/features/store_credit_reasons_spec.rb | 2 +- 7 files changed, 21 insertions(+), 24 deletions(-) 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 d6e791c121f..895ba87a770 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 @@ -23,4 +23,3 @@ <% end %> <% end %> <% end %> -<%= render component("store_credit_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.rb index 8a079ff9e96..afab08b3bec 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/edit/component.rb +++ b/admin/app/components/solidus_admin/store_credit_reasons/edit/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::StoreCreditReasons::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, store_credit_reason:) - @page = page + def initialize(store_credit_reason:) @store_credit_reason = store_credit_reason end 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 744045ba2c6..94cd464fca5 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 @@ -9,7 +9,10 @@ def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_store_credit_reason_path, data: { turbo_frame: :new_store_credit_reason_modal }, + href: solidus_admin.new_store_credit_reason_path, data: { + turbo_frame: :new_store_credit_reason_modal, + turbo_prefetch: false, + }, icon: "add-line", class: "align-self-end w-full", ) @@ -22,8 +25,8 @@ def turbo_frames ] end - def row_url(store_credit_reason) - spree.edit_admin_store_credit_reason_path(store_credit_reason, _turbo_frame: :edit_store_credit_reason_modal) + def edit_path(store_credit_reason) + spree.edit_admin_store_credit_reason_path(store_credit_reason) end def search_url @@ -47,7 +50,14 @@ def batch_actions def columns [ - :name, + { + header: :name, + data: ->(store_credit_reason) do + link_to store_credit_reason.name, edit_path(store_credit_reason), + data: { turbo_frame: :edit_store_credit_reason_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, { header: :active, data: ->(store_credit_reason) do 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 1d8f9d8d22d..9209539edc8 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 @@ -23,5 +23,3 @@ <% end %> <% end %> <% end %> - -<%= render component("store_credit_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/store_credit_reasons/new/component.rb b/admin/app/components/solidus_admin/store_credit_reasons/new/component.rb index 9fbeebbe21a..99cf4e5ac0e 100644 --- a/admin/app/components/solidus_admin/store_credit_reasons/new/component.rb +++ b/admin/app/components/solidus_admin/store_credit_reasons/new/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::StoreCreditReasons::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, store_credit_reason:) - @page = page + def initialize(store_credit_reason:) @store_credit_reason = store_credit_reason end diff --git a/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb b/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb index 98bbd0615bf..10d9e96728f 100644 --- a/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb +++ b/admin/app/controllers/solidus_admin/store_credit_reasons_controller.rb @@ -17,10 +17,8 @@ def index def new @store_credit_reason = Spree::StoreCreditReason.new - set_index_page - respond_to do |format| - format.html { render component('store_credit_reasons/new').new(page: @page, store_credit_reason: @store_credit_reason) } + format.html { render component('store_credit_reasons/new').new(store_credit_reason: @store_credit_reason) } end end @@ -40,11 +38,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('store_credit_reasons/new').new(page: @page, store_credit_reason: @store_credit_reason) + page_component = component('store_credit_reasons/new').new(store_credit_reason: @store_credit_reason) render page_component, status: :unprocessable_entity end end @@ -52,10 +48,8 @@ def create end def edit - set_index_page - respond_to do |format| - format.html { render component('store_credit_reasons/edit').new(page: @page, store_credit_reason: @store_credit_reason) } + format.html { render component('store_credit_reasons/edit').new(store_credit_reason: @store_credit_reason) } end end @@ -73,11 +67,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('store_credit_reasons/edit').new(page: @page, store_credit_reason: @store_credit_reason) + page_component = component('store_credit_reasons/edit').new(store_credit_reason: @store_credit_reason) render page_component, status: :unprocessable_entity end end diff --git a/admin/spec/features/store_credit_reasons_spec.rb b/admin/spec/features/store_credit_reasons_spec.rb index fcbe4bbea6c..f5a145c9d31 100644 --- a/admin/spec/features/store_credit_reasons_spec.rb +++ b/admin/spec/features/store_credit_reasons_spec.rb @@ -65,7 +65,7 @@ before do Spree::StoreCreditReason.create(name: "New Customer Reward") visit "/admin/store_credit_reasons#{query}" - find_row("New Customer Reward").click + click_on "New Customer Reward" expect(page).to have_selector("dialog", wait: 5) expect(page).to have_content("Edit Store Credit Reason") expect(page).to be_axe_clean From 39634957a8129d65ba137d41f55a9136ded1b837 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 21:23:44 +0100 Subject: [PATCH 07/12] Admin return reasons: Load modal with turbo frame --- .../return_reasons/edit/component.html.erb | 1 - .../return_reasons/edit/component.rb | 3 +-- .../return_reasons/index/component.rb | 15 +++++++++++---- .../return_reasons/new/component.html.erb | 2 -- .../return_reasons/new/component.rb | 3 +-- .../solidus_admin/return_reasons_controller.rb | 16 ++++------------ admin/spec/features/return_reasons_spec.rb | 2 +- 7 files changed, 18 insertions(+), 24 deletions(-) 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 8782aa23c43..5e14b95e423 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 @@ -23,4 +23,3 @@ <% end %> <% end %> <% end %> -<%= render component("return_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/return_reasons/edit/component.rb b/admin/app/components/solidus_admin/return_reasons/edit/component.rb index 2ce5ed7f0bf..a73bca5670a 100644 --- a/admin/app/components/solidus_admin/return_reasons/edit/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/edit/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::ReturnReasons::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, return_reason:) - @page = page + def initialize(return_reason:) @return_reason = return_reason end 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 175d9575828..8a6ee9f80ef 100644 --- a/admin/app/components/solidus_admin/return_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/index/component.rb @@ -13,8 +13,8 @@ def search_key :name_cont end - def row_url(return_reason) - spree.edit_admin_return_reason_path(return_reason, _turbo_frame: :edit_return_reason_modal) + def edit_path(return_reason) + spree.edit_admin_return_reason_path(return_reason) end def turbo_frames @@ -29,7 +29,7 @@ def page_actions tag: :a, text: t('.add'), href: solidus_admin.new_return_reason_path, - data: { turbo_frame: :new_return_reason_modal }, + data: { turbo_frame: :new_return_reason_modal, turbo_prefetch: false }, icon: "add-line", class: "align-self-end w-full", ) @@ -48,7 +48,14 @@ def batch_actions def columns [ - :name, + { + header: :name, + data: ->(return_reason) do + link_to return_reason.name, edit_path(return_reason), + data: { turbo_frame: :edit_return_reason_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, { header: :active, data: ->(return_reason) do 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 7a55ebbcacd..237315fb3e8 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 @@ -23,5 +23,3 @@ <% end %> <% end %> <% end %> - -<%= render component("return_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/return_reasons/new/component.rb b/admin/app/components/solidus_admin/return_reasons/new/component.rb index 7efe494f634..35ae39d7dbe 100644 --- a/admin/app/components/solidus_admin/return_reasons/new/component.rb +++ b/admin/app/components/solidus_admin/return_reasons/new/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::ReturnReasons::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, return_reason:) - @page = page + def initialize(return_reason:) @return_reason = return_reason end diff --git a/admin/app/controllers/solidus_admin/return_reasons_controller.rb b/admin/app/controllers/solidus_admin/return_reasons_controller.rb index 892603806ca..7effdd9f213 100644 --- a/admin/app/controllers/solidus_admin/return_reasons_controller.rb +++ b/admin/app/controllers/solidus_admin/return_reasons_controller.rb @@ -17,10 +17,8 @@ def index def new @return_reason = Spree::ReturnReason.new - set_index_page - respond_to do |format| - format.html { render component('return_reasons/new').new(page: @page, return_reason: @return_reason) } + format.html { render component('return_reasons/new').new(return_reason: @return_reason) } end end @@ -40,11 +38,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('return_reasons/new').new(page: @page, return_reason: @return_reason) + page_component = component('return_reasons/new').new(return_reason: @return_reason) render page_component, status: :unprocessable_entity end end @@ -52,10 +48,8 @@ def create end def edit - set_index_page - respond_to do |format| - format.html { render component('return_reasons/edit').new(page: @page, return_reason: @return_reason) } + format.html { render component('return_reasons/edit').new(return_reason: @return_reason) } end end @@ -73,11 +67,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('return_reasons/edit').new(page: @page, return_reason: @return_reason) + page_component = component('return_reasons/edit').new(return_reason: @return_reason) render page_component, status: :unprocessable_entity end end diff --git a/admin/spec/features/return_reasons_spec.rb b/admin/spec/features/return_reasons_spec.rb index 41c978da8de..721b00ecc98 100644 --- a/admin/spec/features/return_reasons_spec.rb +++ b/admin/spec/features/return_reasons_spec.rb @@ -67,7 +67,7 @@ before do Spree::ReturnReason.create(name: "Good Reason") visit "/admin/return_reasons#{query}" - find_row("Good Reason").click + click_on "Good Reason" expect(page).to have_selector("dialog", wait: 5) expect(page).to have_content("Edit Return Reason") expect(page).to be_axe_clean From 40a31e704b5a8ce399b724c14e61b61147458868 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 21:53:39 +0100 Subject: [PATCH 08/12] Admin refund reasons: Load modal with turbo frame --- .../refund_reasons/edit/component.html.erb | 1 - .../refund_reasons/edit/component.rb | 3 +-- .../refund_reasons/index/component.rb | 27 +++++++++++++++---- .../refund_reasons/new/component.html.erb | 2 -- .../refund_reasons/new/component.rb | 3 +-- .../refund_reasons_controller.rb | 16 +++-------- admin/spec/features/refund_reasons_spec.rb | 2 +- 7 files changed, 29 insertions(+), 25 deletions(-) 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 4fab63b28f3..bb8f9bc1d9a 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 @@ -24,4 +24,3 @@ <% end %> <% end %> <% end %> -<%= render component("refund_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/refund_reasons/edit/component.rb b/admin/app/components/solidus_admin/refund_reasons/edit/component.rb index 285847dc84d..690d81bfd37 100644 --- a/admin/app/components/solidus_admin/refund_reasons/edit/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/edit/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::RefundReasons::Edit::Component < SolidusAdmin::BaseComponent - def initialize(page:, refund_reason:) - @page = page + def initialize(refund_reason:) @refund_reason = refund_reason end 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 0cc0bf4f443..34bb225b391 100644 --- a/admin/app/components/solidus_admin/refund_reasons/index/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/index/component.rb @@ -13,8 +13,8 @@ def search_key :name_or_code_cont end - def row_url(refund_reason) - spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal) + def edit_path(refund_reason) + spree.edit_admin_refund_reason_path(refund_reason) end def turbo_frames @@ -28,7 +28,10 @@ def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal }, + href: solidus_admin.new_refund_reason_path, data: { + turbo_frame: :new_refund_reason_modal, + turbo_prefetch: false + }, icon: "add-line", class: "align-self-end w-full", ) @@ -47,8 +50,22 @@ def batch_actions def columns [ - :name, - :code, + { + header: :name, + data: ->(refund_reason) do + link_to refund_reason.name, edit_path(refund_reason), + data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, + { + header: :code, + data: ->(refund_reason) do + link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason), + data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, { header: :active, data: ->(refund_reason) do 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 ef1a44999d2..fc9188b47b0 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 @@ -23,5 +23,3 @@ <% end %> <% end %> <% end %> - -<%= render component("refund_reasons/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/refund_reasons/new/component.rb b/admin/app/components/solidus_admin/refund_reasons/new/component.rb index 686fc0e9ade..ca31915fa61 100644 --- a/admin/app/components/solidus_admin/refund_reasons/new/component.rb +++ b/admin/app/components/solidus_admin/refund_reasons/new/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::RefundReasons::New::Component < SolidusAdmin::BaseComponent - def initialize(page:, refund_reason:) - @page = page + def initialize(refund_reason:) @refund_reason = refund_reason end diff --git a/admin/app/controllers/solidus_admin/refund_reasons_controller.rb b/admin/app/controllers/solidus_admin/refund_reasons_controller.rb index 92e8c5b2195..3a9506ce936 100644 --- a/admin/app/controllers/solidus_admin/refund_reasons_controller.rb +++ b/admin/app/controllers/solidus_admin/refund_reasons_controller.rb @@ -17,10 +17,8 @@ def index def new @refund_reason = Spree::RefundReason.new - set_index_page - respond_to do |format| - format.html { render component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason) } + format.html { render component('refund_reasons/new').new(refund_reason: @refund_reason) } end end @@ -40,11 +38,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason) + page_component = component('refund_reasons/new').new(refund_reason: @refund_reason) render page_component, status: :unprocessable_entity end end @@ -52,10 +48,8 @@ def create end def edit - set_index_page - respond_to do |format| - format.html { render component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason) } + format.html { render component('refund_reasons/edit').new(refund_reason: @refund_reason) } end end @@ -73,11 +67,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason) + page_component = component('refund_reasons/edit').new(refund_reason: @refund_reason) render page_component, status: :unprocessable_entity end end diff --git a/admin/spec/features/refund_reasons_spec.rb b/admin/spec/features/refund_reasons_spec.rb index 19f83464914..63f7d3c5131 100644 --- a/admin/spec/features/refund_reasons_spec.rb +++ b/admin/spec/features/refund_reasons_spec.rb @@ -65,7 +65,7 @@ before do Spree::RefundReason.create(name: "Return process") visit "/admin/refund_reasons#{query}" - find_row("Return process").click + click_on "Return process" expect(page).to have_css("dialog", wait: 5) expect(page).to have_content("Edit Refund Reason") expect(page).to be_axe_clean From ca8ae782dec8e17e08ab30d71e91a0620eae1fa5 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 22:05:18 +0100 Subject: [PATCH 09/12] Admin tax categories: Load modal with turbo frame --- .../tax_categories/edit/component.html.erb | 2 -- .../tax_categories/edit/component.rb | 3 +- .../tax_categories/index/component.rb | 36 +++++++++++++++---- .../tax_categories/new/component.html.erb | 2 -- .../tax_categories/new/component.rb | 3 +- .../tax_categories_controller.rb | 16 +++------ 6 files changed, 36 insertions(+), 26 deletions(-) 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 a5feeef7251..a02e97cb830 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 @@ -24,5 +24,3 @@ <% end %> <% end %> <% end %> - -<%= render component("tax_categories/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/tax_categories/edit/component.rb b/admin/app/components/solidus_admin/tax_categories/edit/component.rb index 31ddbd13d72..abb9f83a5b5 100644 --- a/admin/app/components/solidus_admin/tax_categories/edit/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/edit/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::TaxCategories::Edit::Component < SolidusAdmin::TaxCategories::Index::Component - def initialize(page:, tax_category:) - @page = page + def initialize(tax_category:) @tax_category = tax_category end 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 c2ce2b16ca2..bb2b9ec8bae 100644 --- a/admin/app/components/solidus_admin/tax_categories/index/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/index/component.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Component - def row_url(tax_category) - spree.edit_admin_tax_category_path(tax_category, _turbo_frame: :edit_tax_category_modal) + def edit_path(tax_category) + spree.edit_admin_tax_category_path(tax_category) end def model_class @@ -17,7 +17,10 @@ def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_tax_category_path, data: { turbo_frame: :new_tax_category_modal }, + href: solidus_admin.new_tax_category_path, data: { + turbo_frame: :new_tax_category_modal, + turbo_prefetch: false, + }, icon: "add-line", class: "align-self-end w-full", ) @@ -47,9 +50,30 @@ def batch_actions def columns [ - :name, - :tax_code, - :description, + { + header: :name, + data: ->(tax_category) do + link_to tax_category.name, edit_path(tax_category), + data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, + { + 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: :edit_tax_category_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, + { + header: :description, + data: ->(tax_category) do + link_to_if tax_category.description, tax_category.description, edit_path(tax_category), + data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false }, + class: 'body-link' + end + }, { header: :is_default, data: ->(tax_category) { 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 b1a97dcc9be..f112dce4e7f 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 @@ -24,5 +24,3 @@ <% end %> <% end %> <% end %> - -<%= render component("tax_categories/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/tax_categories/new/component.rb b/admin/app/components/solidus_admin/tax_categories/new/component.rb index d61ef1e3dd5..5bf598a3cd7 100644 --- a/admin/app/components/solidus_admin/tax_categories/new/component.rb +++ b/admin/app/components/solidus_admin/tax_categories/new/component.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true class SolidusAdmin::TaxCategories::New::Component < SolidusAdmin::TaxCategories::Index::Component - def initialize(page:, tax_category:) - @page = page + def initialize(tax_category:) @tax_category = tax_category end diff --git a/admin/app/controllers/solidus_admin/tax_categories_controller.rb b/admin/app/controllers/solidus_admin/tax_categories_controller.rb index 96a7d96a750..20922dc0e19 100644 --- a/admin/app/controllers/solidus_admin/tax_categories_controller.rb +++ b/admin/app/controllers/solidus_admin/tax_categories_controller.rb @@ -9,20 +9,16 @@ class TaxCategoriesController < SolidusAdmin::BaseController def new @tax_category = Spree::TaxCategory.new - set_index_page - respond_to do |format| - format.html { render component('tax_categories/new').new(page: @page, tax_category: @tax_category) } + format.html { render component('tax_categories/new').new(tax_category: @tax_category) } end end def edit @tax_category = Spree::TaxCategory.find(params[:id]) - set_index_page - respond_to do |format| - format.html { render component('tax_categories/edit').new(page: @page, tax_category: @tax_category) } + format.html { render component('tax_categories/edit').new(tax_category: @tax_category) } end end @@ -44,11 +40,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('tax_categories/new').new(page: @page, tax_category: @tax_category) + page_component = component('tax_categories/new').new(tax_category: @tax_category) render page_component, status: :unprocessable_entity end end @@ -69,11 +63,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('tax_categories/edit').new(page: @page, tax_category: @tax_category) + page_component = component('tax_categories/edit').new(tax_category: @tax_category) render page_component, status: :unprocessable_entity end end From aad8c9e46a37b2163edbb8a64df72007d7b091bd Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 22:25:05 +0100 Subject: [PATCH 10/12] Admin user roles: Load modal with turbo frame --- .../roles/edit/component.html.erb | 2 -- .../solidus_admin/roles/edit/component.rb | 3 +-- .../solidus_admin/roles/index/component.rb | 21 ++++++++++++++----- .../roles/new/component.html.erb | 2 -- .../solidus_admin/roles/new/component.rb | 3 +-- .../solidus_admin/roles_controller.rb | 16 ++++---------- admin/spec/features/roles_spec.rb | 2 +- 7 files changed, 23 insertions(+), 26 deletions(-) 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 9e6b674eb48..bf3ee61cb62 100644 --- a/admin/app/components/solidus_admin/roles/edit/component.html.erb +++ b/admin/app/components/solidus_admin/roles/edit/component.html.erb @@ -29,5 +29,3 @@ <% end %> <% end %> <% end %> - -<%= render component("roles/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/roles/edit/component.rb b/admin/app/components/solidus_admin/roles/edit/component.rb index 67b1f47659f..cad11f9a258 100644 --- a/admin/app/components/solidus_admin/roles/edit/component.rb +++ b/admin/app/components/solidus_admin/roles/edit/component.rb @@ -3,8 +3,7 @@ class SolidusAdmin::Roles::Edit::Component < SolidusAdmin::BaseComponent include SolidusAdmin::PermissionSetsHelper - def initialize(page:, role:) - @page = page + def initialize(role:) @role = role end diff --git a/admin/app/components/solidus_admin/roles/index/component.rb b/admin/app/components/solidus_admin/roles/index/component.rb index c5c4e92e297..1b9195f62ab 100644 --- a/admin/app/components/solidus_admin/roles/index/component.rb +++ b/admin/app/components/solidus_admin/roles/index/component.rb @@ -13,15 +13,18 @@ def search_url solidus_admin.roles_path end - def row_url(role) - solidus_admin.edit_role_path(role, _turbo_frame: :edit_role_modal) + def edit_path(role) + solidus_admin.edit_role_path(role) end def page_actions render component("ui/button").new( tag: :a, text: t('.add'), - href: solidus_admin.new_role_path, data: { turbo_frame: :new_role_modal }, + href: solidus_admin.new_role_path, data: { + turbo_frame: :new_role_modal, + turbo_prefetch: false, + }, icon: "add-line", ) end @@ -59,11 +62,19 @@ def columns [ { header: :role, - data: :name, + data: ->(role) do + link_to role.name, edit_path(role), + data: { turbo_frame: :edit_role_modal, turbo_prefetch: false }, + class: "body-link" + end, }, { header: :description, - data: :description, + data: ->(role) do + link_to_if role.description, role.description, edit_path(role), + data: { turbo_frame: :edit_role_modal, turbo_prefetch: false }, + class: "body-link" + end } ] 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 92d44cd2d76..5bb47301b52 100644 --- a/admin/app/components/solidus_admin/roles/new/component.html.erb +++ b/admin/app/components/solidus_admin/roles/new/component.html.erb @@ -29,5 +29,3 @@ <% end %> <% end %> <% end %> - -<%= render component("roles/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/roles/new/component.rb b/admin/app/components/solidus_admin/roles/new/component.rb index 3619452722e..cc328f1ba4d 100644 --- a/admin/app/components/solidus_admin/roles/new/component.rb +++ b/admin/app/components/solidus_admin/roles/new/component.rb @@ -3,8 +3,7 @@ class SolidusAdmin::Roles::New::Component < SolidusAdmin::BaseComponent include SolidusAdmin::PermissionSetsHelper - def initialize(page:, role:) - @page = page + def initialize(role:) @role = role end diff --git a/admin/app/controllers/solidus_admin/roles_controller.rb b/admin/app/controllers/solidus_admin/roles_controller.rb index fea6e2f5b0f..0067e06e4f6 100644 --- a/admin/app/controllers/solidus_admin/roles_controller.rb +++ b/admin/app/controllers/solidus_admin/roles_controller.rb @@ -20,10 +20,8 @@ def index def new @role = Spree::Role.new - set_index_page - respond_to do |format| - format.html { render component('roles/new').new(page: @page, role: @role) } + format.html { render component('roles/new').new(role: @role) } end end @@ -43,11 +41,9 @@ def create end end else - set_index_page - respond_to do |format| format.html do - page_component = component('roles/new').new(page: @page, role: @role) + page_component = component('roles/new').new(role: @role) render page_component, status: :unprocessable_entity end end @@ -55,10 +51,8 @@ def create end def edit - set_index_page - respond_to do |format| - format.html { render component('roles/edit').new(page: @page, role: @role) } + format.html { render component('roles/edit').new(role: @role) } end end @@ -76,11 +70,9 @@ def update end end else - set_index_page - respond_to do |format| format.html do - page_component = component('roles/edit').new(page: @page, role: @role) + page_component = component('roles/edit').new(role: @role) render page_component, status: :unprocessable_entity end end diff --git a/admin/spec/features/roles_spec.rb b/admin/spec/features/roles_spec.rb index 625d048e2a9..84eb98f0dc2 100644 --- a/admin/spec/features/roles_spec.rb +++ b/admin/spec/features/roles_spec.rb @@ -120,7 +120,7 @@ before do Spree::Role.create(name: "Reviewer", permission_sets: [settings_edit_permission]) visit "/admin/roles#{query}" - find_row("Reviewer").click + click_on "Reviewer" expect(page).to have_selector("dialog", wait: 5) expect(page).to have_content("Edit Role") expect(page).to be_axe_clean From 2de581049a5873398a672f9fa76e7855a4d522d3 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 23:04:27 +0100 Subject: [PATCH 11/12] Add user store credit: Load modal with turbo frame --- .../users/store_credits/index/component.html.erb | 9 +++++++-- .../users/store_credits/new/component.html.erb | 1 - .../solidus_admin/users/store_credits/new/component.rb | 1 - admin/spec/requests/solidus_admin/store_credits_spec.rb | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) 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 d5eefee139e..43e78529669 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 @@ -5,9 +5,14 @@ <%= page_header_actions do %> <%= render component("ui/button").new( - "data-action": "click->#{stimulus_id}#actionButtonClicked", - "data-#{stimulus_id}-url-param": solidus_admin.new_user_store_credit_path(user_id: @user.id, _turbo_frame: :new_store_credit_modal), + tag: :a, + href: solidus_admin.new_user_store_credit_path(user_id: @user.id), + data: { + turbo_frame: :new_store_credit_modal, + turbo_prefetch: false + }, text: t(".add_store_credit"), + icon: "add-line" )%> <% end %> <% 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 d90ebf1c124..39bb8c48cf5 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 @@ -28,4 +28,3 @@ <% end %> <% end %> <% end %> -<%= render component("users/store_credits/index").new(user: @user, store_credits: @store_credits) %> diff --git a/admin/app/components/solidus_admin/users/store_credits/new/component.rb b/admin/app/components/solidus_admin/users/store_credits/new/component.rb index afecb8b683e..bebe6ff4d63 100644 --- a/admin/app/components/solidus_admin/users/store_credits/new/component.rb +++ b/admin/app/components/solidus_admin/users/store_credits/new/component.rb @@ -5,7 +5,6 @@ def initialize(user:, store_credit:, categories:) @user = user @store_credit = store_credit @store_credit_categories = categories - @store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc) end def form_id diff --git a/admin/spec/requests/solidus_admin/store_credits_spec.rb b/admin/spec/requests/solidus_admin/store_credits_spec.rb index 7e4f7a951f5..88563a6ff72 100644 --- a/admin/spec/requests/solidus_admin/store_credits_spec.rb +++ b/admin/spec/requests/solidus_admin/store_credits_spec.rb @@ -60,7 +60,6 @@ it "renders the new store credit template with a 200 OK status" do get solidus_admin.new_user_store_credit_path(user) expect(response).to have_http_status(:ok) - expect(response.body).to include(store_credit.amount.to_s) end end From 6b476d46f5abaa8b65587433df29a51a6c296933 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 20 Dec 2024 23:31:38 +0100 Subject: [PATCH 12/12] Admin stock items: Load modal with turbo frame --- .../stock_items/edit/component.html.erb | 10 ++++++---- .../solidus_admin/stock_items/edit/component.rb | 3 +-- .../solidus_admin/stock_items/index/component.rb | 12 ++++++++---- .../solidus_admin/stock_items_controller.rb | 9 ++++++--- 4 files changed, 21 insertions(+), 13 deletions(-) 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 64a8d7cc594..725bf505ae2 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 @@ -11,7 +11,9 @@ <%= link_to spree.edit_admin_product_variant_path( @stock_item.variant.product, @stock_item.variant, - ), class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %> + ), + data: {turbo_frame: "_top"}, + class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %> <%= render component("ui/resource_item").new( thumbnail: ( @@ -23,7 +25,9 @@ "#{@stock_item.variant.sku}#{@stock_item.variant.options_text.presence&.prepend(" - ")}", ) %> <% end %> - <%= link_to spree.edit_admin_stock_location_path(@stock_item.stock_location), class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %> + <%= link_to spree.edit_admin_stock_location_path(@stock_item.stock_location), + data: {turbo_frame: "_top"}, + class: 'hover:bg-gray-25 rounded p-1 w-1/2 border border-gray-100' do %> <%= render component("ui/resource_item").new( title: @stock_item.stock_location.name, subtitle: "#{Spree::StockLocation.model_name.human} #{@stock_item.stock_location.code}", @@ -78,6 +82,4 @@ <% end %> <% end %> <% end %> - - <%= render component("stock_items/index").new(page: @page) %> diff --git a/admin/app/components/solidus_admin/stock_items/edit/component.rb b/admin/app/components/solidus_admin/stock_items/edit/component.rb index 3573444d413..bdb9e27f6d8 100644 --- a/admin/app/components/solidus_admin/stock_items/edit/component.rb +++ b/admin/app/components/solidus_admin/stock_items/edit/component.rb @@ -1,9 +1,8 @@ # frozen_string_literal: true class SolidusAdmin::StockItems::Edit::Component < SolidusAdmin::BaseComponent - def initialize(stock_item:, page:) + def initialize(stock_item:) @stock_item = stock_item - @page = page end def title diff --git a/admin/app/components/solidus_admin/stock_items/index/component.rb b/admin/app/components/solidus_admin/stock_items/index/component.rb index fc20bb93f71..d9d91d817a7 100644 --- a/admin/app/components/solidus_admin/stock_items/index/component.rb +++ b/admin/app/components/solidus_admin/stock_items/index/component.rb @@ -13,8 +13,8 @@ def search_url solidus_admin.stock_items_path end - def row_url(stock_item) - solidus_admin.edit_stock_item_path(stock_item, _turbo_frame: :edit_stock_item_modal) + def edit_path(stock_item) + solidus_admin.edit_stock_item_path(stock_item) end def scopes @@ -90,7 +90,9 @@ def name_column { header: :name, data: ->(stock_item) do - content_tag :div, stock_item.variant.name + link_to stock_item.variant.name, edit_path(stock_item), + data: { turbo_frame: :edit_stock_item_modal, turbo_prefetch: false }, + class: 'body-link' end } end @@ -99,7 +101,9 @@ def sku_column { header: :sku, data: ->(stock_item) do - content_tag :div, stock_item.variant.sku + link_to stock_item.variant.sku, edit_path(stock_item), + data: { turbo_frame: :edit_stock_item_modal, turbo_prefetch: false }, + class: 'body-link' end } end diff --git a/admin/app/controllers/solidus_admin/stock_items_controller.rb b/admin/app/controllers/solidus_admin/stock_items_controller.rb index 1333dbe672c..f474573f4b8 100644 --- a/admin/app/controllers/solidus_admin/stock_items_controller.rb +++ b/admin/app/controllers/solidus_admin/stock_items_controller.rb @@ -3,7 +3,7 @@ module SolidusAdmin class StockItemsController < SolidusAdmin::BaseController include SolidusAdmin::ControllerHelpers::Search - before_action :load_stock_items, only: [:index, :edit, :update] + before_action :load_stock_items, only: [:index] before_action :load_stock_item, only: [:edit, :update] search_scope(:all, default: true) { _1 } @@ -20,7 +20,7 @@ def index def edit respond_to do |format| - format.html { render component('stock_items/edit').new(stock_item: @stock_item, page: @page) } + format.html { render component('stock_items/edit').new(stock_item: @stock_item) } end end @@ -36,7 +36,10 @@ def update end else respond_to do |format| - format.html { render component('stock_items/edit').new(stock_item: @stock_item, page: @page), status: :unprocessable_entity } + format.html { + render component('stock_items/edit').new(stock_item: @stock_item), + status: :unprocessable_entity + } end end end