feat(ssr): add clear filters button to transactions

Shows a "Clear filters" button in the transactions action bar whenever a
non-date filter is active. It's a boosted link back to the transactions
page that preserves the date range (and any implied status), so the
sidebar filters and table both reset.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 22:43:43 -07:00
parent a7e9fbaf6b
commit 2e3c1e3646

View File

@@ -421,6 +421,35 @@
(import-batch-id* request)
(exact-match-id* request)]])
(def non-date-filter-params
"Query-param keys that represent transaction filters other than the date range."
[:vendor :account :bank-account :description :memo :location
:amount-gte :amount-lte :linked-to :unresolved :potential-duplicates
:import-batch-id :exact-match-id])
(defn- filter-value-active? [v]
(cond
(nil? v) false
(false? v) false
(string? v) (not (str/blank? v))
:else true))
(defn non-date-filters-active? [request]
(boolean (some (comp filter-value-active? #(get (:query-params request) %))
non-date-filter-params)))
(defn clear-filters-href
"URL for the transactions page with every non-date filter cleared, preserving
the active date range (and an implied status, if any)."
[request]
(let [qp (:query-params request)
status (:status qp)]
(str (hu/url (bidi/path-for ssr-routes/only-routes ::route/page)
(cond-> {}
(:start-date qp) (assoc "start-date" (atime/unparse (:start-date qp) atime/normal-date))
(:end-date qp) (assoc "end-date" (atime/unparse (:end-date qp) atime/normal-date))
(keyword? status) (assoc "status" (name status)))))))
(def grid-page
(helper/build {:id "entity-table"
:nav com/main-aside-nav
@@ -434,29 +463,34 @@
(assoc-in (exact-match-id* request) [1 :hx-swap-oob] true)
(some-> (import-batch-id* request) (assoc-in [1 :hx-swap-oob] true))])
:action-buttons (fn [request]
[(com/button {:color :primary
:hx-get (bidi/path-for ssr-routes/only-routes ::route/bulk-code)
:hx-target "#modal-holder"
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
"x-bind:disabled" "selected.length === 0 && !all_selected"
"hx-include" "#transaction-filters"}
"Code")
(com/button {:color :primary
:hx-post (bidi/path-for ssr-routes/only-routes ::route/bulk-delete)
:hx-target "#modal-holder"
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
"x-bind:disabled" "selected.length === 0 && !all_selected"
"hx-include" "#transaction-filters"
:hx-confirm "Are you sure you want to delete these transactions?"}
"Delete")
(com/button {:color :primary
:hx-post (bidi/path-for ssr-routes/only-routes ::route/bulk-delete)
:hx-target "#modal-holder"
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
"x-bind:disabled" "selected.length === 0 && !all_selected"
"hx-include" "#transaction-filters"
:hx-confirm "Are you sure you want to suppress these transactions?"}
"Suppress")])
(cond-> [(com/button {:color :primary
:hx-get (bidi/path-for ssr-routes/only-routes ::route/bulk-code)
:hx-target "#modal-holder"
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
"x-bind:disabled" "selected.length === 0 && !all_selected"
"hx-include" "#transaction-filters"}
"Code")
(com/button {:color :primary
:hx-post (bidi/path-for ssr-routes/only-routes ::route/bulk-delete)
:hx-target "#modal-holder"
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
"x-bind:disabled" "selected.length === 0 && !all_selected"
"hx-include" "#transaction-filters"
:hx-confirm "Are you sure you want to delete these transactions?"}
"Delete")
(com/button {:color :primary
:hx-post (bidi/path-for ssr-routes/only-routes ::route/bulk-delete)
:hx-target "#modal-holder"
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
"x-bind:disabled" "selected.length === 0 && !all_selected"
"hx-include" "#transaction-filters"
:hx-confirm "Are you sure you want to suppress these transactions?"}
"Suppress")]
(non-date-filters-active? request)
(conj (com/a-button {:color :secondary
:hx-boost "true"
:href (clear-filters-href request)}
"Clear filters"))))
:row-buttons (fn [request entity]
(let [client (:transaction/client entity)
locked-until (:client/locked-until client)