Skip to content

Commit

Permalink
feat(admin/shipping_categories): Load modal remotely
Browse files Browse the repository at this point in the history
This is actual links to open the new and edit forms in the modal dialog
remotely.
  • Loading branch information
tvdeyen committed Dec 20, 2024
1 parent 619632e commit 909607d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("shipping_categories/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("shipping_categories/index").new(page: @page) %>
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions admin/spec/features/shipping_categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 909607d

Please sign in to comment.