Skip to content

Enhancement: Facility search feature for User Dashboard#16248

Open
pranavrutagi-egov wants to merge 3 commits intoohcnetwork:developfrom
pranavrutagi-egov:issues/#16220/Enhancement-User-Home-Facility-Selector
Open

Enhancement: Facility search feature for User Dashboard#16248
pranavrutagi-egov wants to merge 3 commits intoohcnetwork:developfrom
pranavrutagi-egov:issues/#16220/Enhancement-User-Home-Facility-Selector

Conversation

@pranavrutagi-egov
Copy link
Copy Markdown
Contributor

@pranavrutagi-egov pranavrutagi-egov commented Apr 1, 2026

Proposed Changes

Fixes #16220

  • Added atom recentFacilityAtom for persisting last visited facility
  • Capturing navigations in AppRouter for facility visit
  • Added Popover (and Drawer for mobile view) in UserDashboard for search functionality for facilities based on existing similar implementation in RoleSelect component
  • Locale added in en.json for last_visited

Tagging: @ohcnetwork/care-fe-code-reviewers

Relevent Screenshots:

  1. Dashboard - Facilities Tab:
    Image

  2. When focusing on search component:
    Image

  3. Searching by facility name:
    Image

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

  • New Features
    • Added facility search to the Facilities tab
    • Recently visited facility appears first in the list
    • Application remembers your last visited facility across browser sessions

@pranavrutagi-egov pranavrutagi-egov requested review from a team April 1, 2026 06:04
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

Walkthrough

This PR introduces facility search and recent facility tracking to the user dashboard. A new Jotai atom persists the last visited facility ID in localStorage. The router tracks facility navigation via URL path changes. The dashboard's Facilities tab is enhanced with a search control, recent facility sorting, and responsive UI (Drawer on mobile, Popover on desktop).

Changes

Cohort / File(s) Summary
State Management
src/atoms/recentFacilityAtom.ts
New Jotai atom using atomWithStorage to persist the last visited facility ID in localStorage under key "last-visited-facility" with initial value null.
Routing & Navigation
src/Routers/AppRouter.tsx
Added effect to track facility navigation via URL pattern matching. Extracts facility ID from /facility/<id> path segments and updates the recent facility atom on every route change.
UI & Features
src/pages/UserDashboard.tsx
Enhanced Facilities tab with search control, recent facility reordering, and responsive UI. Added facility-name search state and navigation to facility overview pages. Mobile uses Drawer; desktop uses Popover for search UI.
Localization
public/locale/en.json
Added new locale string key last_visited with value "Last Visited" for UI labeling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the facility search feature with UI for both desktop (Popover) and mobile (Drawer), displays recent/last-visited facility first, and adds required localization.
Out of Scope Changes check ✅ Passed All changes directly support the facility search feature: atom for persistence, router integration for tracking visits, UI components for search, and required localization key.
Title check ✅ Passed The pull request title 'Enhancement: Facility search feature for User Dashboard' directly and accurately summarizes the main change: adding a searchable facility selector to the User Dashboard with support for tracking recently visited facilities.
Description check ✅ Passed The pull request description includes all required sections: proposed changes, issue reference, detailed change list, team tagging, relevant screenshots, and merge checklist with appropriate checkmarks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🚀 Preview Deployment Ready!

🔗 Preview URL: https://pr-16248.care-preview-a7w.pages.dev

📱 Mobile Access:
Scan the QR code below to open the preview on your mobile device.

QR Code


