Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change_items_per_page_url on paginator component #3675

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading