Skip to content

Commit

Permalink
Helper to render admin components resolved from the container
Browse files Browse the repository at this point in the history
As it's going to be something that we'll use a lot, it's better to have
a helper to render components resolved from the container.
  • Loading branch information
waiting-for-dev committed Jun 5, 2023
1 parent dc5adba commit e502c75
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions admin/app/components/solidus_admin/base_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ class BaseComponent < ViewComponent::Base
def container
SolidusAdmin::Container
end

def component(name)
container.resolve("#{name}_component")
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav>
<%=
render container["main_nav_item_component"].with_collection(
render component("main_nav_item").with_collection(
container.within_namespace("main_nav").sort_by(&:position)
)
%>
Expand Down
4 changes: 4 additions & 0 deletions admin/app/helpers/solidus_admin/container_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ module ContainerHelper
def container
SolidusAdmin::Container
end

def component(name)
container.resolve("#{name}_component")
end
end
end
2 changes: 1 addition & 1 deletion admin/app/views/layouts/solidus_admin/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<body>
<h1 class="text-4xl">Layout is rendered</h1>
<%= render container["main_nav_component"].new %>
<%= render component("main_nav").new %>
<%= yield %>
</body>
</html>

0 comments on commit e502c75

Please sign in to comment.