This preview will be automatically updated when you push new commits to this PR.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@public/locale/en.json`:
- Line 3015: Remove the "last_visited" key from its current position (the entry
`"last_visited": "Last Visited",`) and append that exact key/value pair to the
very end of the en.json file so the file remains valid JSON (watch
commas/whitespace). Ensure you only move the existing key (do not duplicate),
preserve the exact label "Last Visited", and validate the file after change so
no trailing-comma or syntax errors are introduced.

In `@src/pages/UserDashboard.tsx`:
- Line 48: The import for useAtomValue from "jotai" is misplaced; move the line
importing useAtomValue so it sits with the other third-party imports at the top
of the file (near React and other external libs) to match the import grouping
used in AppRouter.tsx; update the import order but do not change the symbol name
(useAtomValue) or any references inside the UserDashboard component.
- Around line 333-335: The TabContent call is using the unsorted facilities list
(tabItems={facilities}) while the search dropdown uses sortedFacilities, causing
inconsistent ordering; update the TabContent invocation in UserDashboard (the
component rendering TabContent) to pass sortedFacilities (or the same sorted
array you compute for the search dropdown) as tabItems so the card grid and
search list use the same ordering, ensuring sortedFacilities is
defined/available in that scope and remove or replace any other usages of
facilities for display to avoid divergent orders.

In `@src/Routers/AppRouter.tsx`:
- Around line 33-34: Reorder the imports in AppRouter.tsx so third-party module
imports come first: move useEffect (from "react") and useSetAtom (from "jotai")
up into the top import group with other 3rd-party imports to follow the
project's convention ("3rd-party → library → CAREUI → UI → components → hooks →
utils → relative"); update the import block so useEffect and useSetAtom are
imported alongside other external packages and keep component/library imports
below them.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 18bc59e6-ce28-4e77-958d-fcf68bea046a

📥 Commits

Reviewing files that changed from the base of the PR and between 296dfbd and b309473.

📒 Files selected for processing (4)
  • public/locale/en.json
  • src/Routers/AppRouter.tsx
  • src/atoms/recentFacilityAtom.ts
  • src/pages/UserDashboard.tsx

"last_updated": "Last Updated",
"last_updated_by": "Last updated by",
"last_vaccinated_on": "Last Vaccinated on",
"last_visited": "Last Visited",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Move this new i18n key to the end of en.json to follow repo rule.

"last_visited" should be appended at the end of public/locale/en.json, not inserted mid-file (Line 3015).

Proposed change
-  "last_vaccinated_on": "Last Vaccinated on",
-  "last_visited": "Last Visited",
+  "last_vaccinated_on": "Last Vaccinated on",
...
-  "zoom_out": "Zoom Out",
+  "zoom_out": "Zoom Out",
+  "last_visited": "Last Visited",
   "℞": "℞"

As per coding guidelines: "Append missing i18n keys directly to the end of the public/locale/en.json file without reading i18n files".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@public/locale/en.json` at line 3015, Remove the "last_visited" key from its
current position (the entry `"last_visited": "Last Visited",`) and append that
exact key/value pair to the very end of the en.json file so the file remains
valid JSON (watch commas/whitespace). Ensure you only move the existing key (do
not duplicate), preserve the exact label "Last Visited", and validate the file
after change so no trailing-comma or syntax errors are introduced.

import { FacilityBareMinimum } from "@/types/facility/facility";
import { Organization, getOrgLabel } from "@/types/organization/organization";
import organizationApi from "@/types/organization/organizationApi";
import { useAtomValue } from "jotai";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Move jotai import to align with 3rd-party imports at the top.

Similar to AppRouter.tsx, the jotai import should be grouped with other 3rd-party imports near the top of the file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/UserDashboard.tsx` at line 48, The import for useAtomValue from
"jotai" is misplaced; move the line importing useAtomValue so it sits with the
other third-party imports at the top of the file (near React and other external
libs) to match the import grouping used in AppRouter.tsx; update the import
order but do not change the symbol name (useAtomValue) or any references inside
the UserDashboard component.

Comment on lines +333 to +335
<TabContent
tabId="facilities-panel"
tabItems={facilities}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent facility ordering between search list and card grid.

The search dropdown uses sortedFacilities (prioritizing recent facility first), but the TabContent card grid renders facilities in original order. This creates inconsistent UX where the "last visited" facility appears first in search but not in the grid view.

Consider using sortedFacilities for the TabContent as well for consistency:

🔧 Suggested fix
               <TabContent
                 tabId="facilities-panel"
-                tabItems={facilities}
+                tabItems={sortedFacilities}
                 description={t("dashboard_tab_facilities")}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<TabContent
tabId="facilities-panel"
tabItems={facilities}
<TabContent
tabId="facilities-panel"
tabItems={sortedFacilities}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/pages/UserDashboard.tsx` around lines 333 - 335, The TabContent call is
using the unsorted facilities list (tabItems={facilities}) while the search
dropdown uses sortedFacilities, causing inconsistent ordering; update the
TabContent invocation in UserDashboard (the component rendering TabContent) to
pass sortedFacilities (or the same sorted array you compute for the search
dropdown) as tabItems so the card grid and search list use the same ordering,
ensuring sortedFacilities is defined/available in that scope and remove or
replace any other usages of facilities for display to avoid divergent orders.

Comment on lines +33 to +34
import { useSetAtom } from "jotai";
import { useEffect } from "react";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Import ordering does not follow project conventions.

Per coding guidelines, 3rd-party imports (react, jotai) should appear at the top of the file, before library and component imports. Currently useSetAtom from jotai and useEffect from react are placed at the end.

♻️ Suggested import reordering

Move these imports to the top with other 3rd-party imports:

+import { useSetAtom } from "jotai";
+import { useEffect } from "react";
 import careConfig from "@careConfig";
 import { usePath, useRedirect, useRoutes } from "raviger";
 ...
-import { useSetAtom } from "jotai";
-import { useEffect } from "react";

As per coding guidelines: "Order imports: 3rd-party → library → CAREUI → UI → components → hooks → utils → relative".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Routers/AppRouter.tsx` around lines 33 - 34, Reorder the imports in
AppRouter.tsx so third-party module imports come first: move useEffect (from
"react") and useSetAtom (from "jotai") up into the top import group with other
3rd-party imports to follow the project's convention ("3rd-party → library →
CAREUI → UI → components → hooks → utils → relative"); update the import block
so useEffect and useSetAtom are imported alongside other external packages and
keep component/library imports below them.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 262
✅ Passed 261
❌ Failed 1
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #7825

@pranavrutagi-egov pranavrutagi-egov changed the title Enhancement #16220: Facility search feature for User Dashboard Enhancement: Facility search feature for User Dashboard Apr 1, 2026
Comment on lines +69 to +70
const [facilitySearchOpen, setFacilitySearchOpen] = useState(false);
const recentFacilityId = useAtomValue(recentFacilityAtom);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was not part of the scope 🤔
Why do we need it? What is the user story here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The atom persists the last visited facility, and updates when user navigates to some facility related route, thus marking it as last visited

Comment on lines +112 to +118
const sortedFacilities = useMemo(() => {
if (!recentFacilityId) return facilities;
return [
...facilities.filter((f) => f.id === recentFacilityId),
...facilities.filter((f) => f.id !== recentFacilityId),
];
}, [facilities, recentFacilityId]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a fan of the listing order chainging after each visit.

Copy link
Copy Markdown
Contributor Author

@pranavrutagi-egov pranavrutagi-egov Apr 2, 2026

Choose a reason for hiding this comment

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

The shared UI design had "last visited facility" on top, and I had also mentioned my approach in the issue. Please let me know if this is not needed, I will remove it.

</Button>
);

const facilitySearchCommand = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we even need a command search 🤔
The server is returning all facilites, why can't we just filter on that list 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @bodhish, the data for facilities is not being fetched from server. The data is fetched only once from user.facilities || []; (line 67) and used in the search.

@parvathyns-creator
Copy link
Copy Markdown

@nihal467 this looks fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a Search for the User Home with Facility Selector

4 participants