Skip to content

[ENG-559] feat: add pagination for user depts#16456

Open
Jacobjeevan wants to merge 2 commits into
developfrom
ENG-559-dept-pagination
Open

[ENG-559] feat: add pagination for user depts#16456
Jacobjeevan wants to merge 2 commits into
developfrom
ENG-559-dept-pagination

Conversation

@Jacobjeevan

@Jacobjeevan Jacobjeevan commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

  • ENG-559
  • Added pagination support for user departments
  • Added search for user departments
  • Ensured role is initiated in Edit Facility User Role Sheet (check screenshot)
image

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

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

Release Notes

  • New Features

    • Added department search and pagination with debounced results and improved query handling.
    • Enhanced role assignment by pre-populating the role selector with the user’s current role.
  • Bug Fixes

    • Improved loading behavior with skeleton/visual feedback during data fetching.
  • UX Improvements

    • Refined empty states to distinguish between “no departments found” (with search) and “no departments assigned” (without search).

@Jacobjeevan Jacobjeevan requested review from a team and Copilot June 16, 2026 07:09
@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit dbf6e2e
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/6a30fbe654363b000821c1e0
😎 Deploy Preview https://deploy-preview-16456.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds search and pagination to the user departments tab and pre-populates the role selector with the user's current role when the edit sheet opens.

  • UserDepartmentsTab now uses useFilters (limit 15, cache disabled) for URL-based pagination and a debounced name search; updateQuery automatically resets to page 1 on each search keystroke, and query.debounced prevents excessive API calls while typing.
  • The empty state now distinguishes between "no departments assigned" and "no search results found", and both search_departments_placeholder / no_departments_found i18n keys are present in the locale files.
  • EditFacilityUserRoleSheet initialises selectedRole with a shallow copy of userRole.role, so the role selector is pre-populated on first open; the existing guard (selectedRole.id === userRole.role.id) keeps the "Update Role" button disabled until the user picks a different role.

Confidence Score: 5/5

Safe to merge — changes are additive (pagination + search) and the existing role-update/remove flows are unaffected.

Both changed files make straightforward, well-scoped additions. The pagination implementation correctly resets to page 1 on search (verified in useFilters source), query invalidation uses prefix keys that still match the expanded query key, and the new i18n keys are present in all locale files.

No files require special attention.

Important Files Changed

Filename Overview
src/components/Users/UserDepartmentsTab.tsx Adds search and pagination for user departments using useFilters; updateQuery correctly resets page to 1 on search; debounced query prevents excessive API calls; conditional rendering of loading/empty/results states is correct
src/pages/Facility/settings/organizations/components/EditFacilityUserRoleSheet.tsx Pre-populates selectedRole with current userRole.role on mount; query invalidations use prefix keys that continue to work with the expanded query key in UserDepartmentsTab

Reviews (2): Last reviewed commit: "chore: add aria label" | Re-trigger Greptile

