Skip to content

Commit

Permalink
feat(admin): Skip layout if turbo frame request
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tvdeyen committed Dec 20, 2024
1 parent c1660ae commit 7a56f2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
13 changes: 12 additions & 1 deletion admin/app/controllers/solidus_admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions admin/spec/controllers/solidus_admin/base_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions admin/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
end

require 'solidus_admin'
require 'rails-controller-testing'

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

Expand Down

0 comments on commit 7a56f2b

Please sign in to comment.