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

Fixed scroll issue in Shifting and Resource #9475

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

Conversation

Jeffrin2005
Copy link

@Jeffrin2005 Jeffrin2005 commented Dec 17, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

final_scroll.mp4

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

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced scrolling experience in the Kanban board with horizontal scrolling functionality.
    • Improved error handling during data fetching for better reliability.
  • Bug Fixes

    • Adjusted scrolling behavior to allow horizontal scrolling while hiding the scrollbar.
  • Refactor

    • Updated the logic for fetching next pages and handling scroll events for improved performance and user experience.
    • Simplified state management for pagination using the latest data fetching techniques.

@Jeffrin2005 Jeffrin2005 requested a review from a team as a code owner December 17, 2024 10:33
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request modifies the Kanban board component in src/components/Kanban/Board.tsx, enhancing the scrolling behavior and error handling. The changes replace the overflow-scroll class with overflow-x-auto scrollbar-hide for improved horizontal scrolling. The state management for pagination is refactored to use the useInfiniteQuery hook, simplifying data fetching. The onBoardReachEnd function is removed, and its functionality is now handled by an onScroll event on the section's div, allowing for more responsive data fetching.

Changes

File Change Summary
src/components/Kanban/Board.tsx - Replaced overflow-scroll with overflow-x-auto scrollbar-hide
- Refactored pagination using useInfiniteQuery
- Removed onBoardReachEnd and added onScroll event handler
package.json - Updated @tanstack/react-query from ^5.62.3 to ^5.62.8
- Added new dependency react-query with version ^3.39.3

Assessment against linked issues

Objective Addressed Explanation
Separate scroll for each section [#7487] It is unclear if the changes fully address the requirement for independent scrolling for each section as the modifications focus on scrolling behavior but do not explicitly separate the scroll for each field.
Resolve scrolling inconsistencies The objective of resolving scrolling inconsistencies across different fields is not directly addressed by the changes made.

Possibly related PRs

  • Update dependencies #9049: This PR updates the @tanstack/react-query dependency, which is directly related to the changes made in the main PR that refactors pagination logic using the useInfiniteQuery hook from the same library.

Suggested labels

tested, reviewed

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 In the Kanban land, we hop and scroll,
Each section dances, a rhythmic stroll!
Errors caught in a gentle embrace,
Smooth transitions, a joyful space!
Hooray for changes, let data flow free! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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 Dec 17, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 9cfb224
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6765408a33e7df0008faa22a
😎 Deploy Preview https://deploy-preview-9475--care-ohc.netlify.app
📱 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.

@Jeffrin2005
Copy link
Author

@rithviknishad I have made the changes. Please Let me know if any further modification needs.

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

🧹 Nitpick comments (2)
src/components/Kanban/Board.tsx (2)

18-19: Remove unnecessary comment

The comment "Adjust the path if necessary" appears to be a leftover development note and doesn't provide any value. Consider removing it.


161-161: Extract magic number in height calculation

The height calculation h-[calc(100vh-250px)] uses a magic number. Consider extracting this value into a constant or CSS variable to improve maintainability and document its purpose.

+// Add at the top of the file
+const KANBAN_SECTION_HEIGHT_OFFSET = 250;

-<ScrollArea className="h-[calc(100vh-250px)]">
+<ScrollArea className={`h-[calc(100vh-${KANBAN_SECTION_HEIGHT_OFFSET}px)]`}>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10bfd6c and ee8f54e.

📒 Files selected for processing (1)
  • src/components/Kanban/Board.tsx (5 hunks)
🔇 Additional comments (3)
src/components/Kanban/Board.tsx (3)

64-64: LGTM: Improved scroll behavior

The updated overflow classes (overflow-x-auto overflow-y-hidden) correctly implement horizontal scrolling while preventing vertical overflow, which is appropriate for a Kanban board layout.


Line range hint 161-186: LGTM: Well-implemented ScrollArea with proper loading states

The ScrollArea implementation effectively solves the scrolling issue while maintaining:

  • Proper loading states with skeleton UI
  • Clear empty state message with i18n support
  • Correct integration with drag and drop functionality

Line range hint 161-186: Verify scroll behavior in different scenarios

While the implementation looks correct, please verify the following scenarios:

  1. Scrolling behavior with varying numbers of items
  2. Interaction between board-level and section-level scrolling
  3. Drag and drop functionality across sections with scroll
✅ Verification successful

Scroll implementation verified and properly integrated

The implementation has been verified through code analysis and shows:

  1. Proper integration of ScrollArea with drag-and-drop functionality using @hello-pangea/dnd
  2. Correct scroll event handling for infinite loading (onBoardReachEnd)
  3. Smooth horizontal scrolling controls with left/right buttons
  4. Consistent implementation across different board types (Resource, Shifting, Notice boards)

The scroll behavior is well-implemented with:

  • Vertical scrolling within sections using ScrollArea component
  • Horizontal scrolling at board level with smooth behavior
  • Proper cleanup of scroll event listeners
  • Scroll-based pagination trigger at 75% scroll threshold
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing scroll-related issues or PRs
gh issue list --search "scroll kanban" --state all
gh pr list --search "scroll kanban" --state all

# Look for other ScrollArea implementations for consistency
rg -l "ScrollArea" --type tsx

Length of output: 1122


Script:

#!/bin/bash
# Search for ScrollArea usage in all TypeScript and TypeScript React files
rg -l "ScrollArea" --type ts --type tsx

# Look for any scroll-related configurations or props in the Kanban components
rg -C 5 "scroll" src/components/Kanban/

# Check for any drag-and-drop related code near ScrollArea usage
rg -C 5 "Draggable|DragDropContext" src/components/Kanban/

# Look for other board implementations that might affect scrolling
fd "Board\.(tsx|ts)$" src/

Length of output: 6745

src/components/Kanban/Board.tsx Outdated Show resolved Hide resolved
@AdityaJ2305
Copy link
Contributor

AdityaJ2305 commented Dec 17, 2024

Hey @Jeffrin2005, it’s not fetching beyond the default limit on scroll anymore, which it was doing previously.

cc: @rithviknishad

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 17, 2024
@rithviknishad rithviknishad added changes required and removed question Further information is requested needs-triage labels Dec 17, 2024
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

fix the issue mentioned before requesting review

@Jeffrin2005
Copy link
Author

fix the issue mentioned before requesting review

@rithviknishad I have committed the changes, but due to some errors, the commits are not showing up. I will close this PR and raise a new one with the updated changes.

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 18, 2024
@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Dec 18, 2024

fix the issue mentioned before requesting review

@rithviknishad I have committed the changes, but due to some errors, the commits are not showing up. I will close this PR and raise a new one with the updated changes.

Try to salvage this rather than opening a new PR - since you haven't force pushed yet, you should be able to use git revert to rollback recent changes and then merge/and push once more.

@Jacobjeevan Jacobjeevan removed question Further information is requested needs-triage labels Dec 18, 2024
@Jeffrin2005 Jeffrin2005 deleted the newbranch branch December 18, 2024 10:58
@Jeffrin2005
Copy link
Author

@Jacobjeevan I've encountered some errors while trying to update my PR. Unfortunately, it led to the PR being closed unexpectedly from my Git. While trying to revert and delete the commit, it caused the PR to close. Sorry for stretching the time. I'll close it and raise a new one with the updated changes.

@Jeffrin2005
Copy link
Author

@rithviknishad @Jacobjeevan, can we reopen this PR?

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 19, 2024
@rithviknishad
Copy link
Member

rithviknishad commented Dec 19, 2024

contributors do have permissions to re-open PRs. It maybe disabled if the branch is deleted.

image

@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Dec 19, 2024

contributors do have permissions to re-open PRs. It maybe disabled if the branch is deleted.

image

Since I've seen a few contributors have this issue where branch is being deleted - not sure what they are doing there 😅 - want to check if this works.

@Jeffrin2005 Create a new branch with the same name and SHA of the most recent commit (e1c61d65b8ad3dd5b895f105286109921858d4e0 in your case) and push to it. Let's see if it allows you to reopen the PR.

@Jeffrin2005 Jeffrin2005 restored the newbranch branch December 19, 2024 06:08
@Jeffrin2005 Jeffrin2005 reopened this Dec 19, 2024
@Jeffrin2005
Copy link
Author

Jeffrin2005 commented Dec 19, 2024

@rithviknishad @Jacobjeevan, as per the issue raised by @AdityaJ2305, I've updated board.tsx. Now, all sets of cards are being fetched. I've also updated the video. Any errors in this?

Comment on lines 105 to 118
try {
const res = await request(options.route, {
...options.options,
query: {
...options.options?.query,
offset: offsetToUse,
limit: defaultLimit,
},
});
const newPages = refresh ? [] : [...pages];
const page = Math.floor(offsetToUse / defaultLimit);
if (res.error) {
console.error("Error fetching data:", res.error);
return;
Copy link
Member

@rithviknishad rithviknishad Dec 19, 2024

Choose a reason for hiding this comment

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

let's use useInfiniteQuery

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: 1

🧹 Nitpick comments (2)
src/components/Kanban/Board.tsx (2)

95-115: Enhance error handling in fetchPage

While the error handling is implemented, consider these improvements:

  1. Use specific error messages that include the actual error details
  2. Consider showing a user-friendly error notification instead of just logging to console
  3. The silent failure with empty results might hide issues from users
 const fetchPage = async ({ pageParam = 0 }) => {
   const options = section.fetchOptions(section.id);
   try {
     const response = await request(options.route, {
       ...options.options,
       query: {
         ...options.options?.query,
         offset: pageParam,
         limit: defaultLimit,
       },
     });

     if (response.error) {
-      throw new Error("Error fetching data");
+      throw new Error(`Error fetching data: ${response.error}`);
     }

     return response.data as QueryResponse<T>;
   } catch (error) {
-    console.error("Error fetching section data:", error);
+    const errorMessage = error instanceof Error ? error.message : "Unknown error";
+    console.error("Error fetching section data:", errorMessage);
+    // Consider using your notification system here
+    // showErrorNotification(`Failed to load items: ${errorMessage}`);
     return { results: [], next: null, count: 0 };
   }
 };

162-172: Consider debouncing the scroll event handler

The scroll event can fire frequently during scrolling. Consider debouncing the handler to prevent excessive calls to fetchNextPage.

+import { debounce } from "lodash";
+
 export function KanbanSection<T extends { id: string }>({
   // ... existing code ...
 }) {
+  const debouncedFetchNext = useRef(
+    debounce((hasNext: boolean, isFetching: boolean) => {
+      if (hasNext && !isFetching) {
+        fetchNextPage();
+      }
+    }, 150)
+  ).current;
+
   // ... existing code ...
   
-            onScroll={(e) => {
-              const target = e.target as HTMLDivElement;
-              if (
-                target.scrollTop + target.clientHeight >=
-                target.scrollHeight - 100
-              ) {
-                if (hasNextPage && !isFetchingNextPage) {
-                  fetchNextPage();
-                }
-              }
-            }}
+            onScroll={e => {
+              const target = e.target as HTMLDivElement;
+              if (
+                target.scrollTop + target.clientHeight >=
+                target.scrollHeight - 100
+              ) {
+                debouncedFetchNext(hasNextPage, isFetchingNextPage);
+              }
+            }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 78efac7 and 9cfb224.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • src/components/Kanban/Board.tsx (3 hunks)
🔇 Additional comments (1)
src/components/Kanban/Board.tsx (1)

61-61: LGTM! Improved scrolling behavior

The change from overflow-scroll to overflow-x-auto scrollbar-hide improves the scrolling behavior while maintaining a clean UI by hiding the scrollbar.

@@ -98,6 +98,7 @@
"react-i18next": "^15.1.3",
"react-infinite-scroll-component": "^6.1.0",
"react-pdf": "^9.1.1",
"react-query": "^3.39.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove redundant react-query dependency

The react-query package is the older version of @tanstack/react-query. Since you're already using @tanstack/react-query (the newer, recommended version), including both packages can lead to conflicts and confusion. Please remove the react-query dependency.

-    "react-query": "^3.39.3",

@Jeffrin2005
Copy link
Author

@rithviknishad Hi, Used useInfiniteQuery, but there is a slight issue while fetching. A slight delay is occurring, as you can see in this clip.

fix.mp4

@rithviknishad
Copy link
Member

rithviknishad commented Dec 20, 2024

That's fine, it's just time spent on fetching the data right. And we are showing the loading state. Expected.

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

lgtm, some minor things

Comment on lines +97 to +105
try {
const response = await request(options.route, {
...options.options,
query: {
...options.options?.query,
offset: pageParam,
limit: defaultLimit,
},
});
Copy link
Member

Choose a reason for hiding this comment

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

can we switch to using callApi or query instead? This will do the handling of errors for you and appropriately show notifications if needed using the queryClient declared globally.

Copy link
Member

Choose a reason for hiding this comment

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

can we not change the packages and package-lock file in this PR?

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.

Infinite Scrolling on Resource Page Scroll issue in shifting in facilities.
4 participants