Skip to content

feat(BR-155): Add search functionality to data feed - #97

Merged
geeth24 merged 3 commits into
mainfrom
kamalesh/br-155-frontend-add-search-to-data-feed
Nov 18, 2025
Merged

feat(BR-155): Add search functionality to data feed#97
geeth24 merged 3 commits into
mainfrom
kamalesh/br-155-frontend-add-search-to-data-feed

Conversation

@Kammohan

@Kammohan Kammohan commented Nov 17, 2025

Copy link
Copy Markdown
Collaborator
  • Backend: Add search query parameter to /weekly-crises endpoint

    • Supports search by crisis name, location, and disaster type
    • Case-insensitive search with SQL ILIKE
  • Frontend: Add search input with 500ms debounce

    • Clean search UI with icon in data feed header
    • Auto-resets to page 1 on search
    • Smart empty state for no search results
  • API Client: Updated getWeeklyCrises() to accept search param

    • Uses URLSearchParams for clean query building

Summary by CodeRabbit

  • New Features
    • Search added to Crisis/Recent Crisis feed (filters by name, location, or disaster type)
    • Live filtering with 500ms debounce for smoother typing
    • Pagination resets to page 1 when a new search is performed
    • Clear "No results found for """ messaging when no matches
    • Header layout updated to include the search input alongside the title

- Backend: Add search query parameter to /weekly-crises endpoint
  - Supports search by crisis name, location, and disaster type
  - Case-insensitive search with SQL ILIKE

- Frontend: Add search input with 500ms debounce
  - Clean search UI with icon in data feed header
  - Auto-resets to page 1 on search
  - Smart empty state for no search results

- API Client: Updated getWeeklyCrises() to accept search param
  - Uses URLSearchParams for clean query building
@Kammohan
Kammohan requested review from a team as code owners November 17, 2025 23:13
@coderabbitai

coderabbitai Bot commented Nov 17, 2025

Copy link
Copy Markdown

Walkthrough

Adds a debounced search input to the crisis feed, threads a new search parameter from frontend → client → backend, and applies an OR-based filter on Disaster.description, Disaster.location_name, and Post.disaster_type when a search term is provided.

Changes

Cohort / File(s) Summary
Frontend Search UI
client/app/dashboard/data-feed/page.tsx
Adds search Input and Search icon, introduces searchQuery and debouncedSearch (500ms), resets pagination on search, updates header layout, and shows "No results found for """ when appropriate
API Client
client/lib/api-client.ts
Extends getWeeklyCrises(...) with optional search parameter, builds request URL via URLSearchParams, and appends trimmed search only when present
Backend Search Logic
server/routers/data_feed.py
Adds search query parameter to get_weekly_crises, imports or_, applies OR filter across Disaster.description, Disaster.location_name, and Post.disaster_type when search is non-empty, preserves ordering and pagination

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as Frontend
    participant Debounce as Debounce (500ms)
    participant Client as API Client
    participant Backend
    participant DB as Database

    User->>UI: Type search term
    UI->>Debounce: update searchQuery
    Debounce-->>Debounce: wait 500ms
    Debounce->>UI: set debouncedSearch (reset page -> 1)
    UI->>Client: getWeeklyCrises(days, page, pageSize, search=debouncedSearch)
    Client->>Backend: GET /crises?...&search=...
    Backend->>DB: WHERE (description ILIKE OR location_name ILIKE OR post.disaster_type ILIKE)
    DB-->>Backend: rows
    Backend-->>Client: response
    Client-->>UI: render list
    alt no results & search non-empty
        UI->>User: show "No results found for '<term>'"
    else results
        UI->>User: show crises list
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Check frontend debounce, page-reset, and UI layout in client/app/dashboard/data-feed/page.tsx
  • Verify getWeeklyCrises URL construction and trimming in client/lib/api-client.ts
  • Validate backend OR-filter logic, parameter handling, and query performance in server/routers/data_feed.py

Suggested labels

enhancement

Suggested reviewers

  • geeth24
  • golanu814

Poem

🐇 I hopped through code to add a search,
I waited half a second for each perch,
I sniffed descriptions, places, and type,
Returned the matches that felt just right,
A tiny hop — results in sight! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main feature being added across all three modified files: search functionality integrated into the data feed at multiple layers (frontend UI, API client, and backend endpoint).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kamalesh/br-155-frontend-add-search-to-data-feed

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f965a8 and 31cd481.

📒 Files selected for processing (1)
  • client/app/dashboard/data-feed/page.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/app/dashboard/data-feed/page.tsx

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) label Nov 17, 2025
@github-actions

github-actions Bot commented Nov 17, 2025

Copy link
Copy Markdown

✨ Version Bump Prediction

When this PR is merged to main, the version will be bumped:

1.48.01.49.0 (minor)


