feat(transactions): filter by AI / AI history categorization status
Merged
JO
2mo ago+281+281+012345678901234567890123456789-3-3-0123456789
Branch: feat/ai-category-provenance-filter (1 commit, 57fa0865, based on main @ 44bbfb2)
Closes: #3598
Independent of the provenance-badge PR (shares the one-line Transaction::AUTO_CATEGORY_SOURCES constant — trivial conflict if both merge).
Problem
After auto-categorization (Bayes pre-pass, then LLM) there is no way to review the transactions whose category was chosen automatically, or the ones where that choice has since been overridden.
Change
- New AI group in the Transactions filter popover with two independent checkboxes:
- AI — an automatic (
ai/bayes)category_idenrichment still equals the current category - AI history — automatic enrichment(s) exist but none matches the current category (changed or cleared)
- both = any automatic enrichment
- AI — an automatic (
Transaction::Search#apply_ai_status_filteruses correlatedEXISTSsubqueries againstdata_enrichments(never a join), so a transaction with both anaiand abayesrow is listed once and counted once in the summary totals (same rationale as #3174). History isEXISTS(any) AND NOT EXISTS(match), so the two sets are disjoint and agree with the badge semantics. Values are whitelisted; SQL uses bound parameters only (Brakeman: 0 warnings).- Controller permits
ai_status[]; active-filter chips render "AI" / "AI history" with icons;clear_filterworks unchanged. - Filter popover nav column gains
md:overflow-y-autoso the ninth item scrolls at the existingmd:h-80height instead of clipping.
Validation
test/models/transaction/search_test.rb(+8): current / history / both / none / bogus values ignored / ai+bayes dual-row counted once in list andtotals.count/ composes withcategories:/ cleared category → history.test/controllers/transactions_controller_test.rb(+4): chips render for current and history, current excludes history-only rows,clear_filteronai_status.bin/rails test test/models/transaction/search_test.rb test/controllers/transactions_controller_test.rb→ 118 runs, 0 failures.bin/rubocop: no offenses.erb_lint: clean.bin/brakeman -q: 0 warnings.
Screenshots
TODO before publishing: filter popover with the AI group; active chips.
Summary by CodeRabbit
- New Features
- Added transaction search filters for automatically categorized transactions, distinguishing categories that remain current from those changed or cleared since categorization.
- Added filter labels, descriptions, and badges to clarify each status, plus improved filter-menu scrolling on medium and larger screens.
- Bug Fixes
- Unsupported AI filter values are ignored, and clearing the filter removes it from search parameters.
- Updated cached transaction data when AI enrichment records are cleared, with cache updates committed alongside the deletion.