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

[Admin] Open edit and new forms in dialog with turbo frame #6046

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -17,7 +17,10 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_adjustment_reason_path, data: { turbo_frame: :new_adjustment_reason_modal },
href: solidus_admin.new_adjustment_reason_path, data: {
turbo_frame: :new_adjustment_reason_modal,
turbo_prefetch: false

Choose a reason for hiding this comment

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

btw we probably can turn turbo-prefetch off globally with meta tag

<meta name="turbo-prefetch" content="false">

I can see prefetching is done on almost all the links, but the problem with it is that prefetch is done on each and every hover on the same link, i.e you hover five times over one link and it makes five requests to the same endpoint. It's not really useful without caching and if i'm not mistaken there's no caching set up (but please correct me if i'm wrong!)

},
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -30,8 +33,8 @@ def turbo_frames
]
end

def row_url(adjustment_reason)
spree.edit_admin_adjustment_reason_path(adjustment_reason, _turbo_frame: :edit_adjustment_reason_modal)
def edit_path(adjustment_reason)
spree.edit_admin_adjustment_reason_path(adjustment_reason)
end

def batch_actions
Expand All @@ -47,8 +50,22 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(adjustment_reason) do
link_to adjustment_reason.name, edit_path(adjustment_reason),
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, edit_path(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 @@ -24,5 +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::New::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 @@ -24,4 +24,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("refund_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::RefundReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
def initialize(refund_reason:)
@refund_reason = refund_reason
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def search_key
:name_or_code_cont
end

def row_url(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason, _turbo_frame: :edit_refund_reason_modal)
def edit_path(refund_reason)
spree.edit_admin_refund_reason_path(refund_reason)
end

def turbo_frames
Expand All @@ -28,7 +28,10 @@ def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_refund_reason_path, data: { turbo_frame: :new_refund_reason_modal },
href: solidus_admin.new_refund_reason_path, data: {
turbo_frame: :new_refund_reason_modal,
turbo_prefetch: false
},
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -47,8 +50,22 @@ def batch_actions

def columns
[
:name,
:code,
{
header: :name,
data: ->(refund_reason) do
link_to refund_reason.name, edit_path(refund_reason),
data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :code,
data: ->(refund_reason) do
link_to_if refund_reason.code, refund_reason.code, edit_path(refund_reason),
data: { turbo_frame: :edit_refund_reason_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :active,
data: ->(refund_reason) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("refund_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::RefundReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, refund_reason:)
@page = page
def initialize(refund_reason:)
@refund_reason = refund_reason
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@
<% end %>
<% end %>
<% end %>
<%= render component("return_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::ReturnReasons::Edit::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
def initialize(return_reason:)
@return_reason = return_reason
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def search_key
:name_cont
end

def row_url(return_reason)
spree.edit_admin_return_reason_path(return_reason, _turbo_frame: :edit_return_reason_modal)
def edit_path(return_reason)
spree.edit_admin_return_reason_path(return_reason)
end

def turbo_frames
Expand All @@ -29,7 +29,7 @@ def page_actions
tag: :a,
text: t('.add'),
href: solidus_admin.new_return_reason_path,
data: { turbo_frame: :new_return_reason_modal },
data: { turbo_frame: :new_return_reason_modal, turbo_prefetch: false },
icon: "add-line",
class: "align-self-end w-full",
)
Expand All @@ -48,7 +48,14 @@ def batch_actions

def columns
[
:name,
{
header: :name,
data: ->(return_reason) do
link_to return_reason.name, edit_path(return_reason),
data: { turbo_frame: :edit_return_reason_modal, turbo_prefetch: false },
class: 'body-link'
end
},
{
header: :active,
data: ->(return_reason) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("return_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::ReturnReasons::New::Component < SolidusAdmin::BaseComponent
def initialize(page:, return_reason:)
@page = page
def initialize(return_reason:)
@return_reason = return_reason
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("roles/index").new(page: @page) %>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class SolidusAdmin::Roles::Edit::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::PermissionSetsHelper

def initialize(page:, role:)
@page = page
def initialize(role:)
@role = role
end

Expand Down
21 changes: 16 additions & 5 deletions admin/app/components/solidus_admin/roles/index/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ def search_url
solidus_admin.roles_path
end

def row_url(role)
solidus_admin.edit_role_path(role, _turbo_frame: :edit_role_modal)
def edit_path(role)
solidus_admin.edit_role_path(role)
end

def page_actions
render component("ui/button").new(
tag: :a,
text: t('.add'),
href: solidus_admin.new_role_path, data: { turbo_frame: :new_role_modal },
href: solidus_admin.new_role_path, data: {
turbo_frame: :new_role_modal,
turbo_prefetch: false,
},
icon: "add-line",
)
end
Expand Down Expand Up @@ -59,11 +62,19 @@ def columns
[
{
header: :role,
data: :name,
data: ->(role) do
link_to role.name, edit_path(role),
data: { turbo_frame: :edit_role_modal, turbo_prefetch: false },
class: "body-link"
end,
},
{
header: :description,
data: :description,
data: ->(role) do
link_to_if role.description, role.description, edit_path(role),
data: { turbo_frame: :edit_role_modal, turbo_prefetch: false },
class: "body-link"
end
}
]
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@
<% end %>
<% end %>
<% end %>

<%= render component("roles/index").new(page: @page) %>
3 changes: 1 addition & 2 deletions admin/app/components/solidus_admin/roles/new/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class SolidusAdmin::Roles::New::Component < SolidusAdmin::BaseComponent
include SolidusAdmin::PermissionSetsHelper

def initialize(page:, role:)
@page = page
def initialize(role:)
@role = role
end

Expand Down
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
Loading
Loading