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 User Default View in Resource and Shifting #9306

Merged

Conversation

nithish1018
Copy link
Contributor

@nithish1018 nithish1018 commented Dec 5, 2024

Proposed Changes

Screen Recording:

fixresourceview.mp4

@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

Summary by CodeRabbit

  • New Features

    • Introduced navigation functions for switching between board and list views, enhancing user experience.
    • Default view settings are now saved in local storage for a more personalized experience.
  • Bug Fixes

    • Improved code readability and separation of concerns in navigation logic.
  • Style

    • Updated button components to a new design with primary variant and improved styling.

@nithish1018 nithish1018 requested a review from a team as a code owner December 5, 2024 12:58
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Walkthrough

The pull request introduces changes to four components: ResourceList, ShiftingBoard, ShiftingList, and ResourceBoard. It adds new functions to handle view changes and set default views in local storage when users navigate between list and board views. The onBoardViewBtnClick and onListViewBtnClick functions encapsulate the navigation logic, enhancing code readability. The button component has been updated across these files to a new Button component, with modifications to its properties for styling and functionality.

Changes

File Change Summary
src/components/Resource/ResourceList.tsx Updated button component from ButtonV2 to Button, added onBoardViewBtnClick function for board view navigation and local storage.
src/components/Shifting/ShiftingBoard.tsx Introduced onListViewBtnClick function for list view navigation and local storage. Updated button component from ButtonV2 to Button.
src/components/Shifting/ShiftingList.tsx Added onBoardViewBtnClick function for board view navigation and local storage. Updated button component from ButtonV2 to Button.
src/components/Resource/ResourceBoard.tsx Updated button component from ButtonV2 to Button, modified button properties for styling.

Assessment against linked issues

