Add rider sign-up date filter to search functionality#497
Conversation
Implement a new "signed up" filter allowing users to search riders by signup timeframes (today, yesterday, week, month, year). Includes autocomplete suggestions and badge styling consistent with existing filters. - Add signed_up filter cases to RiderSearch module - Support explicit date boundaries for today/yesterday - Support relative time queries for week/month/year ranges - Add UI suggestions and autocomplete support - Add comprehensive test suite - Introduce signed_up_ago/2 helper for cleaner test code
📝 WalkthroughWalkthroughThis PR adds a complete rider search filter for sign-up dates. Users can filter riders by when they joined using five time period options (today, yesterday, week, month, year). The backend applies date-based and relative-window queries, the frontend provides autocompleting filter suggestions, and comprehensive tests validate the filtering logic. ChangesSigned Up Filter Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/bike_brigade/riders/rider_search_test.exs (1)
245-263: ⚡ Quick winAdd exclusion-path tests for
monthandyear.You validate inclusion for
month/year, but not explicit exclusion. Adding those two cases would close the regression gap around window boundaries.Suggested additions
+ test "month - excludes rider who signed up more than a month ago" do + rider = fixture(:rider, %{signed_up_on: signed_up_ago(40, :day)}) + + {_rs, results} = + RiderSearch.new(filters: [%Filter{type: :signed_up, search: "month"}]) + |> RiderSearch.fetch() + + refute rider_in_results?(results, rider.id) + end + + test "year - excludes rider who signed up more than a year ago" do + rider = fixture(:rider, %{signed_up_on: signed_up_ago(370, :day)}) + + {_rs, results} = + RiderSearch.new(filters: [%Filter{type: :signed_up, search: "year"}]) + |> RiderSearch.fetch() + + refute rider_in_results?(results, rider.id) + endAs per coding guidelines, “
test/**/*.exs: Review test coverage and ExUnit best practices. Ensure tests are focused and descriptive.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/bike_brigade/riders/rider_search_test.exs` around lines 245 - 263, Add two exclusion tests mirroring the existing inclusion specs: create tests named like "month - excludes rider who signed up just over a month ago" and "year - excludes rider who signed up just over a year ago"; each should create a rider via fixture(:rider, %{signed_up_on: signed_up_ago(31, :day)}) and fixture(:rider, %{signed_up_on: signed_up_ago(366, :day)}) respectively, run RiderSearch.new(filters: [%Filter{type: :signed_up, search: "month"}]) |> RiderSearch.fetch() and RiderSearch.new(... search: "year" ...) |> RiderSearch.fetch(), and assert the rider is not returned using refute rider_in_results?(results, rider.id) to close the boundary-regression gap.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/bike_brigade_web/live/rider_live/index.ex`:
- Line 51: The empty-search branch resets many fields on the suggestions map but
omits phone, leaving stale phone suggestions; update the map literal used there
(the %{suggestions | ...} expression in rider_live/index.ex) to also reset the
phone field (e.g., add phone: [] or phone: nil consistent with how
suggestions.phone is used elsewhere) so phone suggestions are cleared when the
search input is cleared.
In `@lib/bike_brigade/riders/rider_search.ex`:
- Around line 361-382: The apply_filter/3 function lacks a fallback clause for
%Filter{type: :signed_up}, causing a FunctionClauseError for unsupported search
values; add a catch-all clause for apply_filter(%Filter{type: :signed_up,
search: _}, query, _filters) that safely no-ops (returns the incoming query) or
rejects with a clear error, and place it after the existing :signed_up clauses
so unknown period values (e.g., "foo") don't crash the process; reference the
existing apply_filter/3 function and the Filter struct when implementing the
fallback.
---
Nitpick comments:
In `@test/bike_brigade/riders/rider_search_test.exs`:
- Around line 245-263: Add two exclusion tests mirroring the existing inclusion
specs: create tests named like "month - excludes rider who signed up just over a
month ago" and "year - excludes rider who signed up just over a year ago"; each
should create a rider via fixture(:rider, %{signed_up_on: signed_up_ago(31,
:day)}) and fixture(:rider, %{signed_up_on: signed_up_ago(366, :day)})
respectively, run RiderSearch.new(filters: [%Filter{type: :signed_up, search:
"month"}]) |> RiderSearch.fetch() and RiderSearch.new(... search: "year" ...) |>
RiderSearch.fetch(), and assert the rider is not returned using refute
rider_in_results?(results, rider.id) to close the boundary-regression gap.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6693a386-50ca-412d-88b7-dc98a9638a1a
📒 Files selected for processing (4)
lib/bike_brigade/riders/rider_search.exlib/bike_brigade_web/live/rider_live/index.exlib/bike_brigade_web/live/rider_live/index.html.heextest/bike_brigade/riders/rider_search_test.exs
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/bike_brigade_web/live/rider_live/index.ex">
<violation number="1" location="lib/bike_brigade_web/live/rider_live/index.ex:51">
P2: The `phone` field is missing from the suggestions reset when search is cleared, which can leave stale phone suggestions visible. Add `phone: nil` to the reset map.</violation>
</file>
<file name="lib/bike_brigade/riders/rider_search.ex">
<violation number="1" location="lib/bike_brigade/riders/rider_search.ex:361">
P2: Missing catch-all clause for `%Filter{type: :signed_up}` — any value outside the expected set (e.g. a crafted `signed_up:foo`) will raise a `FunctionClauseError`. Add a fallback that returns the query unchanged.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Describe your changes
Implement a new "signed up" filter allowing users to search riders by signup timeframes (today, yesterday, week, month, year). Includes autocomplete suggestions and badge styling consistent with existing filters.
Checklist before requesting a review
about this update in the description above.
Summary by cubic
Adds a "signed up" filter to rider search so you can find riders by signup timeframe (today, yesterday, week, month, year). Includes autocomplete suggestions, a "Signed Up" badge, and full test coverage.
New Features
signed_upfilter with values: today, yesterday, week, month, year.signed_up_ago/2test helper.signed_upvalues are ignored (no-op) to prevent errors.Refactors
:forfor simpler markup.Written for commit 4e9e025. Summary will update on new commits.
Summary by CodeRabbit
Release Notes