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..301567e3bb8 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 :edit_adjustment_reason_modal do %>
+<%= turbo_frame_tag @adjustment_reason, :edit, target: '_top' do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: solidus_admin.adjustment_reason_path(@adjustment_reason), html: { id: form_id } do |f| %>
@@ -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..05e41863bf2 100644
--- a/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb
+++ b/admin/app/components/solidus_admin/adjustment_reasons/index/component.rb
@@ -24,14 +24,18 @@ def page_actions
end
def turbo_frames
- %w[
- new_adjustment_reason_modal
- edit_adjustment_reason_modal
+ return @turbo_frames if defined? @turbo_frames
+
+ @turbo_frames = [
+ component('utils/turbo_frame').new(id: dom_id(Spree::AdjustmentReason, :new)),
]
+
+ @page.records.each { @turbo_frames << component('utils/turbo_frame').new(id: dom_id(_1, :edit)) }
+ @turbo_frames
end
def row_url(adjustment_reason)
- spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: :edit_adjustment_reason_modal)
+ spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: dom_id(adjustment_reason, :edit))
end
def batch_actions
@@ -47,8 +51,22 @@ def batch_actions
def columns
[
- :name,
- :code,
+ {
+ header: :name,
+ data: ->(adjustment_reason) do
+ link_to adjustment_reason.name, row_url(adjustment_reason),
+ class: 'body-link',
+ data: { turbo_frame: dom_id(adjustment_reason, :edit), turbo_prefetch: false }
+ end
+ },
+ {
+ header: :code,
+ data: ->(adjustment_reason) do
+ link_to adjustment_reason.code, row_url(adjustment_reason),
+ class: 'body-link',
+ data: { turbo_frame: dom_id(adjustment_reason, :edit), turbo_prefetch: false }
+ end
+ },
{
header: :active,
data: ->(adjustment_reason) do
@@ -57,4 +75,11 @@ def columns
},
]
end
+
+ def eager_loaded_frame(frame_id, src)
+ frame = turbo_frames.index_by(&:id)[frame_id]
+ return unless frame
+
+ frame.src = src
+ end
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 f30e26730cd..28947deeb99 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 :new_adjustment_reason_modal do %>
+<%= turbo_frame_tag :new_adjustment_reason do %>
<%= render component("ui/modal").new(title: t(".title")) do |modal| %>
<%= form_for @adjustment_reason, url: solidus_admin.adjustment_reasons_path, html: { id: form_id } do |f| %>
diff --git a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb
index 69916f08dd4..efd20b24e01 100644
--- a/admin/app/components/solidus_admin/ui/pages/index/component.html.erb
+++ b/admin/app/components/solidus_admin/ui/pages/index/component.html.erb
@@ -39,6 +39,6 @@
<% end %>
<% turbo_frames.each do |frame| %>
- <%= turbo_frame_tag frame %>
+ <%= render frame %>
<% end %>
<% end %>
diff --git a/admin/app/components/solidus_admin/utils/turbo_frame/component.html.erb b/admin/app/components/solidus_admin/utils/turbo_frame/component.html.erb
new file mode 100644
index 00000000000..8dea1e0df62
--- /dev/null
+++ b/admin/app/components/solidus_admin/utils/turbo_frame/component.html.erb
@@ -0,0 +1 @@
+<%= turbo_frame_tag(@id, src: @src) %>
diff --git a/admin/app/components/solidus_admin/utils/turbo_frame/component.rb b/admin/app/components/solidus_admin/utils/turbo_frame/component.rb
new file mode 100644
index 00000000000..22d84bc86dd
--- /dev/null
+++ b/admin/app/components/solidus_admin/utils/turbo_frame/component.rb
@@ -0,0 +1,9 @@
+class SolidusAdmin::Utils::TurboFrame::Component < SolidusAdmin::BaseComponent
+ attr_reader :id
+ attr_writer :src
+
+ def initialize(id:, src: nil)
+ @id = id
+ @src = src
+ end
+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..84c3856f857 100644
--- a/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb
+++ b/admin/app/controllers/solidus_admin/adjustment_reasons_controller.rb
@@ -52,10 +52,17 @@ 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
+ if turbo_frame_request?
+ render component('adjustment_reasons/edit').new(adjustment_reason: @adjustment_reason), layout: false
+ else
+ set_index_page
+ component = component('adjustment_reasons/index').new(page: @page)
+ component.eager_loaded_frame(dom_id(@adjustment_reason, :edit), solidus_admin.edit_adjustment_reason_path(@adjustment_reason))
+ render component
+ end
+ end
end
end
@@ -77,7 +84,7 @@ def update
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/app/controllers/solidus_admin/base_controller.rb b/admin/app/controllers/solidus_admin/base_controller.rb
index 44665e05295..a0a3f3605e3 100644
--- a/admin/app/controllers/solidus_admin/base_controller.rb
+++ b/admin/app/controllers/solidus_admin/base_controller.rb
@@ -7,6 +7,7 @@ class BaseController < ApplicationController
include ActiveStorage::SetCurrent
include Spree::Core::ControllerHelpers::Store
include GearedPagination::Controller
+ include ActionView::RecordIdentifier
include SolidusAdmin::ControllerHelpers::Authentication
include SolidusAdmin::ControllerHelpers::Authorization
diff --git a/admin/spec/requests/solidus_admin/adjustment_reasons_spec.rb b/admin/spec/requests/solidus_admin/adjustment_reasons_spec.rb
index 1f4a8bd7ccb..951c6e7aa3e 100644
--- a/admin/spec/requests/solidus_admin/adjustment_reasons_spec.rb
+++ b/admin/spec/requests/solidus_admin/adjustment_reasons_spec.rb
@@ -68,6 +68,11 @@
get solidus_admin.edit_adjustment_reason_path(adjustment_reason)
expect(response).to have_http_status(:ok)
end
+
+ it "renders the edit template with a 200 OK status for Turbo-Frame request" do
+ get solidus_admin.edit_adjustment_reason_path(adjustment_reason), headers: { "Turbo-Frame": "adjustment_reason_#{adjustment_reason.id}_edit" }
+ expect(response).to have_http_status(:ok)
+ end
end
describe "PATCH /update" do