diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index 36e45b01..1fdfa33d 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -24,7 +24,16 @@ class TransactionsController < ApplicationController
session.delete(ransack_session_key)
elsif params[:remove_param]
current_params = session[ransack_session_key] || {}
- updated_params = delete_search_param(current_params, params[:remove_param], value: params[:remove_param_value])
+ if params[:remove_param] == "date_range"
+ updated_params = current_params.except("date_gteq", "date_lteq")
+ elsif params[:remove_param_value]
+ key_to_remove = params[:remove_param]
+ value_to_remove = params[:remove_param_value]
+ updated_params = current_params.deep_dup
+ updated_params[key_to_remove] = updated_params[key_to_remove] - [ value_to_remove ]
+ else
+ updated_params = current_params.except(params[:remove_param])
+ end
session[ransack_session_key] = updated_params
elsif params[:q]
session[ransack_session_key] = params[:q]
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rb
index 36098d12..d50ea4d1 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/transactions_helper.rb
@@ -1,2 +1,20 @@
module TransactionsHelper
+ def transaction_filters
+ [
+ { name: "Account", partial: "account_filter", icon: "layers" },
+ { name: "Date", partial: "date_filter", icon: "calendar" },
+ { name: "Type", partial: "type_filter", icon: "shapes" },
+ { name: "Amount", partial: "amount_filter", icon: "hash" },
+ { name: "Category", partial: "category_filter", icon: "tag" },
+ { name: "Merchant", partial: "merchant_filter", icon: "store" }
+ ]
+ end
+
+ def transaction_filter_id(filter)
+ "txn-#{filter[:name].downcase}-filter"
+ end
+
+ def transaction_filter_by_name(name)
+ transaction_filters.find { |filter| filter[:name] == name }
+ end
end
diff --git a/app/models/transaction.rb b/app/models/transaction.rb
index 890736f3..b778cd08 100644
--- a/app/models/transaction.rb
+++ b/app/models/transaction.rb
@@ -23,6 +23,8 @@ class Transaction < ApplicationRecord
def self.build_filter_list(params, family)
filters = []
+ date_filters = { gteq: nil, lteq: nil }
+
if params
params.each do |key, value|
next if value.blank?
@@ -38,8 +40,16 @@ class Transaction < ApplicationRecord
end
when "category_name_or_account_name_or_name_cont"
filters << { type: "search", value: value, original: { key: key, value: nil } }
+ when "date_gteq"
+ date_filters[:gteq] = value
+ when "date_lteq"
+ date_filters[:lteq] = value
end
end
+
+ unless date_filters.values.compact.empty?
+ filters << { type: "date_range", value: date_filters, original: { key: "date_range", value: nil } }
+ end
end
filters
diff --git a/app/views/transactions/_filter.html.erb b/app/views/transactions/_filter.html.erb
index 3e22bbba..19405d8b 100644
--- a/app/views/transactions/_filter.html.erb
+++ b/app/views/transactions/_filter.html.erb
@@ -16,11 +16,25 @@
<%= lucide_icon "text", class: "w-5 h-5 text-gray-500" %>
<%= "\"#{filter[:value]}\"".truncate(20) %>
+ <% when "date_range" %>
+
+ <%= lucide_icon "calendar", class: "w-5 h-5 text-gray-500" %>
+
+ <% if filter[:value][:gteq] && filter[:value][:lteq] %>
+ <%= filter[:value][:gteq] %> → <%= filter[:value][:lteq] %>
+ <% elsif filter[:value][:gteq] %>
+ on or after <%= filter[:value][:gteq] %>
+ <% elsif filter[:value][:lteq] %>
+ on or before <%= filter[:value][:lteq] %>
+ <% end %>
+
+
<% end %>
<%= form_with url: search_transactions_path, html: { class: "flex items-center" } do |form| %>
<%= form.hidden_field :remove_param, value: filter[:original][:key] %>
<% if filter[:original][:value] %>
<%= form.hidden_field :remove_param_value, value: filter[:original][:value] %>
+ <% else %>
<% end %>
<%= form.button type: "submit", class: "hover:text-gray-900" do %>
<%= lucide_icon "x", class: "w-4 h-4 text-gray-500" %>
diff --git a/app/views/transactions/_filters.html.erb b/app/views/transactions/_filters.html.erb
index 5a7d2b7e..5349f2b0 100644
--- a/app/views/transactions/_filters.html.erb
+++ b/app/views/transactions/_filters.html.erb
@@ -1,7 +1,7 @@
<%# locals: (filters:) %>
<%= turbo_frame_tag "transactions_filters" do %>
-
+
<% filters.each do |filter| %>
<%= render partial: "transactions/filter", locals: { filter: filter } %>
<% end %>
diff --git a/app/views/transactions/_search_form.html.erb b/app/views/transactions/_search_form.html.erb
index c595540c..7087c712 100644
--- a/app/views/transactions/_search_form.html.erb
+++ b/app/views/transactions/_search_form.html.erb
@@ -1,7 +1,7 @@
<%# locals: (q:) %>
<%= turbo_frame_tag "transactions_search_form" do %>
- <%= search_form_for @q, url: search_transactions_path, html: { method: :post, data: { turbo_frame: "transactions_list", "controller": "auto-submit-form" } } do |form| %>
+ <%= search_form_for @q, url: search_transactions_path, html: { method: :post, data: { turbo_frame: "transactions_list" } } do |form| %>
<%= render partial: "transactions/search_form/search_filter", locals: { form: form } %>
@@ -11,52 +11,40 @@
<%= lucide_icon("list-filter", class: "w-5 h-5 text-gray-500") %>
Filter
- <%# TODO: Refactor this for readability and maintainability %>
-
+
"
+ class="hidden absolute flex z-10 h-80 w-[540px] top-12 right-0 border border-alpha-black-25 bg-white rounded-lg shadow-xs">
-
-
-
-
-
-
+ <% transaction_filters.each do |filter| %>
+
+ <% end %>
-
-
- <%= render partial: "transactions/search_form/date_filter", locals: { form: form } %>
+
+
+ <% transaction_filters.each do |filter| %>
+
+ <%= render partial: "transactions/search_form/#{filter[:partial]}", locals: { form: form } %>
+
+ <% end %>
-
- <%= render partial: "transactions/search_form/account_filter", locals: { form: form } %>
-
-
- <%= render partial: "transactions/search_form/type_filter", locals: { form: form } %>
-
-
- <%= render partial: "transactions/search_form/amount_filter", locals: { form: form } %>
-
-
- <%= render partial: "transactions/search_form/category_filter", locals: { form: form } %>
-
-
- <%= render partial: "transactions/search_form/merchant_filter", locals: { form: form } %>
+
+ <%= button_tag type: "reset", data: { action: "menu#close" }, class: "py-2 px-3 bg-gray-50 rounded-lg text-sm text-gray-900 font-medium" do %>
+ Cancel
+ <% end %>
+ <%= button_tag type: "submit", class: "py-2 px-3 bg-gray-900 rounded-lg text-sm text-white font-medium" do %>
+ Apply
+ <% end %>
diff --git a/app/views/transactions/search_form/_account_filter.html.erb b/app/views/transactions/search_form/_account_filter.html.erb
index c0d0625e..38fbe7c1 100644
--- a/app/views/transactions/search_form/_account_filter.html.erb
+++ b/app/views/transactions/search_form/_account_filter.html.erb
@@ -7,7 +7,7 @@
<% Current.family.accounts.each do |account| %>
- <%= form.check_box :account_id_in, { "data-auto-submit-form-target": "auto", multiple: true, class: "rounded-sm border-gray-300 text-indigo-600 shadow-xs focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" }, account.id, nil %>
+ <%= form.check_box :account_id_in, { multiple: true, class: "rounded-sm border-gray-300 text-indigo-600 shadow-xs focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" }, account.id, nil %>
<%= form.label :account_id_in, account.name, value: account.id, class: "text-sm text-gray-900" %>
<% end %>
diff --git a/app/views/transactions/search_form/_date_filter.html.erb b/app/views/transactions/search_form/_date_filter.html.erb
index abe66367..265a8980 100644
--- a/app/views/transactions/search_form/_date_filter.html.erb
+++ b/app/views/transactions/search_form/_date_filter.html.erb
@@ -1,4 +1,5 @@
<%# locals: (form:) %>
-
-
Filter by date coming soon...
+
+ <%= form.date_field :date_gteq, placeholder: "Start date", class: "block w-full border border-gray-200 rounded-md py-2 pl-3 pr-3 focus:border-gray-500 focus:ring-gray-500 sm:text-sm" %>
+ <%= form.date_field :date_lteq, placeholder: "End date", class: "block w-full border border-gray-200 rounded-md py-2 pl-3 pr-3 focus:border-gray-500 focus:ring-gray-500 sm:text-sm mt-2" %>