Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: adjustment reason edit with turbo-frame link and turbo template with no index #6045

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("adjustment_reasons/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,22 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(adjustment_reason) do
link_to adjustment_reason.name, row_url(adjustment_reason),
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
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, row_url(adjustment_reason),
class: 'body-link',
data: { turbo_frame: :edit_adjustment_reason_modal, turbo_prefetch: false }
end
},
{
header: :active,
data: ->(adjustment_reason) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class AdjustmentReasonsController < SolidusAdmin::BaseController

before_action :set_adjustment_reason, only: %i[edit update]

turbo_actions :edit

def index
set_index_page

Expand Down Expand Up @@ -52,10 +54,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), layout: false
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
end
end
end

Expand All @@ -77,7 +79,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
Expand Down
1 change: 1 addition & 0 deletions admin/app/controllers/solidus_admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BaseController < ApplicationController
include SolidusAdmin::ControllerHelpers::Authorization
include SolidusAdmin::ControllerHelpers::Locale
include SolidusAdmin::ControllerHelpers::Theme
include SolidusAdmin::ControllerHelpers::TurboActions
include SolidusAdmin::ComponentsHelper
include SolidusAdmin::AuthenticationAdapters::Backend if defined?(Spree::Backend)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module SolidusAdmin::ControllerHelpers::TurboActions
extend ActiveSupport::Concern

included do
class_attribute :registered_turbo_actions, instance_writer: false, default: []
before_action :ensure_turbo_frame_request, if: ->(controller) do
registered_turbo_actions.include?(controller.action_name.to_sym)
end
end

class_methods do
def turbo_actions(*actions)
self.registered_turbo_actions += actions.map(&:to_sym)
end
end

private

def ensure_turbo_frame_request
redirect_to action: :index unless turbo_frame_request?
end
end
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@
end

describe "GET /edit" do
it "renders the edit template with a 200 OK status" do
it "redirects when the request is not Turbo-Frame" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we want that these routes still accessible in ie. new tabs or tests w/o javascript.

get solidus_admin.edit_adjustment_reason_path(adjustment_reason)
expect(response).to have_http_status(:redirect)
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": :edit_adjustment_reason_modal }
expect(response).to have_http_status(:ok)
end
end
Expand Down
Loading