Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pagination): auto-reset page on organization change #10881

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

MethodManav
Copy link

@MethodManav MethodManav commented Feb 28, 2025

Proposed Changes

Screen.Recording.2025-02-28.at.7.35.19.PM.mov

@ohcnetwork/care-fe-code-reviewers

Summary by CodeRabbit

  • New Features

    • Enhanced user interaction with pagination by introducing a page parameter in the URL structure for organization-related views.
    • Updated navigation paths to reflect the current page in the OrganizationLayout component.
    • Simplified search functionality without resetting the page state.
  • Bug Fixes

    • Corrected URL links in the UserDashboard to include the default page number for organization links.

@MethodManav MethodManav requested a review from a team as a code owner February 28, 2025 14:18
Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Walkthrough

The changes introduce a page prop to various components related to organization views, enhancing their functionality for pagination. The OrganizationView component now directly uses the page prop instead of managing its state locally. Routes have been updated to include a :page parameter, allowing navigation to specific pages. Each organization-related component, including OrganizationFacilities, OrganizationPatients, and OrganizationUsers, has been modified to accept and utilize the page prop, ensuring consistent pagination across the application.

Changes

File Summary
src/pages/Organization/OrganizationView.tsx Added page prop to Props interface and updated its usage throughout the component.
src/Routers/routes/OrganizationRoutes.tsx Updated route definitions to include :page parameter for organization-related routes.
src/pages/Organization/OrganizationFacilities.tsx Added page prop to Props interface for pagination functionality.
src/pages/Organization/OrganizationPatients.tsx Added page prop to Props interface to manage pagination state.
src/pages/Organization/OrganizationUsers.tsx Added page prop to Props interface for pagination management.
src/pages/Organization/components/OrganizationLayout.tsx Updated Props interface to include page and modified navigation paths accordingly.
src/pages/UserDashboard.tsx Modified organization links to include /1 in the URL for pagination.

Possibly related PRs

Suggested labels

tested, needs review, P1

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

Hopping through code, what a sight,
Pages now dance, oh what delight!
With each new route, a page to explore,
Navigation's smooth, we leap and soar!
In the burrow of code, we celebrate,
Pagination's here, oh isn't it great!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Feb 28, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 4bde3e5
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67cd2fc08175250008c38084
😎 Deploy Preview https://deploy-preview-10881.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@khavinshankar khavinshankar added the reviewed reviewed by a core member label Mar 4, 2025
@nihal467
Copy link
Member

nihal467 commented Mar 4, 2025

image

  • Add pagination to the query parameters so that when a user clicks the back button, the pagination is preserved.

@nihal467 nihal467 added test failed and removed needs testing reviewed reviewed by a core member labels Mar 4, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Mar 6, 2025
Copy link

github-actions bot commented Mar 6, 2025

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @MethodManav

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

@Jacobjeevan
Copy link
Contributor

@MethodManav Any updates?

@MethodManav
Copy link
Author

working on it and will try to finish today, @Jacobjeevan

Copy link
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: 0

🔭 Outside diff range comments (1)
src/pages/Organization/components/OrganizationLayout.tsx (1)

119-125: 💡 Verification agent

🧩 Analysis chain

Potential issue with path matching logic.

Now that the paths include dynamic page numbers, the strict equality check path === item.path might not work as expected for highlighting the active menu item.

Consider updating this logic to use a more flexible comparison, such as checking if the current path starts with or includes a base path without the page number.


🏁 Script executed:

#!/bin/bash
# Check if this logic is implemented elsewhere with a more flexible approach
rg "path\s*===\s*item\.path" --type ts

Length of output: 136


Action Required: Revise Path Matching for Dynamic Segments

The current strict equality check (path === item.path) at src/pages/Organization/components/OrganizationLayout.tsx (lines 119-125) will likely fail to correctly highlight the active menu item when dynamic page numbers are part of the URL. Consider updating the logic—for example, by using a check like path.startsWith(item.path) or a suitable regex—to account for dynamic segments.

  • Location: src/pages/Organization/components/OrganizationLayout.tsx, lines 119-125
  • Suggestion: Replace path === item.path with a more flexible comparison that correctly handles dynamic paths.
🧹 Nitpick comments (1)
src/Routers/routes/OrganizationRoutes.tsx (1)

1-68: Consider adding more robust page parameter validation.

The current implementation converts the page parameter using Number(page || 1), which handles null/undefined cases but doesn't validate against negative or non-integer values.

Consider adding validation to ensure the page is a positive integer, possibly with a utility function for consistency.

- page={Number(page || 1)}
+ page={Math.max(1, Math.floor(Number(page || 1)))}

Or create a utility function:

function validatePageNumber(page: string | undefined): number {
  const pageNum = Number(page || 1);
  return Math.max(1, Math.floor(pageNum));
}

Then use it consistently:

- page={Number(page || 1)}
+ page={validatePageNumber(page)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57ed304 and 4bde3e5.

📒 Files selected for processing (7)
  • src/Routers/routes/OrganizationRoutes.tsx (1 hunks)
  • src/pages/Organization/OrganizationFacilities.tsx (2 hunks)
  • src/pages/Organization/OrganizationPatients.tsx (2 hunks)
  • src/pages/Organization/OrganizationUsers.tsx (2 hunks)
  • src/pages/Organization/OrganizationView.tsx (6 hunks)
  • src/pages/Organization/components/OrganizationLayout.tsx (3 hunks)
  • src/pages/UserDashboard.tsx (1 hunks)
🔇 Additional comments (24)
src/pages/UserDashboard.tsx (1)

129-129: Good implementation of default pagination.

The change to add /1 to the organization link correctly implements the default pagination page, ensuring that when a user clicks on an organization from the dashboard, they'll always start at page 1. This addresses the core issue of resetting pagination on organization change.

src/pages/Organization/OrganizationFacilities.tsx (3)

28-28: LGTM: Added pagination prop to interface.

Adding the page property to the Props interface allows the component to receive pagination information.


34-34: LGTM: Updated function parameters.

The function signature now correctly destructures the page prop.


61-65: LGTM: Page prop passed to OrganizationLayout.

The page parameter is now correctly passed to the OrganizationLayout component, allowing the layout to handle pagination appropriately.

src/pages/Organization/OrganizationPatients.tsx (3)

29-29: LGTM: Added pagination prop to interface.

Adding the page property to the Props interface allows the component to receive pagination information.


32-36: LGTM: Updated function parameters.

The function signature now correctly destructures the page prop.


103-103: LGTM: Page prop passed to OrganizationLayout.

The page parameter is now correctly passed to the OrganizationLayout component, which handles the pagination context.

src/pages/Organization/OrganizationUsers.tsx (3)

32-32: LGTM: Added pagination prop to interface.

Adding the page property to the Props interface allows the component to receive pagination information.


35-39: LGTM: Updated function parameters.

The function signature now correctly destructures the page prop.


110-114: LGTM: Page prop passed to OrganizationLayout.

The page parameter is now correctly passed to the OrganizationLayout component, ensuring consistent pagination behavior.

src/pages/Organization/OrganizationView.tsx (8)

2-2: Nice update to include navigate from raviger!

The import change is appropriate for implementing navigation to pages with updated URL patterns.


26-26: LGTM! Good addition of the page prop.

Adding the page prop to the Props interface correctly implements the requirement to handle pagination through the component props.


29-33: LGTM! Proper component signature update.

The component signature has been correctly updated to include the page prop, which aligns with the PR objective of handling pagination through props.


52-53: Simplifying the baseUrl logic.

This change removes the conditional logic that was previously checking navOrganizationId but always resulting in the same value.


56-60: LGTM! Correctly passing page prop to OrganizationLayout.

The OrganizationLayout component now properly receives the page prop, ensuring consistent pagination behavior across components.


115-115: LGTM! Updated link correctly includes page parameter.

The view details link has been properly updated to include the page parameter, maintaining consistent URL structure.


147-147: Great implementation of pagination navigation!

Using the navigate function to update the URL with the new page number is the correct approach for maintaining state in the URL, which addresses the core requirement of this PR.


75-77:

❓ Verification inconclusive

Search no longer resets pagination - is this intentional?

The comment indicates the search should reset to the first page, but the implementation no longer does this. Consider whether this behavior change is intended.


🏁 Script executed:

#!/bin/bash
# Check if there are other places where search is resetting pagination
rg -B 2 -A 2 "setSearchQuery.*page.*1" --type ts

Length of output: 50


I'll run a follow‐up verification to check if any code in the file resets the pagination (e.g. by calling something like setPage(1)) when the search query changes. Please execute the following shell script:


🏁 Script executed:

#!/bin/bash
rg -n "setPage\(1\)" src/pages/Organization/OrganizationView.tsx

Length of output: 66


Attention: Confirm Pagination Reset Behavior

The code in src/pages/Organization/OrganizationView.tsx (lines 75–77) updates the search query but no longer resets the pagination, even though the inline comment implies it should. There’s no evidence of a call like setPage(1) anywhere in this file.

Please verify whether the removal of the pagination reset is intentional. If resetting the pagination on a search change is still desired, consider adding the necessary logic (e.g., invoking setPage(1)) or updating the comment to accurately reflect the current behavior.

src/pages/Organization/components/OrganizationLayout.tsx (3)

26-26: LGTM! Good addition of the page prop.

Adding the page prop to the Props interface ensures the layout component can properly handle pagination.


40-40: LGTM! Component signature updated correctly.

The page prop is now properly included in the component parameters.


76-76: LGTM! Updated navigation paths to include page parameter.

All navigation items have been updated to include the page parameter, ensuring consistent URL structure throughout the application.

Also applies to: 82-82, 88-88, 94-94

src/Routers/routes/OrganizationRoutes.tsx (3)

10-12: LGTM! Routes properly updated to include page parameter.

The route definition has been correctly updated to include the page parameter. The fallback logic Number(page || 1) ensures a valid page number is always provided.


13-21: LGTM! All organization routes properly updated.

All organization routes have been correctly updated to include the page parameter, maintaining consistency across the application.


22-32: LGTM! Child organization routes correctly updated.

The routes for child organizations have been properly updated to include the page parameter, ensuring consistent navigation throughout the application.

Also applies to: 33-43, 44-54, 55-64

@MethodManav
Copy link
Author

@Jacobjeevan and @rithviknishad, I have completed the changes. Please review the updates and let me know if they work fine 🙂

@bodhish bodhish added needs testing needs review and removed test failed merge conflict pull requests with merge conflict labels Mar 9, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Mar 9, 2025
Copy link

github-actions bot commented Mar 9, 2025

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @MethodManav

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge conflict pull requests with merge conflict needs review needs testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pagination Page Reset Issue on Organization change
6 participants