Objective Addressed Explanation
User default should change based on user latest preference (#9304)

Possibly related PRs

  • Design of List View layout in Resource Page #9096: This PR modifies the ListView component in src/components/Resource/ResourceList.tsx, which is directly related to the changes made in the main PR that also updates the ListView component in the same file.
  • Adjusted the view change button position #9172: This PR also updates the ListView component in src/components/Resource/ResourceList.tsx, focusing on the button's position, which is relevant to the modifications made in the main PR regarding the button component and its properties.

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan
  • shivankacker

Poem

In the land of code where rabbits play,
A new view was set for a brighter day.
With clicks and storage, the paths align,
Navigating smoothly, all things divine.
Hop along, dear friend, to the board or the list,
Each click a delight, none can resist! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9302534 and 7ab9adf.

📒 Files selected for processing (2)
  • src/components/Resource/ResourceBoard.tsx (2 hunks)
  • src/components/Resource/ResourceList.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Resource/ResourceList.tsx
  • src/components/Resource/ResourceBoard.tsx

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 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 5, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit a27c6cf
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67529da11727c000083bf224
😎 Deploy Preview https://deploy-preview-9306--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.

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

🧹 Outside diff range and nitpick comments (3)
src/components/Shifting/ShiftingBoard.tsx (1)

Line range hint 1-1: Consider a centralized view preference management system

The current implementation has several systemic issues across components. Consider implementing a centralized solution:

  1. Create a custom hook for view preference management
  2. Implement a context provider for sharing view state
  3. Add proper TypeScript types for view preferences
  4. Add migration logic for handling legacy preferences

Would you like me to provide a detailed implementation plan for this architectural improvement?

src/components/Resource/ResourceList.tsx (2)

Line range hint 35-36: Consider persisting view preference on navigation

The board view navigation doesn't update the stored preference, which could lead to inconsistency with the actual view state.

  const onBoardViewBtnClick = () => {
+   try {
+     localStorage.setItem("defaultResourceView", "board");
+   } catch (error) {
+     console.error("Failed to save view preference:", error);
+   }
    navigate("/resource/board", { query: qParams });
  };

26-26: Consider adding unit tests for view persistence

To ensure the view persistence feature works reliably, add unit tests covering:

  • Initial view selection
  • View switching
  • localStorage error handling
  • Navigation with stored preferences

Would you like me to help create unit tests for the view persistence functionality?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a24b9ca and 11ee192.

📒 Files selected for processing (4)
  • src/components/Resource/ResourceBoard.tsx (1 hunks)
  • src/components/Resource/ResourceList.tsx (1 hunks)
  • src/components/Shifting/ShiftingBoard.tsx (1 hunks)
  • src/components/Shifting/ShiftingList.tsx (1 hunks)
🔇 Additional comments (1)
src/components/Resource/ResourceList.tsx (1)

26-26: Verify the view persistence implementation across components

The localStorage implementation needs to be consistent across all view components to ensure proper view persistence.

✅ Verification successful

Based on the results, I can now generate the final response as we have sufficient information about the localStorage implementation across components.

View persistence implementation is consistent across components

The localStorage implementation for view preferences is consistently implemented:

  • Resource views correctly set "defaultResourceView" to "list"/"board" in both ResourceList and ResourceBoard
  • Shifting views follow the same pattern with "defaultShiftView"
  • Navigation between views is properly handled with query parameter preservation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent localStorage implementation across view components

# Check for localStorage usage in resource views
echo "Checking resource view components..."
rg -A 2 'localStorage\.setItem.*defaultResourceView' 

# Check for localStorage usage in shifting views
echo "Checking shifting view components..."
rg -A 2 'localStorage\.setItem.*defaultShiftView'

# Check for proper view preference handling in navigation
echo "Checking navigation handling..."
rg -A 5 'navigate\(.*/resource/(list|board)'

Length of output: 2427

src/components/Shifting/ShiftingList.tsx Outdated Show resolved Hide resolved
src/components/Resource/ResourceBoard.tsx Outdated Show resolved Hide resolved
src/components/Shifting/ShiftingBoard.tsx Outdated Show resolved Hide resolved
src/components/Resource/ResourceList.tsx Outdated Show resolved Hide resolved
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5dc8cac and 9302534.

📒 Files selected for processing (4)
  • src/components/Resource/ResourceBoard.tsx (2 hunks)
  • src/components/Resource/ResourceList.tsx (3 hunks)
  • src/components/Shifting/ShiftingBoard.tsx (3 hunks)
  • src/components/Shifting/ShiftingList.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/components/Shifting/ShiftingList.tsx
  • src/components/Resource/ResourceList.tsx
  • src/components/Resource/ResourceBoard.tsx
🔇 Additional comments (3)
src/components/Shifting/ShiftingBoard.tsx (3)

9-10: LGTM: Clean import of new Button component

The migration from ButtonV2 to the new Button component aligns with UI standardization.


127-130: LGTM: Clean Button implementation

The Button component implementation follows best practices:

  • Uses proper variant
  • Includes icon with label for accessibility
  • Properly integrates with translation system

79-82: Verify consistent implementation across components

Let's verify that the view preference handling is consistent across all components.

✅ Verification successful

Let me correct the file type flags and try again with a more precise search pattern.


Let me try one more time with the correct file type flags.


Based on the search results, I can now provide a final response as we have sufficient evidence:

View preference handling is consistent across components

The implementation is consistent across both Shifting and Resource components:

  • Both ShiftingBoard and ShiftingList components use "defaultShiftView"
  • Both ResourceBoard and ResourceList components use "defaultResourceView"
  • Each component correctly sets the opposite view type when switching views
  • Navigation patterns are consistent, using the same structure for both resources
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent view preference implementation across components

# Search for localStorage usage with view preferences
echo "Checking localStorage usage for view preferences:"
rg -A 2 "localStorage\.setItem\(.*View.*\)" --type ts --type tsx

# Search for view navigation patterns
echo "\nChecking view navigation patterns:"
rg -A 2 "navigate\(.*/(list|board)" --type ts --type tsx

# Search for similar button implementations
echo "\nChecking button implementations:"
ast-grep --pattern 'Button $props { 
  $$$
  onClick={$_} 
  $$$
}'

Length of output: 522


Script:

#!/bin/bash
# Search for localStorage usage with view preferences
echo "Checking localStorage usage for view preferences:"
rg "localStorage\.setItem.*View" -t typescript -t tsx

# Search for view navigation patterns
echo -e "\nChecking view navigation patterns:"
rg "navigate.*/(list|board)" -t typescript -t tsx

# Search for view-related button click handlers
echo -e "\nChecking view-related click handlers:"
rg "on(List|Board|Grid).*Click" -t typescript -t tsx

Length of output: 552


Script:

#!/bin/bash
# Search for localStorage usage with view preferences
echo "Checking localStorage usage for view preferences:"
rg "localStorage\.setItem.*View"

# Search for view navigation patterns
echo -e "\nChecking view navigation patterns:"
rg "navigate.*/(list|board)"

# Search for view-related button click handlers
echo -e "\nChecking view-related click handlers:"
rg "on(List|Board|Grid).*Click"

# Check the file extension pattern in the codebase
echo -e "\nChecking available file extensions:"
fd -e ts -e tsx

Length of output: 27695

src/components/Shifting/ShiftingBoard.tsx Show resolved Hide resolved
@Jacobjeevan Jacobjeevan added needs testing reviewed reviewed by a core member labels Dec 5, 2024
@nihal467
Copy link
Member

LGTM

@rithviknishad rithviknishad merged commit 0f7a9d8 into ohcnetwork:develop Dec 10, 2024
19 checks passed
Copy link

@nithish1018 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
reviewed reviewed by a core member tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource tab is always redirecting to list view instead of user default view
4 participants