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: Links of sidebar_menu now working at view_profile_section #3086

Conversation

PratapRathi
Copy link
Contributor

@PratapRathi PratapRathi commented Dec 30, 2024

What kind of change does this PR introduce?
This PR will fix the issue, when at view_profile page left-side menu links are not working, also separate test is also added for the same so that it will not break again.

Issue Number:
Fixes #3000

Did you add tests for your changes?
Yes

Snapshots/Videos:

Screenshot 2024-12-30 at 19 40 35
Screen.Recording.2024-12-30.at.18.59.47.mov

If relevant, did you update the documentation?
N/A

Summary
Does this PR introduce a breaking change?
No

Other information
When we click on the view profile link it was routing page to /member/:userId but now it is fixed to /member/:orgId. Also when orgId is not available then route to /member/.

Have you read the contributing guide?
Yes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Updated profile dropdown to use URL parameters for navigation.
    • Improved routing logic for profile navigation based on organization ID.
  • Bug Fixes

    • Removed reliance on local storage for user ID.
    • Enhanced error handling for logout process.
  • Tests

    • Added routing context to profile dropdown tests.
    • Expanded test coverage for navigation scenarios, including error logging on logout failure.

Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

Walkthrough

The pull request modifies the ProfileDropdown component and its test suite to improve routing and navigation logic. The changes involve extracting the organization ID from URL parameters instead of local storage, updating the logout navigation flow, and enhancing the test suite to handle routing contexts and error scenarios more robustly.

Changes

File Change Summary
src/components/ProfileDropdown/ProfileDropdown.tsx - Replaced userID from local storage with orgId from URL parameters
- Updated logout navigation to use orgId
src/components/ProfileDropdown/ProfileDropdown.spec.tsx - Added Route and Routes for routing context in tests
- Updated test case to simulate navigation with dynamic path
- Enhanced error handling test for logout functionality

Assessment against linked issues

Objective Addressed Explanation
Sidebar menu links not working in view profile section [#3000]
Routing with selected organization
Handling navigation when no organization selected Requires further investigation

Possibly related PRs

Suggested reviewers

  • palisadoes

Poem

🐰 A rabbit's tale of code so bright,
Routing paths now set just right,
From local store to URL's embrace,
ProfileDropdown dances with grace,
Navigating with newfound might! 🚀


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fc97ed and 7e3a8e6.

📒 Files selected for processing (1)
  • src/components/ProfileDropdown/ProfileDropdown.spec.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/ProfileDropdown/ProfileDropdown.spec.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 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.

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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/ProfileDropdown/ProfileDropdown.tsx (1)

106-106: Ensure fallback navigation logic for members is intentional
When userRole is not 'User', the code navigates to /member/${orgId || ''}. If orgId is empty, this might cause a route mismatch. Consider redirecting to a fully qualified and valid path when orgId isn’t present.

-: navigate(`/member/${orgId || ''}`)
+: navigate(orgId ? `/member/${orgId}` : '/defaultMemberPath')
src/components/ProfileDropdown/ProfileDropdown.spec.tsx (1)

242-242: Consider using an in-memory router for testing.

While window.history.pushState() works here, you might find MemoryRouter or createMemoryHistory (from history) more aligned with typical React testing patterns. This approach isolates navigation for each test, preventing potential side effects in a shared window history.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bc3c5e and 4fc97ed.

📒 Files selected for processing (2)
  • src/components/ProfileDropdown/ProfileDropdown.spec.tsx (3 hunks)
  • src/components/ProfileDropdown/ProfileDropdown.tsx (3 hunks)
🔇 Additional comments (5)
src/components/ProfileDropdown/ProfileDropdown.tsx (2)

4-4: Use of useParams is aligned with React Router best practices
The import of the useParams hook is a commendable approach to extracting route parameters directly from the URL, aligning well with recommended usage patterns.


40-40: Verify that orgId will always be available or handled gracefully
If orgId in the URL is omitted, useParams() returns undefined. The fallback to an empty string might result in navigation issues (e.g., navigating to /member/). Confirm the presence of a default route or guard this scenario more explicitly.

✅ Verification successful

Let me verify the usage of orgId with additional checks.


Let me check how the MemberDetail component handles the orgId parameter.


Let me check how the ProfileDropdown component handles navigation and if there are any fallbacks.


The orgId parameter is handled gracefully with appropriate fallbacks

The codebase shows that:

  1. The ProfileDropdown component handles missing orgId by using the nullish coalescing operator (orgId || ''), preventing navigation to an invalid URL.
  2. There's a default route /member without parameters that will catch any invalid member routes.
  3. The navigation is role-dependent, with users being redirected to /user/settings instead of the member route.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the /member/ route is defined or gracefully handled in the codebase.

# Searching for route definitions containing '/member'
rg -A 3 $'/member'

Length of output: 5061


Script:

#!/bin/bash
# Check how MemberDetail component handles the orgId parameter
ast-grep --pattern 'function MemberDetail() {
  $$$
}'

