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

add visit button in joined organization filter #3218

Conversation

gkbishnoi07
Copy link

@gkbishnoi07 gkbishnoi07 commented Jan 9, 2025

What kind of change does this PR introduce?
Feature: Added a visit button component to the Joined Organizations section

Issue Number:
Fixes #3162

Did you add tests for your changes?
Yes

  • Added unit tests for VisitButton component in JoinedOrganizations
  • Added integration tests for button interactions within the organizations list
  • Added test cases for organization URL validation

Snapshots/Videos:

issue.3162.mp4

Summary
This PR adds a visit button component to the Joined Organizations section that:

  • Allows users to directly visit organization websites from their joined organizations list
  • Integrates seamlessly with existing organization card design
  • Implements proper URL validation and error handling
  • Maintains consistent styling with our design system

Does this PR introduce a breaking change?
No

Other information

  • Button appears in each organization card in the Joined Organizations section
  • Opens organization URLs in a new tab for better user experience
  • Includes loading state while processing clicks
  • Implements aria-labels for accessibility
  • Handles cases where organization URL might be missing or invalid

Have you read the contributing guide?
Yes

Summary by CodeRabbit

  • New Features

    • Enhanced Organization Card with more detailed information
    • Added membership request management functionality
    • Improved organization display with image, description, and address
  • Bug Fixes

    • Refined organization membership status tracking
    • Updated logic for displaying organization membership states
  • Documentation

    • Updated component documentation to reflect new properties and functionality
  • Tests

    • Expanded test coverage for Organization Card component
    • Improved testing environment with routing and internationalization support

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request introduces significant changes to the OrganizationCard component and its associated test file. The modifications enhance the component's functionality by adding more detailed organization information, implementing membership request handling, and improving the testing setup. The changes include expanding the component's props, adding new rendering logic for organization details, and creating more comprehensive unit tests that cover various scenarios of component rendering.

Changes

File Change Summary
src/components/OrganizationCard/OrganizationCard.spec.tsx - Added imports for routing, internationalization, and GraphQL mocking
- Renamed test description block
- Updated test cases with expanded props
- Added test for rendering without image
src/components/OrganizationCard/OrganizationCard.tsx - Expanded interface with new properties
- Added membership request handling functionality
- Updated rendering logic with more detailed organization information
- Implemented conditional button rendering
src/screens/UserPortal/Organizations/Organizations.tsx - Modified organization list processing
- Added isJoined and explicit membershipRequestStatus for different organization modes

Assessment against linked issues

Objective Addressed Explanation
Visit Button for Joined Organizations [#3162]

Possibly related issues

Possibly related PRs

Suggested reviewers

  • disha1202
  • pranshugupta54
  • AVtheking

Poem

🐰 A Rabbit's Ode to Organization Cards 🏢

Buttons dance, memberships flow,
Cards now tell a story to show,
Images bright, details galore,
Testing magic from floor to floor,
Code hops with joy, no more to implore! 🌟

Finishing Touches

  • 📝 Generate Docstrings

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

github-actions bot commented Jan 9, 2025

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

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

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

🔭 Outside diff range comments (1)
src/screens/UserPortal/Organizations/Organizations.tsx (1)

Line range hint 226-228: Fix inconsistent element ID in handleSearchByBtnClick

The id used in document.getElementById is 'searchUserOrgs', but the Form.Control element has an id of 'searchOrganizations'. This mismatch will cause the search functionality to fail.

Apply this diff to correct the id:

const handleSearchByBtnClick = (): void => {
  const value =
-    (document.getElementById('searchUserOrgs') as HTMLInputElement)?.value || '';
+    (document.getElementById('searchOrganizations') as HTMLInputElement)?.value || '';
  handleSearch(value);
};
🧹 Nitpick comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (1)

176-176: Simplify null checks using optional chaining

You can simplify the null checks by using optional chaining for better readability.

Apply this diff to use optional chaining:

-{address && address.city && (
+{address?.city && (
🧰 Tools
🪛 Biome (1.9.4)

[error] 176-176: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/screens/UserPortal/Organizations/Organizations.tsx (1)

254-258: Review the necessity of the isJoined property

The isJoined property is added to organizations but is not defined in InterfaceOrganizationCardProps and does not appear to be used in the OrganizationCard component. If it is not required, consider removing it to simplify the code.

Also applies to: 266-271, 281-286

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 50cd26d and 751e9e2.

📒 Files selected for processing (3)
  • src/components/OrganizationCard/OrganizationCard.spec.tsx (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (1 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/OrganizationCard/OrganizationCard.tsx

[error] 176-176: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)

Comment on lines +133 to +138
if (error.message === 'User is already a member') {
toast.error(t('AlreadyJoined') as string);
} else {
toast.error(t('errorOccured') as string);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling by using error codes instead of error messages

Comparing error messages as strings can be brittle and may not handle localization properly. Consider using error codes or custom error types to handle specific errors.

Comment on lines +143 to +151
const membershipRequest = membershipRequests.find(
(request) => request.user._id === userId,
);

await cancelMembershipRequest({
variables: {
membershipRequestId: membershipRequest?._id,
},
});
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

Handle case when membership request is not found

The membershipRequest may be undefined if no request is found. Add a check to handle this case to prevent potential runtime errors.

Apply this diff to handle the undefined case:

async function withdrawMembershipRequest(): Promise<void> {
  const membershipRequest = membershipRequests.find(
    (request) => request.user._id === userId,
  );

+  if (!membershipRequest) {
+    toast.error(t('MembershipRequestNotFound') as string);
+    return;
+  }

  await cancelMembershipRequest({
    variables: {
      membershipRequestId: membershipRequest?._id,
    },
  });
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const membershipRequest = membershipRequests.find(
(request) => request.user._id === userId,
);
await cancelMembershipRequest({
variables: {
membershipRequestId: membershipRequest?._id,
},
});
const membershipRequest = membershipRequests.find(
(request) => request.user._id === userId,
);
if (!membershipRequest) {
toast.error(t('MembershipRequestNotFound') as string);
return;
}
await cancelMembershipRequest({
variables: {
membershipRequestId: membershipRequest._id,
},
});

Comment on lines +28 to +57
describe('Organization Card', () => {
test('renders organization card with image', () => {
render(
<MockedProvider>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrganizationCard {...props} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);

expect(screen.getByText(props.name)).toBeInTheDocument();
expect(screen.getByText(/Owner:/i)).toBeInTheDocument();
expect(screen.getByText(props.firstName)).toBeInTheDocument();
expect(screen.getByText(props.lastName)).toBeInTheDocument();
expect(screen.getByRole('img')).toBeInTheDocument();
});

it('Should render text elements when props value is not passed', () => {
const props = {
id: '123',
test('renders organization card without image', () => {
const propsWithoutImage = {
...props,
image: '',
firstName: 'John',
lastName: 'Doe',
name: 'Sample',
};

render(<OrganizationCard {...props} />);
render(
<MockedProvider>
<BrowserRouter>
<I18nextProvider i18n={i18nForTest}>
<OrganizationCard {...propsWithoutImage} />
</I18nextProvider>
</BrowserRouter>
</MockedProvider>,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add unit tests for membership status conditional rendering

The current test suite does not cover the conditional rendering based on membershipRequestStatus. To ensure the component functions correctly in all scenarios, add unit tests for cases where membershipRequestStatus is 'accepted', 'pending', and an empty string.

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 17 lines in your changes missing coverage. Please review.

Project coverage is 89.91%. Comparing base (50cd26d) to head (751e9e2).
Report is 2 commits behind head on develop-postgres.

Files with missing lines Patch % Lines
...c/components/OrganizationCard/OrganizationCard.tsx 48.27% 15 Missing ⚠️
...screens/UserPortal/Organizations/Organizations.tsx 60.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3218       +/-   ##
=====================================================
+ Coverage             12.22%   89.91%   +77.69%     
=====================================================
  Files                   308      329       +21     
  Lines                  7839     8555      +716     
  Branches               1709     1920      +211     
=====================================================
+ Hits                    958     7692     +6734     
+ Misses                 6815      628     -6187     
- Partials                 66      235      +169     

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

@gkbishnoi07 gkbishnoi07 closed this by deleting the head repository Jan 9, 2025
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.

1 participant