Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.

Commit 2cc8919

Browse files
Feature | Filter on uncategorized transactions (#1359)
* allow filtering uncategorized transactions * user can filter uncategorized transactions test * rubocop linting
1 parent aa3342b commit 2cc8919

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

app/helpers/categories_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ def null_category
44
name: "Uncategorized",
55
color: Category::UNCATEGORIZED_COLOR
66
end
7+
8+
def family_categories
9+
[ null_category ].concat(Current.family.categories.alphabetically)
10+
end
711
end

app/models/account/transaction.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ class Account::Transaction < ApplicationRecord
1313
class << self
1414
def search(params)
1515
query = all
16-
query = query.joins(:category).where(categories: { name: params[:categories] }) if params[:categories].present?
16+
if params[:categories].present?
17+
if params[:categories].exclude?("Uncategorized")
18+
query = query
19+
.joins(:category)
20+
.where(categories: { name: params[:categories] })
21+
else
22+
query = query
23+
.left_joins(:category)
24+
.where(categories: { name: params[:categories] })
25+
.or(query.where(category_id: nil))
26+
end
27+
end
28+
1729
query = query.joins(:merchant).where(merchants: { name: params[:merchants] }) if params[:merchants].present?
1830

1931
if params[:tags].present?

app/views/transactions/searches/filters/_category_filter.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= lucide_icon("search", class: "w-5 h-5 text-gray-500 absolute inset-y-0 left-2 top-1/2 transform -translate-y-1/2") %>
66
</div>
77
<div class="my-2" id="list" data-list-filter-target="list">
8-
<% Current.family.categories.alphabetically.each do |category| %>
8+
<% family_categories.each do |category| %>
99
<div class="filterable-item flex items-center gap-2 p-2" data-filter-name="<%= category.name %>">
1010
<%= form.check_box :categories,
1111
{

test/system/transactions_test.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TransactionsTest < ApplicationSystemTestCase
66

77
Account::Entry.delete_all # clean slate
88

9-
create_transaction("one", 12.days.ago.to_date, 100)
9+
@uncategorized_transaction = create_transaction("one", 12.days.ago.to_date, 100)
1010
create_transaction("two", 10.days.ago.to_date, 100)
1111
create_transaction("three", 9.days.ago.to_date, 100)
1212
create_transaction("four", 8.days.ago.to_date, 100)
@@ -61,6 +61,30 @@ class TransactionsTest < ApplicationSystemTestCase
6161
end
6262
end
6363

64+
test "can filter uncategorized transactions" do
65+
find("#transaction-filters-button").click
66+
67+
within "#transaction-filters-menu" do
68+
click_button "Category"
69+
check("Uncategorized")
70+
click_button "Apply"
71+
end
72+
73+
assert_selector "#" + dom_id(@uncategorized_transaction), count: 1
74+
assert_no_selector("#" + dom_id(@transaction))
75+
76+
find("#transaction-filters-button").click
77+
78+
within "#transaction-filters-menu" do
79+
click_button "Category"
80+
check(@transaction.account_transaction.category.name)
81+
click_button "Apply"
82+
end
83+
84+
assert_selector "#" + dom_id(@transaction), count: 1
85+
assert_selector "#" + dom_id(@uncategorized_transaction), count: 1
86+
end
87+
6488
test "all filters work and empty state shows if no match" do
6589
find("#transaction-filters-button").click
6690

0 commit comments

Comments
 (0)