From bc3e5a824f5320b42898222ccf23cb6db00b989d Mon Sep 17 00:00:00 2001 From: Alessio Cappa <104093777+alessiocappa@users.noreply.github.com> Date: Tue, 26 May 2026 22:17:00 +0200 Subject: [PATCH] feat: Add pagination in merchants page (#1965) * feat: Add pagination in merchants page * fix: Add separate paginations for family/provider merchants * refactor: simplify conditions in view --- app/controllers/family_merchants_controller.rb | 11 +++++++---- app/views/family_merchants/index.html.erb | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/controllers/family_merchants_controller.rb b/app/controllers/family_merchants_controller.rb index db77ee413..d6420b01f 100644 --- a/app/controllers/family_merchants_controller.rb +++ b/app/controllers/family_merchants_controller.rb @@ -5,8 +5,8 @@ class FamilyMerchantsController < ApplicationController @breadcrumbs = [ [ t("breadcrumbs.home"), root_path ], [ t("breadcrumbs.merchants"), nil ] ] # Show all merchants for this family - @family_merchants = Current.family.merchants.alphabetically - @provider_merchants = Current.family.assigned_merchants_for(Current.user).where(type: "ProviderMerchant").alphabetically + @all_family_merchants = Current.family.merchants.alphabetically + @all_provider_merchants = Current.family.assigned_merchants_for(Current.user).where(type: "ProviderMerchant").alphabetically # Show recently unlinked ProviderMerchants (within last 30 days) # Exclude merchants that are already assigned to transactions (they appear in provider_merchants) @@ -14,12 +14,15 @@ class FamilyMerchantsController < ApplicationController .where(family: Current.family) .recently_unlinked .pluck(:merchant_id) - assigned_ids = @provider_merchants.pluck(:id) + assigned_ids = @all_provider_merchants.pluck(:id) @unlinked_merchants = ProviderMerchant.where(id: recently_unlinked_ids - assigned_ids).alphabetically - @enhanceable_count = @provider_merchants.where(website_url: [ nil, "" ]).count + @enhanceable_count = @all_provider_merchants.where(website_url: [ nil, "" ]).count @llm_available = Provider::Registry.get_provider(:openai).present? + @pagy_family_merchants, @family_merchants = pagy(@all_family_merchants, page_param: :family_page, limit: safe_per_page) + @pagy_provider_merchants, @provider_merchants = pagy(@all_provider_merchants, page_param: :provider_page, limit: safe_per_page) + render layout: "settings" end diff --git a/app/views/family_merchants/index.html.erb b/app/views/family_merchants/index.html.erb index e647e5833..ceb8cb07c 100644 --- a/app/views/family_merchants/index.html.erb +++ b/app/views/family_merchants/index.html.erb @@ -19,10 +19,10 @@

<%= t(".family_title", moniker: family_moniker) %>

· -

<%= @family_merchants.count %>

+

<%= @all_family_merchants.count %>

- <% if @family_merchants.any? %> + <% if @all_family_merchants.any? %>
@@ -52,13 +52,17 @@ <% end %> + +
+ <%= render "shared/pagination", pagy: @pagy_family_merchants %> +

<%= t(".provider_title") %>

· -

<%= @provider_merchants.count %>

+

<%= @all_provider_merchants.count %>

@@ -84,7 +88,7 @@
<% end %> - <% if @provider_merchants.any? %> + <% if @all_provider_merchants.any? %>
@@ -106,6 +110,10 @@

<%= t(".provider_empty", moniker: family_moniker_downcase) %>

<% end %> + +
+ <%= render "shared/pagination", pagy: @pagy_provider_merchants %> +
<% if @unlinked_merchants.any? %>