Skip to content

Commit

Permalink
fix: change_items_per_page_url on paginator component (#3675)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Feb 19, 2025
1 parent e1eb8af commit 94d1ed9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/components/avo/paginator_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Avo::PaginatorComponent < Avo::BaseComponent
prop :resource
prop :parent_record
prop :parent_resource
prop :pagy
prop :turbo_frame do |frame|
frame.present? ? CGI.escapeHTML(frame) : :_top
Expand All @@ -12,7 +13,14 @@ class Avo::PaginatorComponent < Avo::BaseComponent

def change_items_per_page_url(option)
if @parent_record.present?
helpers.related_resources_path(@parent_record, @parent_record, per_page: option, keep_query_params: true, page: 1)
helpers.related_resources_path(
@parent_record,
@parent_record,
parent_resource: @parent_resource,
per_page: option,
keep_query_params: true,
page: 1
)
else
helpers.resources_path(resource: @resource, per_page: option, keep_query_params: true, page: 1)
end
Expand Down
4 changes: 2 additions & 2 deletions app/components/avo/views/resource_index_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<% if view_type.to_sym == :table || view_type.to_sym == :map %>
<% if @records.present? %>
<div class="mt-4 w-full">
<%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, discreet_pagination: field&.discreet_pagination %>
<%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, parent_resource: @parent_resource, discreet_pagination: field&.discreet_pagination %>
</div>
<% end %>
<% end %>
Expand All @@ -88,7 +88,7 @@
<%= render Avo::Index::ResourceGridComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, actions: @actions) %>
</div>
<div class="mt-6">
<%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, discreet_pagination: field&.discreet_pagination %>
<%= render Avo::PaginatorComponent.new pagy: @pagy, turbo_frame: @turbo_frame, index_params: @index_params, resource: @resource, parent_record: @parent_record, parent_resource: @parent_resource, discreet_pagination: field&.discreet_pagination %>
</div>
<% end %>
<% end %>
Expand Down
5 changes: 4 additions & 1 deletion app/helpers/avo/url_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def related_resources_path(
parent_record,
record,
keep_query_params: false,
parent_resource: nil,
**args
)
return if record.nil?
Expand All @@ -75,7 +76,9 @@ def related_resources_path(
rescue
end

avo.resources_associations_index_path(parent_record.model_name.route_key, record.to_param, **existing_params, **args)
route_key = parent_resource&.route_key || parent_record.model_name.route_key

avo.resources_associations_index_path(route_key, record.to_param, **existing_params, **args)
end

def resource_view_path(**args)
Expand Down

0 comments on commit 94d1ed9

Please # to comment.