Comment on lines +43 to +45
const [selectedRole, setSelectedRole] = useState<RoleBase>({
...userRole.role,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Stale selection persists across sheet open/close cycles

useState initializes selectedRole only once when the component mounts. Because this component lives permanently in the DOM inside each rendered DepartmentCard, the selectedRole state is never reset between opens. If a user selects a different role, cancels without saving, then reopens the sheet, they will see the previously-chosen (but unsaved) role pre-selected — which is misleading and would cause an unintended role change if they then click "Update Role". Add a useEffect that resets to userRole.role whenever open transitions to true.

Comment thread src/components/Users/UserDepartmentsTab.tsx
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 70b26b75-5fee-44f2-9588-1d9587074607

📥 Commits

Reviewing files that changed from the base of the PR and between 4dafafe and dbf6e2e.

📒 Files selected for processing (1)
  • src/components/Users/UserDepartmentsTab.tsx

Walkthrough

UserDepartmentsTab adds useFilters-based search and pagination with a debounced API query, skeleton loading, and distinct empty states. EditFacilityUserRoleSheet initializes selectedRole from the existing userRole.role instead of leaving it undefined.

Changes

User Management UX

Layer / File(s) Summary
UserDepartmentsTab: search, pagination, and loading state
src/components/Users/UserDepartmentsTab.tsx
Imports useFilters and Input; hooks up qParams, updateQuery, Pagination, and resultsPerPage via useFilters; rewires useQuery to query.debounced with name/limit/offset params; renders a search Input, CardGridSkeleton while loading, separate empty-state messages for active-search vs. no-assignment, the department grid, and a Pagination control from departmentsData?.count.
EditFacilityUserRoleSheet: seed initial role selection
src/pages/Facility/settings/organizations/components/EditFacilityUserRoleSheet.tsx
selectedRole state is now seeded with {...userRole.role} so RoleSelect and the update button's disabled state reflect the current role immediately on mount.
🚥 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
Title check ✅ Passed The title accurately describes the main change (adding pagination for user departments) and is concise and clear.
Description check ✅ Passed The description covers the main changes, includes the issue reference, tags reviewers, and has a merge checklist. However, it lacks proper issue number linking and several critical checklist items remain incomplete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-559-dept-pagination

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

Copilot AI left a comment

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.

Pull request overview

Adds pagination and search support to the “User Departments” view, and ensures the “Edit Facility User Role” sheet opens with the current role pre-selected—improving usability when users belong to many departments.

Changes:

  • Added useFilters-driven pagination (limit/offset) for user departments listing.
  • Added department name search input with debounced fetching and updated empty-state messaging for “no results”.
  • Initialized role selection state in the role-edit sheet using the existing userRole.role.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pages/Facility/settings/organizations/components/EditFacilityUserRoleSheet.tsx Pre-populates selected role state from the user’s current role when the component mounts.
src/components/Users/UserDepartmentsTab.tsx Adds search + limit/offset pagination to the departments list and renders pagination controls + search-aware empty state.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 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 `@src/components/Users/UserDepartmentsTab.tsx`:
- Around line 157-162: The Input component in UserDepartmentsTab.tsx (around
line 157) currently relies only on a placeholder for accessibility, which is not
reliable for screen-reader users. Add an `aria-label` attribute to the Input
component with an appropriate accessible label (such as "Search departments") to
provide a consistent accessible name that screen readers can reliably announce,
ensuring compliance with accessibility guidelines.
- Around line 134-139: The offset calculation for pagination in the queryParams
object uses an unsafe expression that can produce invalid values when
qParams.page contains zero, negative numbers, or non-numeric strings from the
URL query state. Instead of directly using ((qParams.page || 1) - 1), validate
and normalize the page parameter first by parsing it as an integer and ensuring
it is at least 1, then use the normalized value in the offset calculation.
Reference the validation patterns established in src/hooks/useFilters.tsx to
align with the URL-derived state handling contract.
🪄 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: a4b08e8f-7439-4c97-9ab2-9c005d227c43

📥 Commits

Reviewing files that changed from the base of the PR and between 5466816 and 4dafafe.

📒 Files selected for processing (2)
  • src/components/Users/UserDepartmentsTab.tsx
  • src/pages/Facility/settings/organizations/components/EditFacilityUserRoleSheet.tsx

Comment thread src/components/Users/UserDepartmentsTab.tsx
Comment thread src/components/Users/UserDepartmentsTab.tsx
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

🎭 Playwright Test Results

Status: ❌ Failed
Test Shards: 3

Metric Count
Total Tests 321
✅ Passed 315
❌ Failed 3
⏭️ Skipped 3

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

Run: #9550

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying care-preview with  Cloudflare Pages  Cloudflare Pages

Latest commit: dbf6e2e
Status: ✅  Deploy successful!
Preview URL: https://68edea89.care-preview-a7w.pages.dev
Branch Preview URL: https://eng-559-dept-pagination.care-preview-a7w.pages.dev

View logs

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.

4 participants