# Check for any route guards or redirects
rg -A 3 "Navigate|Redirect" src/

Length of output: 56327


Script:

#!/bin/bash
# Check MemberDetail component implementation
rg -A 10 "function MemberDetail" src/screens/MemberDetail/MemberDetail.tsx

# Check if there are any guards or error handling for orgId in MemberDetail
rg -A 5 "orgId|currentUrl" src/screens/MemberDetail/MemberDetail.tsx

Length of output: 1366


Script:

#!/bin/bash
# Check ProfileDropdown navigation logic
rg -B 5 -A 5 "navigate.*member.*orgId" src/components/ProfileDropdown/ProfileDropdown.tsx

# Check if there are any default routes or fallbacks for member route
rg -A 3 "path=\"/member\"" src/App.tsx

Length of output: 674

src/components/ProfileDropdown/ProfileDropdown.spec.tsx (3)

4-4: Use of Route and Routes is appropriate.

Importing Route and Routes from react-router-dom for test scenarios is a recommended approach and ensures that the component is properly tested in a realistic routing context.


250-252: Route definition for /:orgId is sufficient but verify broader coverage.

Your inclusion of the <Route path="/:orgId" element={<ProfileDropdown />} /> covers the updated logic. However, consider edge cases and error routes (e.g., invalid or missing orgId) by adding tests to ensure robust handling.
[approve]

Would you like me to draft a shell script to locate and check all route definitions in the codebase to confirm coverage for possible error states?


266-266: Ensure that /member/:orgId route is present in production code.

The test expects navigation to '/member/321'. Please confirm that the main application indeed has a corresponding route for '/member/:orgId'. If not, the test might pass locally but encounter an undefined route in production.

✅ Verification successful

Route /member/:orgId is properly defined and used throughout the application

The route /member/:orgId is correctly defined in src/App.tsx:

<Route path="/member/:orgId" element={<MemberDetail />} />

This route is consistently used across multiple components:

  • OrganizationPeople: Links to member profiles
  • ProfileDropdown: Navigation to member profiles
  • AddMember: Member profile navigation
  • ManageTag: View profile functionality
  • Leaderboard: User profile navigation
  • EventAttendance: Member profile links

The test's expectation of navigation to /member/321 aligns with the production code's routing implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for route definitions matching '/member/{orgId}'
rg -A 5 $'/member/'

Length of output: 6878

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 30, 2024
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.94%. Comparing base (1bc3c5e) to head (7e3a8e6).
Report is 3 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3086       +/-   ##
=====================================================
+ Coverage             26.46%   88.94%   +62.47%     
=====================================================
  Files                   300      321       +21     
  Lines                  7568     8410      +842     
  Branches               1652     1837      +185     
=====================================================
+ Hits                   2003     7480     +5477     
+ Misses                 5434      688     -4746     
- Partials                131      242      +111     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes palisadoes merged commit e0da67b into PalisadoesFoundation:develop-postgres Dec 30, 2024
15 checks passed
Dhiren-Mhatre pushed a commit to Dhiren-Mhatre/talawa-admin that referenced this pull request Dec 30, 2024
…adoesFoundation#3086)

* fix: Links of sidebar_menu now working at view_profile_section

* Added Test when no organisation is selected
@PratapRathi PratapRathi deleted the fix-links-of-sidebar-menu-not-working-at-view-profile-page branch December 30, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants