Skip to content

Commit ca8ae78

Browse files
committed
Admin tax categories: Load modal with turbo frame
1 parent 40a31e7 commit ca8ae78

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

admin/app/components/solidus_admin/tax_categories/edit/component.html.erb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@
2424
<% end %>
2525
<% end %>
2626
<% end %>
27-
28-
<%= render component("tax_categories/index").new(page: @page) %>

admin/app/components/solidus_admin/tax_categories/edit/component.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
class SolidusAdmin::TaxCategories::Edit::Component < SolidusAdmin::TaxCategories::Index::Component
4-
def initialize(page:, tax_category:)
5-
@page = page
4+
def initialize(tax_category:)
65
@tax_category = tax_category
76
end
87

admin/app/components/solidus_admin/tax_categories/index/component.rb

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

33
class SolidusAdmin::TaxCategories::Index::Component < SolidusAdmin::Taxes::Component
4-
def row_url(tax_category)
5-
spree.edit_admin_tax_category_path(tax_category, _turbo_frame: :edit_tax_category_modal)
4+
def edit_path(tax_category)
5+
spree.edit_admin_tax_category_path(tax_category)
66
end
77

88
def model_class
@@ -17,7 +17,10 @@ def page_actions
1717
render component("ui/button").new(
1818
tag: :a,
1919
text: t('.add'),
20-
href: solidus_admin.new_tax_category_path, data: { turbo_frame: :new_tax_category_modal },
20+
href: solidus_admin.new_tax_category_path, data: {
21+
turbo_frame: :new_tax_category_modal,
22+
turbo_prefetch: false,
23+
},
2124
icon: "add-line",
2225
class: "align-self-end w-full",
2326
)
@@ -47,9 +50,30 @@ def batch_actions
4750

4851
def columns
4952
[
50-
:name,
51-
:tax_code,
52-
:description,
53+
{
54+
header: :name,
55+
data: ->(tax_category) do
56+
link_to tax_category.name, edit_path(tax_category),
57+
data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false },
58+
class: 'body-link'
59+
end
60+
},
61+
{
62+
header: :tax_code,
63+
data: ->(tax_category) do
64+
link_to_if tax_category.tax_code, tax_category.tax_code, edit_path(tax_category),
65+
data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false },
66+
class: 'body-link'
67+
end
68+
},
69+
{
70+
header: :description,
71+
data: ->(tax_category) do
72+
link_to_if tax_category.description, tax_category.description, edit_path(tax_category),
73+
data: { turbo_frame: :edit_tax_category_modal, turbo_prefetch: false },
74+
class: 'body-link'
75+
end
76+
},
5377
{
5478
header: :is_default,
5579
data: ->(tax_category) {

admin/app/components/solidus_admin/tax_categories/new/component.html.erb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@
2424
<% end %>
2525
<% end %>
2626
<% end %>
27-
28-
<%= render component("tax_categories/index").new(page: @page) %>

admin/app/components/solidus_admin/tax_categories/new/component.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# frozen_string_literal: true
22

33
class SolidusAdmin::TaxCategories::New::Component < SolidusAdmin::TaxCategories::Index::Component
4-
def initialize(page:, tax_category:)
5-
@page = page
4+
def initialize(tax_category:)
65
@tax_category = tax_category
76
end
87

admin/app/controllers/solidus_admin/tax_categories_controller.rb

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@ class TaxCategoriesController < SolidusAdmin::BaseController
99
def new
1010
@tax_category = Spree::TaxCategory.new
1111

12-
set_index_page
13-
1412
respond_to do |format|
15-
format.html { render component('tax_categories/new').new(page: @page, tax_category: @tax_category) }
13+
format.html { render component('tax_categories/new').new(tax_category: @tax_category) }
1614
end
1715
end
1816

1917
def edit
2018
@tax_category = Spree::TaxCategory.find(params[:id])
2119

22-
set_index_page
23-
2420
respond_to do |format|
25-
format.html { render component('tax_categories/edit').new(page: @page, tax_category: @tax_category) }
21+
format.html { render component('tax_categories/edit').new(tax_category: @tax_category) }
2622
end
2723
end
2824

@@ -44,11 +40,9 @@ def create
4440
end
4541
end
4642
else
47-
set_index_page
48-
4943
respond_to do |format|
5044
format.html do
51-
page_component = component('tax_categories/new').new(page: @page, tax_category: @tax_category)
45+
page_component = component('tax_categories/new').new(tax_category: @tax_category)
5246
render page_component, status: :unprocessable_entity
5347
end
5448
end
@@ -69,11 +63,9 @@ def update
6963
end
7064
end
7165
else
72-
set_index_page
73-
7466
respond_to do |format|
7567
format.html do
76-
page_component = component('tax_categories/edit').new(page: @page, tax_category: @tax_category)
68+
page_component = component('tax_categories/edit').new(tax_category: @tax_category)
7769
render page_component, status: :unprocessable_entity
7870
end
7971
end

0 commit comments

Comments
 (0)