Skip to content

Commit

Permalink
Admin user roles: Load modal with turbo frame
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Dec 20, 2024
1 parent ca8ae78 commit aad8c9e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
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/edit/component.rb
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
16 changes: 4 additions & 12 deletions admin/app/controllers/solidus_admin/roles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ def index
def new
@role = Spree::Role.new

set_index_page

respond_to do |format|
format.html { render component('roles/new').new(page: @page, role: @role) }
format.html { render component('roles/new').new(role: @role) }
end
end

Expand All @@ -43,22 +41,18 @@ def create
end
end
else
set_index_page

respond_to do |format|
format.html do
page_component = component('roles/new').new(page: @page, role: @role)
page_component = component('roles/new').new(role: @role)
render page_component, status: :unprocessable_entity
end
end
end
end

def edit
set_index_page

respond_to do |format|
format.html { render component('roles/edit').new(page: @page, role: @role) }
format.html { render component('roles/edit').new(role: @role) }
end
end

Expand All @@ -76,11 +70,9 @@ def update
end
end
else
set_index_page

respond_to do |format|
format.html do
page_component = component('roles/edit').new(page: @page, role: @role)
page_component = component('roles/edit').new(role: @role)
render page_component, status: :unprocessable_entity
end
end
Expand Down
2 changes: 1 addition & 1 deletion admin/spec/features/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
before do
Spree::Role.create(name: "Reviewer", permission_sets: [settings_edit_permission])
visit "/admin/roles#{query}"
find_row("Reviewer").click
click_on "Reviewer"
expect(page).to have_selector("dialog", wait: 5)
expect(page).to have_content("Edit Role")
expect(page).to be_axe_clean
Expand Down

0 comments on commit aad8c9e

Please sign in to comment.