Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

feat: Transaction pagination Improvements (#873)

Karan Kirie13c3d927117
diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index 0c569d96..98be1c39 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -6,7 +6,7 @@ class TransactionsController < ApplicationController
def index
@q = search_params
result = Current.family.transactions.search(@q).ordered
- @pagy, @transactions = pagy(result, items: 50)
+ @pagy, @transactions = pagy(result, items: params[:per_page] || "10")
@totals = {
count: result.select { |t| t.currency == Current.family.currency }.count,
diff --git a/app/views/layouts/with_sidebar.html.erb b/app/views/layouts/with_sidebar.html.erb
index f014dd66..ca824d45 100644
--- a/app/views/layouts/with_sidebar.html.erb
+++ b/app/views/layouts/with_sidebar.html.erb
@@ -7,7 +7,7 @@
<%= render "layouts/sidebar" %>
<% end %>
</div>
- <main class="grow px-20 pt-6 pb-32 h-full overflow-y-auto">
+ <main class="grow px-20 py-6 h-full overflow-y-auto">
<%= yield %>
</main>
</div>
diff --git a/app/views/transactions/_pagination.html.erb b/app/views/transactions/_pagination.html.erb
index 2ad3149a..a485ce71 100644
--- a/app/views/transactions/_pagination.html.erb
+++ b/app/views/transactions/_pagination.html.erb
@@ -1,39 +1,56 @@
-<nav class="flex items-center justify-center px-4 mt-4 sm:px-0">
- <div>
- <% if pagy.prev %>
- <%= link_to pagy_url_for(pagy, pagy.prev), class: "inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
- <%= lucide_icon("chevron-left", class: "w-5 h-5 text-gray-500") %>
+<nav class="flex items-center justify-between px-4 mt-4 sm:px-0 w-full">
+ <div class="flex">
+ <div>
+ <% if pagy.prev %>
+ <%= link_to pagy_url_for(pagy, pagy.prev), class: "inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
+ <%= lucide_icon("chevron-left", class: "w-5 h-5 text-gray-500") %>
+ <% end %>
+ <% else %>
+ <div class="inline-flex items-center px-3 py-3 text-sm font-medium hover:border-gray-300">
+ <%= lucide_icon("chevron-left", class: "w-5 h-5 text-gray-200") %>
+ </div>
<% end %>
- <% else %>
- <div class="inline-flex items-center px-3 py-3 text-sm font-medium hover:border-gray-300">
- <%= lucide_icon("chevron-left", class: "w-5 h-5 text-gray-200") %>
- </div>
- <% end %>
- </div>
- <div class="bg-gray-25 rounded-xl">
- <% pagy.series.each do |series_item| %>
- <% if series_item.is_a?(Integer) %>
- <%= link_to pagy_url_for(pagy, series_item), class: "inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
- <%= series_item %>
+ </div>
+ <div class="bg-gray-25 rounded-xl">
+ <% pagy.series.each do |series_item| %>
+ <% if series_item.is_a?(Integer) %>
+ <%= link_to pagy_url_for(pagy, series_item), class: "inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
+ <%= series_item %>
+ <% end %>
+ <% elsif series_item.is_a?(String) %>
+ <%= link_to pagy_url_for(pagy, series_item), class: "shadow-lg ring-2 ring-inset ring-gray-200 rounded-xl bg-white inline-flex items-center m-1 px-4 py-2 text-sm font-medium text-gray-900" do %>
+ <%= series_item %>
+ <% end %>
+ <% elsif series_item == :gap %>
+ <span class="inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500">...</span>
<% end %>
- <% elsif series_item.is_a?(String) %>
- <%= link_to pagy_url_for(pagy, series_item), class: "shadow-lg ring-2 ring-inset ring-gray-200 rounded-xl bg-white inline-flex items-center m-1 px-4 py-2 text-sm font-medium text-gray-900" do %>
- <%= series_item %>
+ <% end %>
+ </div>
+ <div>
+ <% if pagy.next %>
+ <%= link_to pagy_url_for(pagy, pagy.next), class: "inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
+ <%= lucide_icon("chevron-right", class: "w-5 h-5 text-gray-500") %>
<% end %>
- <% elsif series_item == :gap %>
- <span class="inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500">...</span>
+ <% else %>
+ <div class="inline-flex items-center px-3 py-3 text-sm font-medium hover:border-gray-300">
+ <%= lucide_icon("chevron-right", class: "w-5 h-5 text-gray-200") %>
+ </div>
<% end %>
- <% end %>
+ </div>
</div>
- <div>
- <% if pagy.next %>
- <%= link_to pagy_url_for(pagy, pagy.next), class: "inline-flex items-center px-3 py-3 text-sm font-medium text-gray-500 hover:border-gray-300 hover:text-gray-700" do %>
- <%= lucide_icon("chevron-right", class: "w-5 h-5 text-gray-500") %>
- <% end %>
- <% else %>
- <div class="inline-flex items-center px-3 py-3 text-sm font-medium hover:border-gray-300">
- <%= lucide_icon("chevron-right", class: "w-5 h-5 text-gray-200") %>
- </div>
- <% end %>
+ <% per_page = params[:per_page] || "50" %>
+ <div class="flex items-center gap-4">
+ <%= form_with url: transactions_path,
+ builder: ActionView::Helpers::FormBuilder,
+ method: :get,
+ class: "flex items-center gap-4",
+ data: { controller: "auto-submit-form" } do |f| %>
+ <%= f.label :per_page, t(".rows_per_page"), class: "text-sm text-gray-500" %>
+ <%= f.select :per_page,
+ options_for_select(["10", "20", "30", "50"], params[:per_page]),
+ {},
+ class: "py-1.5 pr-8 text-sm text-gray-900 font-medium border border-gray-200 rounded-lg focus:border-gray-900 focus:ring-gray-900 focus-visible:ring-gray-900",
+ data: { "auto-submit-form-target": "auto" } %>
+ <% end %>
</div>
</nav>
diff --git a/app/views/transactions/index.html.erb b/app/views/transactions/index.html.erb
index 23fff412..faf0f110 100644
--- a/app/views/transactions/index.html.erb
+++ b/app/views/transactions/index.html.erb
@@ -1,41 +1,46 @@
-<div class="space-y-4">
+<div class="space-y-4 h-full flex flex-col overflow-y-auto">
<%= render "header" %>
<%= render partial: "transactions/summary", locals: { totals: @totals } %>
- <div id="transactions" data-controller="bulk-select" data-bulk-select-resource-value="<%= t(".transaction") %>" class="bg-white rounded-xl border border-alpha-black-25 shadow-xs p-4 space-y-4">
+ <div id="transactions" data-controller="bulk-select" data-bulk-select-resource-value="<%= t(".transaction") %>" class="overflow-y-auto flex flex-col bg-white rounded-xl border border-alpha-black-25 shadow-xs pb-4">
- <%= render partial: "transactions/searches/search", locals: { transactions: @transactions } %>
+ <div class="p-4 pb-0">
+ <%= render partial: "transactions/searches/search", locals: { transactions: @transactions } %>
+ </div>
<% if @transactions.present? %>
<div hidden id="transaction-selection-bar" data-bulk-select-target="selectionBar">
<%= render "selection_bar" %>
</div>
-
- <div class="grid grid-cols-12 bg-gray-25 rounded-xl px-5 py-3 text-xs uppercase font-medium text-gray-500 items-center mb-4">
- <div class="pl-0.5 col-span-4 flex items-center gap-4">
- <%= check_box_tag "selection_transaction",
- class: "maybe-checkbox maybe-checkbox--light",
- data: { action: "bulk-select#togglePageSelection" } %>
- <p class="col-span-4">transaction</p>
+ <div class="grow overflow-y-auto px-4">
+ <div class="grid grid-cols-12 bg-gray-25 rounded-xl px-5 py-3 text-xs uppercase font-medium text-gray-500 items-center mb-4">
+ <div class="pl-0.5 col-span-4 flex items-center gap-4">
+ <%= check_box_tag "selection_transaction",
+ class: "maybe-checkbox maybe-checkbox--light",
+ data: { action: "bulk-select#togglePageSelection" } %>
+ <p class="col-span-4">transaction</p>
+ </div>
+
+ <p class="col-span-3 pl-4">category</p>
+ <p class="col-span-3">account</p>
+ <p class="col-span-2 justify-self-end">amount</p>
</div>
-
- <p class="col-span-3 pl-4">category</p>
- <p class="col-span-3">account</p>
- <p class="col-span-2 justify-self-end">amount</p>
- </div>
- <div class="space-y-6">
- <% group_transactions_by_date(@transactions).each do |date, group| %>
+ <div class="space-y-6">
+ <% group_transactions_by_date(@transactions).each do |date, group| %>
<%= render partial: "date_group", locals: { date:, group: } %>
<% end %>
+ </div>
</div>
<% else %>
<%= render "empty" %>
<% end %>
- <% if @pagy.pages > 1 %>
- <%= render "pagination", pagy: @pagy %>
- <% end %>
+ <div class="px-4">
+ <% if @pagy.pages > 1 %>
+ <%= render "pagination", pagy: @pagy %>
+ <% end %>
+ </div>
</div>
</div>
diff --git a/app/views/transactions/searches/_search.html.erb b/app/views/transactions/searches/_search.html.erb
index fcd93fc4..22491dde 100644
--- a/app/views/transactions/searches/_search.html.erb
+++ b/app/views/transactions/searches/_search.html.erb
@@ -3,9 +3,11 @@
<ul id="transaction-search-filters" class="flex items-center flex-wrap gap-2">
<% @q.each do |param_key, param_value| %>
<% unless param_value.blank? %>
+ <div class="pb-4">
<% Array(param_value).each do |value| %>
<%= render partial: "transactions/searches/filters/badge", locals: { param_key: param_key, param_value: value } %>
<% end %>
+ </div>
<% end %>
<% end %>
</ul>
diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.yml
index 78120fe9..6d485f48 100644
--- a/config/locales/views/transactions/en.yml
+++ b/config/locales/views/transactions/en.yml
@@ -50,6 +50,8 @@ en:
transaction: transaction
mark_transfers:
success: Marked as transfer
+ pagination:
+ rows_per_page: Rows per page
selection_bar:
mark_transfers: Mark as transfers?
mark_transfers_confirm: Mark as transfers
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index 7dbcde8d..9e3cc9d9 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -4,7 +4,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
@transaction = transactions(:checking_one)
- @recent_transactions = @user.family.transactions.ordered.where(transfer_id: nil).limit(20).to_a
+ @recent_transactions = @user.family.transactions.ordered.limit(20).to_a
end
test "should get paginated index with most recent transactions first" do
@@ -36,7 +36,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
get transactions_url(page: 2)
assert_response :success
- @recent_transactions[10, 10].each do |transaction|
+ @recent_transactions[10, 10].select { |t| t.transfer_id == nil }.each do |transaction|
assert_dom "#" + dom_id(transaction), count: 1
end
end