💡 How to change the version bump type

The version bump is determined by your commit messages and PR title:

  • Major (2.0.0): Use BREAKING CHANGE: or MAJOR: in title/commits
  • Minor (1.49.0): Use feat: or feature: in title/commits
  • Patch (1.48.1): Use fix:, chore:, docs:, etc.

What I analyzed:

  • PR Title: feat(BR-155): Add search functionality to data feed
  • Commits: 3 commit(s)

Edit your PR title or commit messages to change the bump type.

@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment Ready!

Backend: https://api-kamalesh-br-155-frontend-add-s.private.bluerelief.app
Frontend: https://kamalesh-br-155-frontend-add-s.private.bluerelief.app
Email Service: https://email-api-kamalesh-br-155-frontend-add-s.private.bluerelief.app

Commit: 13950d9


🔐 Authentication

Demo Login: Click "Google Sign In" → Use demo auth (no Google account needed)
Demo Account: demo@bluerelief.test
Note: Google OAuth not available for preview domains. Demo mode enabled for testing.


✨ Version Bump Prediction

When this PR is merged to main, the version will be bumped:

1.47.21.47.3 (patch)

💡 How to change the version bump type

  • For patch: Use fix:, chore:, docs:, or ci: in commit messages
  • For minor: Use feat: or feature: in commit messages
  • For major: Include BREAKING CHANGE or breaking: in commit messages

Preview will be automatically deleted when PR is closed or merged.

@github-actions github-actions Bot added version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) and removed version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) labels Nov 17, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
server/routers/data_feed.py (1)

97-108: LGTM! Search filter correctly implemented with a performance note.

The search implementation is functionally correct:

  • Proper trimming and empty-string checks
  • Case-insensitive search across the three relevant fields (description, location_name, disaster_type)
  • SQLAlchemy's parameter binding safely handles the search term

Performance consideration: ILIKE with leading wildcards (%term%) cannot leverage standard B-tree indexes. For larger datasets, consider PostgreSQL's trigram indexes (pg_trgm) or full-text search (tsvector) for better performance.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 405216e and e9c418e.

📒 Files selected for processing (3)
  • client/app/dashboard/data-feed/page.tsx (6 hunks)
  • client/lib/api-client.ts (2 hunks)
  • server/routers/data_feed.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
server/routers/data_feed.py (1)
server/db_utils/db.py (2)
  • Disaster (183-202)
  • Post (116-180)
client/app/dashboard/data-feed/page.tsx (1)
client/lib/api-client.ts (1)
  • getWeeklyCrises (95-130)
🪛 Ruff (0.14.5)
server/routers/data_feed.py

86-86: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

🔇 Additional comments (8)
client/lib/api-client.ts (1)

95-129: LGTM! Clean implementation of search parameter.

The search parameter is correctly integrated:

  • Default empty string is appropriate
  • URLSearchParams handles encoding properly
  • Conditional append prevents empty search parameters in the URL
  • Trimming prevents whitespace-only searches
client/app/dashboard/data-feed/page.tsx (5)

4-4: LGTM! Necessary imports for search functionality.

The Search icon and Input component are properly imported and used in the search UI.

Also applies to: 8-8


80-81: LGTM! Proper state management for debounced search.

The two-state pattern (immediate searchQuery and debounced debouncedSearch) is the correct approach for implementing search with debounce.


103-111: LGTM! Solid debounce implementation.

The 500ms debounce with page reset is well-implemented:

  • Proper cleanup prevents memory leaks
  • Resetting to page 1 on search ensures users see the first page of results
  • Timer delay is appropriate for search UX

117-117: LGTM! Correct API integration with proper dependencies.

The implementation correctly:

  • Passes the debounced search term (not the immediate value) to the API
  • Includes both currentPage and debouncedSearch in useEffect dependencies, ensuring data refetch on either change

Also applies to: 128-128


445-467: LGTM! Excellent UX implementation.

The search UI and empty states are well-designed:

  • Search input is prominently placed with clear placeholder text
  • Icon positioning enhances visual clarity
  • Empty state messaging intelligently differentiates between "no search results" vs "no crises detected"
  • The conditional messaging at lines 582-600 provides helpful user guidance

Also applies to: 582-600

server/routers/data_feed.py (2)

3-3: LGTM! Correct import for OR-based filtering.

The or_ import from SQLAlchemy is properly used in the search filter implementation.


85-88: LGTM! Proper FastAPI parameter definition.

The search parameter is correctly defined with appropriate defaults and description. The docstring accurately reflects the new search capability.

Note: The static analysis warning about Depends(get_db) in line 86 is a false positive - this is the standard and correct FastAPI pattern for dependency injection.

- Merged lucide-react imports (Search + Info, X)
- Added showDisclaimer state from main
- Kept BR-155 search functionality intact

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
client/app/dashboard/data-feed/page.tsx (1)

458-467: Consider adding aria-label for accessibility.

The search input would benefit from an explicit aria-label to improve screen reader accessibility, especially since the placeholder text may not be announced consistently across all screen readers.

Apply this diff to add the aria-label:

  <Input
    type="text"
    placeholder="Search by name, location, or disaster type..."
    value={searchQuery}
    onChange={(e) => setSearchQuery(e.target.value)}
    className="pl-9"
+   aria-label="Search crises by name, location, or disaster type"
  />
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9c418e and 3f965a8.

📒 Files selected for processing (1)
  • client/app/dashboard/data-feed/page.tsx (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client/app/dashboard/data-feed/page.tsx (1)
client/lib/api-client.ts (1)
  • getWeeklyCrises (95-130)
🔇 Additional comments (4)
client/app/dashboard/data-feed/page.tsx (4)

4-4: LGTM!

The new imports are correctly added and used in the search functionality implementation.

Also applies to: 8-8


104-112: LGTM!

The debounce implementation is correct with proper cleanup and an appropriate 500ms delay. Resetting to page 1 on search change provides good UX.


118-118: LGTM!

The crisis fetch integration correctly passes the debounced search term to the API and includes it in the useEffect dependencies to trigger re-fetching when the search changes.

Also applies to: 129-129


583-601: LGTM!

The conditional empty state rendering correctly differentiates between "no search results" and "no crises detected," providing clear, helpful feedback to users.

const [lastUpdated, setLastUpdated] = useState<Date | null>(null)
const [searchQuery, setSearchQuery] = useState("")
const [debouncedSearch, setDebouncedSearch] = useState("")
const [showDisclaimer, setShowDisclaimer] = useState(true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove unused state variable.

The showDisclaimer state is declared but never used anywhere in the component. This should be removed to keep the code clean.

Apply this diff to remove the unused state:

  const [searchQuery, setSearchQuery] = useState("")
  const [debouncedSearch, setDebouncedSearch] = useState("")
- const [showDisclaimer, setShowDisclaimer] = useState(true)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In client/app/dashboard/data-feed/page.tsx around line 82, the component
declares an unused state variable `showDisclaimer` via useState which is never
referenced; remove the entire declaration (importing useState is optional) and
any related unused imports so the component no longer defines or references
`showDisclaimer`, and tidy up imports if useState becomes unused.

- Merged Search import from BR-155 with Info, X from main
- Kept all state variables (searchQuery, debouncedSearch, showDisclaimer)
@github-actions github-actions Bot added version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) and removed version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0) labels Nov 18, 2025
@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment Ready!

Backend: https://api-kamalesh-br-155-frontend-add-s.private.bluerelief.app
Frontend: https://kamalesh-br-155-frontend-add-s.private.bluerelief.app
Email Service: https://email-api-kamalesh-br-155-frontend-add-s.private.bluerelief.app

Commit: c33fa55


🔐 Authentication

Demo Login: Click "Google Sign In" → Use demo auth (no Google account needed)
Demo Account: demo@bluerelief.test
Note: Google OAuth not available for preview domains. Demo mode enabled for testing.


✨ Version Bump Prediction

When this PR is merged to main, the version will be bumped:

1.48.01.48.1 (patch)

💡 How to change the version bump type

  • For patch: Use fix:, chore:, docs:, or ci: in commit messages
  • For minor: Use feat: or feature: in commit messages
  • For major: Include BREAKING CHANGE or breaking: in commit messages

Preview will be automatically deleted when PR is closed or merged.

@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment Ready!

Backend: https://api-kamalesh-br-155-frontend-add-s.private.bluerelief.app
Frontend: https://kamalesh-br-155-frontend-add-s.private.bluerelief.app
Email Service: https://email-api-kamalesh-br-155-frontend-add-s.private.bluerelief.app

Commit: c33fa55


🔐 Authentication

Demo Login: Click "Google Sign In" → Use demo auth (no Google account needed)
Demo Account: demo@bluerelief.test
Note: Google OAuth not available for preview domains. Demo mode enabled for testing.


✨ Version Bump Prediction

When this PR is merged to main, the version will be bumped:

1.48.01.48.1 (patch)

💡 How to change the version bump type

  • For patch: Use fix:, chore:, docs:, or ci: in commit messages
  • For minor: Use feat: or feature: in commit messages
  • For major: Include BREAKING CHANGE or breaking: in commit messages

Preview will be automatically deleted when PR is closed or merged.

@geeth24
geeth24 merged commit 2e65a9e into main Nov 18, 2025
15 checks passed
@geeth24
geeth24 deleted the kamalesh/br-155-frontend-add-search-to-data-feed branch November 18, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version: minor ✨ New features - bumps minor version (1.0.0 → 1.1.0)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants