From a4d10097d579cc383057b4d857a724cf22761106 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 20 Dec 2024 11:24:46 -0500 Subject: [PATCH] Preserve pagination on entry updates (#1563) * Preserve pagination on entry updates * Test fix --- app/helpers/application_helper.rb | 20 +++++++++++++++++ app/models/concerns/providable.rb | 6 ++--- app/views/account/entries/index.html.erb | 2 +- app/views/accounts/show/_activity.html.erb | 2 +- app/views/application/_pagination.html.erb | 26 ++++++++++++++-------- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 24c962df2b3..85aca138411 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -166,4 +166,24 @@ def show_super_admin_bar? cookies[:admin] == "true" end + + def custom_pagy_url_for(pagy, page, current_path: nil) + if current_path.blank? + pagy_url_for(pagy, page) + else + uri = URI.parse(current_path) + params = URI.decode_www_form(uri.query || "").to_h + + # Delete existing page param if it exists + params.delete("page") + # Add new page param unless it's page 1 + params["page"] = page unless page == 1 + + if params.empty? + uri.path + else + "#{uri.path}?#{URI.encode_www_form(params)}" + end + end + end end diff --git a/app/models/concerns/providable.rb b/app/models/concerns/providable.rb index 4a8de8c09c1..996efff8841 100644 --- a/app/models/concerns/providable.rb +++ b/app/models/concerns/providable.rb @@ -23,10 +23,8 @@ def git_repository_provider end def synth_provider - @synth_provider ||= begin - api_key = self_hosted? ? Setting.synth_api_key : ENV["SYNTH_API_KEY"] - api_key.present? ? Provider::Synth.new(api_key) : nil - end + api_key = self_hosted? ? Setting.synth_api_key : ENV["SYNTH_API_KEY"] + api_key.present? ? Provider::Synth.new(api_key) : nil end private diff --git a/app/views/account/entries/index.html.erb b/app/views/account/entries/index.html.erb index c659d97f532..31197675d6d 100644 --- a/app/views/account/entries/index.html.erb +++ b/app/views/account/entries/index.html.erb @@ -84,7 +84,7 @@
- <%= render "pagination", pagy: @pagy %> + <%= render "pagination", pagy: @pagy, current_path: account_path(@account, page: params[:page]) %>
<% end %> diff --git a/app/views/accounts/show/_activity.html.erb b/app/views/accounts/show/_activity.html.erb index c041b6523eb..290c5be5b67 100644 --- a/app/views/accounts/show/_activity.html.erb +++ b/app/views/accounts/show/_activity.html.erb @@ -1,5 +1,5 @@ <%# locals: (account:) %> -<%= turbo_frame_tag dom_id(account, :entries), src: account_entries_path(account_id: account.id) do %> +<%= turbo_frame_tag dom_id(account, :entries), src: account_entries_path(account_id: account.id, page: params[:page]) do %> <%= render "account/entries/loading" %> <% end %> diff --git a/app/views/application/_pagination.html.erb b/app/views/application/_pagination.html.erb index dee086be568..f4548512314 100644 --- a/app/views/application/_pagination.html.erb +++ b/app/views/application/_pagination.html.erb @@ -1,9 +1,11 @@ -<%# locals: (pagy:) %> +<%# locals: (pagy:, current_path: nil) %>