feat(transactions): filter by AI / AI history categorization status

Merged
JO
2mo ago
+281-3

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_id enrichment still equals the current category
    • AI history — automatic enrichment(s) exist but none matches the current category (changed or cleared)
    • both = any automatic enrichment
  • Transaction::Search#apply_ai_status_filter uses correlated EXISTS subqueries against data_enrichments (never a join), so a transaction with both an ai and a bayes row is listed once and counted once in the summary totals (same rationale as #3174). History is EXISTS(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_filter works unchanged.
  • Filter popover nav column gains md:overflow-y-auto so the ninth item scrolls at the existing md:h-80 height 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 and totals.count / composes with categories: / cleared category → history.
  • test/controllers/transactions_controller_test.rb (+4): chips render for current and history, current excludes history-only rows, clear_filter on ai_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.