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 Organization View Pagination and Search #11074

Merged
merged 1 commit into from
Mar 6, 2025

Conversation

rithviknishad
Copy link
Member

@rithviknishad rithviknishad commented Mar 6, 2025

Proposed Changes

  • Fixes org. view not resetting page when searched or selected a sub-org.

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA in Mobile Devices
  • Completion of QA in Desktop Devices

Summary by CodeRabbit

  • New Features
    • Improved pagination behavior: the page now resets to the beginning when search criteria change.
    • Streamlined pagination controls: they display only when there are more results than the set page limit, ensuring a cleaner and more consistent user experience.

@rithviknishad rithviknishad requested a review from a team as a code owner March 6, 2025 09:12
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

The changes refactor the pagination logic in the organization view. A useEffect hook now resets the page state to 1 when the id or searchQuery changes. A centralized constant, RESULTS_PER_PAGE_LIMIT, replaces a previously hardcoded value (12) for pagination settings, affecting both the offset in queries and the conditional rendering logic for the pagination component. The query key for useQuery is updated accordingly.

Changes

File(s) Change Summary
src/pages/Organization/OrganizationView.tsx Added a useEffect hook to reset the page state on id or searchQuery changes; replaced hardcoded pagination limit with RESULTS_PER_PAGE_LIMIT; updated query key and conditional rendering logic for pagination.
src/common/constants Introduced the constant RESULTS_PER_PAGE_LIMIT to centralize pagination settings.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant O as OrganizationView
    participant Q as useQuery
    U->>O: Modify search query or organization id
    O->>O: Trigger useEffect → Reset page state to 1
    O->>Q: Invoke query with RESULTS_PER_PAGE_LIMIT
    Q-->>O: Return paginated data
Loading

Possibly related PRs

Suggested labels

tested, P1, changes required

Suggested reviewers

  • Jacobjeevan

Poem

I’m a rabbit tapping keys with glee,
Hopping through code changes, wild and free.
A constant now leads our pagination way,
Resetting pages in a bright new day!
With carrots and code, we celebrate in cheer 🥕✨.


📜 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 9cfed2f and 06fb84b.

📒 Files selected for processing (1)
  • src/pages/Organization/OrganizationView.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
🔇 Additional comments (7)
src/pages/Organization/OrganizationView.tsx (7)

3-3: Added required import for new pagination reset logic.

The addition of useEffect to the imports is necessary for implementing the pagination reset functionality when search query or organization ID changes.


16-16: Good practice: Using a centralized constant for pagination limit.

Importing the RESULTS_PER_PAGE_LIMIT constant improves code maintainability by centralizing the pagination configuration. This makes future changes to the pagination limit easier as it only needs to be updated in one place.


37-37: Appropriately updated query key dependencies.

Including searchQuery in the query key ensures that the data is properly refreshed when the search term changes.


41-43: Replaced hardcoded pagination values with constant.

Using the RESULTS_PER_PAGE_LIMIT constant instead of hardcoded values for offset calculation and limit improves maintainability and consistency.


48-50: Key fix: Added pagination reset on search or organization change.

This useEffect hook implements the core functionality needed to address the PR objective - it resets the pagination to page 1 whenever the search query or organization ID changes.

Note: There's also a setPage(1) call in the search input onChange handler on line 75. While this creates some redundancy for the search case, it ensures pagination is reset in all scenarios.


142-142: Updated pagination rendering condition with constant.

Replaced hardcoded value with RESULTS_PER_PAGE_LIMIT for the conditional rendering of the pagination component, maintaining consistency with the rest of the changes.


147-147: Updated pagination component prop with constant.

Using RESULTS_PER_PAGE_LIMIT for the defaultPerPage prop ensures the pagination component is configured consistently with the API request.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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 Mar 6, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 06fb84b
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67c966fc7a23dd0008eb8e8d
😎 Deploy Preview https://deploy-preview-11074.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.

Copy link

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 06fb84b
Status: ✅  Deploy successful!
Preview URL: https://669d4bf2.care-fe.pages.dev
Branch Preview URL: https://rithviknishad-fix-org-reset.care-fe.pages.dev

View logs

@rithviknishad rithviknishad added the P1 breaking issue or vital feature label Mar 6, 2025
@bodhish bodhish merged commit ea95f1a into develop Mar 6, 2025
19 of 26 checks passed
@bodhish bodhish deleted the rithviknishad/fix/org-reset branch March 6, 2025 09:16
Copy link

github-actions bot commented Mar 6, 2025

@rithviknishad Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 breaking issue or vital feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants