Skip to content

Commit 94d1ed9

Browse files
authored
fix: change_items_per_page_url on paginator component (#3675)
1 parent e1eb8af commit 94d1ed9

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

app/components/avo/paginator_component.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class Avo::PaginatorComponent < Avo::BaseComponent
44
prop :resource
55
prop :parent_record
6+
prop :parent_resource
67
prop :pagy
78
prop :turbo_frame do |frame|
89
frame.present? ? CGI.escapeHTML(frame) : :_top
@@ -12,7 +13,14 @@ class Avo::PaginatorComponent < Avo::BaseComponent
1213

1314
def change_items_per_page_url(option)
1415
if @parent_record.present?
15-
helpers.related_resources_path(@parent_record, @parent_record, per_page: option, keep_query_params: true, page: 1)
16+
helpers.related_resources_path(
17+
@parent_record,
18+
@parent_record,
19+
parent_resource: @parent_resource,
20+
per_page: option,
21+
keep_query_params: true,
22+
page: 1
23+
)
1624
else
1725
helpers.resources_path(resource: @resource, per_page: option, keep_query_params: true, page: 1)
1826
end

app/components/avo/views/resource_index_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<% if view_type.to_sym == :table || view_type.to_sym == :map %>
8080
<% if @records.present? %>
8181
<div class="mt-4 w-full">
82-
<%= 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 %>
82+
<%= 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 %>
8383
</div>
8484
<% end %>
8585
<% end %>
@@ -88,7 +88,7 @@
8888
<%= render Avo::Index::ResourceGridComponent.new(resources: @resources, resource: @resource, reflection: @reflection, parent_record: @parent_record, parent_resource: @parent_resource, actions: @actions) %>
8989
</div>
9090
<div class="mt-6">
91-
<%= 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 %>
91+
<%= 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 %>
9292
</div>
9393
<% end %>
9494
<% end %>

app/helpers/avo/url_helpers.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def related_resources_path(
6161
parent_record,
6262
record,
6363
keep_query_params: false,
64+
parent_resource: nil,
6465
**args
6566
)
6667
return if record.nil?
@@ -75,7 +76,9 @@ def related_resources_path(
7576
rescue
7677
end
7778

78-
avo.resources_associations_index_path(parent_record.model_name.route_key, record.to_param, **existing_params, **args)
79+
route_key = parent_resource&.route_key || parent_record.model_name.route_key
80+
81+
avo.resources_associations_index_path(route_key, record.to_param, **existing_params, **args)
7982
end
8083

8184
def resource_view_path(**args)

0 commit comments

Comments
 (0)