-
I've integrated Hotwire Turbo in my AA v4 admin. It's mostly working well. There's an issue where, on pagination click, the page scrolls to top. This happens on show do
attributes_table do
# ...
end
panel "Here be nested resource" do
table_for resource.tasks do
column(:title)
end
div { paginate resource.tasks, param_name: :tasks_page }
end
end I'm trying to fix this and prevent scrolling to top by wrapping the panel in This does not render turbo_frame_tag :tasks_page do
panel "Here be nested resource" do
table_for resource.tasks do
column(:title)
end
div { paginate resource.tasks, param_name: :tasks_page }
end
end This renders # app/admin/resources.rb
render "active_admin/shared/paginated_collection", param_name: :tasks_page do
panel "Here be nested resource" do
table_for resource.tasks do
column(:title)
end
div { paginate resource.tasks, param_name: :tasks_page }
end
end <%# app/views/active_admin/shared/_paginated_collection.html.erb %>
<%= turbo_frame_tag param_name do %>
<%= yield %>
<% end %> So I tried inheriting from # app/admin/resources.rb
turbo_frame_collection(param_name: :tasks_page) do
panel "Here be nested resource" do
table_for resource.tasks do
column(:title)
end
div { paginate resource.tasks, param_name: :tasks_page }
end
end
# app/extensions/turbo_frame_collection.rb
module ActiveAdmin
module Views
class TurboFrameCollection < ActiveAdmin::Component
builder_method :turbo_frame_collection
def build(attributes = {}, &)
super(attributes)
frame_content = helpers.turbo_frame_tag(attributes[:param_name]) do
instance_eval(&) if block_given?
end
text_node frame_content.html_safe
end
end
end
end This renders empty In the last code snippet, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
...and as luck would always have it, few moments later, I have found a way to achieve what I wanted. It doesn't look like the cleanest solution out there (I can't use module ActiveAdmin
module Views
class TurboFrameTag < ActiveAdmin::Component
builder_method :turbo_frame_tag
def build(attributes = {}, &)
super(id: attributes[:param_name])
end
def tag_name = "turbo-frame"
end
end
end |
Beta Was this translation helpful? Give feedback.
...and as luck would always have it, few moments later, I have found a way to achieve what I wanted. It doesn't look like the cleanest solution out there (I can't use
turbo_frame_tag
directly, nor is it generalized so that it works for all Rails ActionView calls), but it works: