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

Refactor: Replace Query with Correct Query to Fetch All and Joined Organizations #3795

Open
wants to merge 5 commits into
base: develop-postgres
Choose a base branch
from

Conversation

gkbishnoi07
Copy link

@gkbishnoi07 gkbishnoi07 commented Mar 4, 2025

What kind of change does this PR introduce?
This PR replaces the previous query that only fetched joined organizations with a correct query to retrieve all organizations. Previously, we used organizationWhereMember to fetch All organizations, but it only returned those where the user was a member. Now, the updated query correctly fetches all organizations.

Now,
We correctly fetch all organizations using the organizations query.
We fetch joined organizations separately using the organizationsWhereMember query.

Issue Number:

Fixes #3565

Snapshots/Videos:

replace joinedOrganization query with organizationsWheremember to fetch only joined organization
where

Summary

Does this PR introduce a breaking change?
No

Checklist

CodeRabbit AI Review

  • I have reviewed and addressed all critical issues flagged by CodeRabbit AI
  • I have implemented or provided justification for each non-critical suggestion
  • I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented

Test Coverage

  • I have written tests for all new changes/features
  • I have verified that test coverage meets or exceeds 95%
  • I have run the test suite locally and all tests pass

Other information

Have you read the contributing guide?

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor

    • Streamlined organization data retrieval to present information more consistently across the portal.
    • Updated organization details with refined profiles, including new identifiers and descriptions for clearer presentation.
    • Enhanced pagination for smoother navigation through organization listings.
  • New Features

    • Introduced updated queries for fetching organization data, improving data structure and access.
    • Added support for pagination in organization member listings.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Warning

Rate limit exceeded

@gkbishnoi07 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7858541 and 12e4a44.

📒 Files selected for processing (2)
  • src/components/OrganizationCard/OrganizationCard.tsx (2 hunks)
  • src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (2 hunks)

Walkthrough

The changes update several GraphQL queries and associated component logic for handling organization data. The primary update replaces the old queries with new ones: the ORGANIZATION_LIST query now returns updated fields including pagination for members, and the USER_JOINED_ORGANIZATIONS_PG query now requires the first parameter. Additionally, references in the OrganizationCard and associated components have been updated to reflect these new queries, along with interface adjustments (renaming _id to id) and minor debugging additions in the Organizations screen.

Changes

File(s) Change Summary
src/GraphQl/Queries/Queries.ts Updated ORGANIZATION_LIST query: removed fields like _id, image, creator, etc., and added new fields (id, name, addressLine1, description, avatarURL); restructured members for pagination; changed USER_JOINED_ORGANIZATIONS_PG argument type for first from Int to Int!.
src/components/OrganizationCard/OrganizationCard.tsx
src/components/UserPortal/OrganizationCard/OrganizationCard.tsx
Replaced USER_ORGANIZATION_CONNECTION with ORGANIZATION_LIST and USER_JOINED_ORGANIZATIONS with USER_JOINED_ORGANIZATIONS_PG; updated refetchQueries in mutations; added a mandatory parameter (first: 5) in one instance.
src/screens/UserPortal/Organizations/Organizations.tsx Removed USER_JOINED_ORGANIZATIONS constant and added ORGANIZATION_LIST; updated interfaces by renaming _id to id; modified useEffect logic for data mapping and added a console.log for debugging.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI Component
    participant AC as Apollo Client
    participant GS as GraphQL Server

    UI->>AC: Request ORGANIZATION_LIST data
    AC->>GS: Send updated ORGANIZATION_LIST query (new fields & pagination)
    GS-->>AC: Return organization data with id, name, addressLine1, description, avatarURL, paginated members
    AC-->>UI: Deliver data for rendering

    UI->>AC: Request USER_JOINED_ORGANIZATIONS_PG (with required 'first')
    AC->>GS: Query user membership details with pagination
    GS-->>AC: Return paginated user organization data
    AC-->>UI: Update UI with membership info
Loading

Possibly related PRs

Suggested labels

no-pr-activity

Suggested reviewers

  • palisadoes
  • gautam-divyanshu

Poem

I'm a rabbit who loves to hop,
Skipping through queries that never stop.
New fields and pagination make the code bright,
Renaming and refactors in full flight.
Carrot cheers for updates that pop! 🥕


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.
  • @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 Mar 4, 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
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

🔭 Outside diff range comments (3)
src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (1)

109-118: ⚠️ Potential issue

Add error handling to withdrawMembershipRequest function.

The function is missing error handling for the case where membershipRequest is undefined. This could happen if the user's membership request is not found in the array.

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

+   if (!membershipRequest) {
+     toast.error(t('MembershipRequestNotFound') as string);
+     return;
+   }
+
    await cancelMembershipRequest({
      variables: {
        membershipRequestId: membershipRequest?._id,
      },
    });
+   toast.success(t('MembershipRequestWithdrawn') as string);
  }
src/screens/UserPortal/Organizations/Organizations.tsx (2)

72-94: ⚠️ Potential issue

Update InterfaceOrganization to also use consistent field names.

While InterfaceOrganizationCardProps has been updated to use id instead of _id, the InterfaceOrganization interface still uses the old field names. This inconsistency could lead to bugs.

interface InterfaceOrganization {
  isJoined: boolean;
-  _id: string;
+  id: string;
  name: string;
  image: string;
  description: string;
  admins: [];
  members: [];
  address: {
    city: string;
    countryCode: string;
    line1: string;
    postalCode: string;
    state: string;
  };
  membershipRequestStatus: string;
  userRegistrationRequired: boolean;
  membershipRequests: {
-    _id: string;
+    id: string;
    user: {
-      _id: string;
+      id: string;
    };
  }[];
}

262-285: ⚠️ Potential issue

Fix field name inconsistencies in organization mapping.

The mapping function is still referencing _id fields, but the new GraphQL schema uses id. This mismatch will cause the membership status check to fail. Additionally, the type annotation also needs to be updated.

- (organization: { members: { _id: string; }[]; membershipRequests: { _id: string; user: { _id: string; }; }[]; }) => {
+ (organization: { members: { id: string; }[]; membershipRequests: { id: string; user: { id: string; }; }[]; }) => {
    let membershipRequestStatus = '';
    if (
      Array.isArray(organization.members) &&
      organization.members.some(
-        (member: { _id: string }) => member._id === userId,
+        (member: { id: string }) => member.id === userId,
      )
    )
      membershipRequestStatus = 'accepted';
    else if (
      organization.membershipRequests?.some(
-        (request: { _id: string; user: { _id: string } }) =>
-          request.user._id === userId,
+        (request: { id: string; user: { id: string } }) =>
+          request.user.id === userId,
      )
    )
      membershipRequestStatus = 'pending';
🧰 Tools
🪛 ESLint

[error] 262-262: Replace ·members:·{·_id:·string;·}[];·membershipRequests:·{·_id:·string;·user:·{·_id:·string;·};·}[]; with ⏎············members:·{·_id:·string·}[];⏎············membershipRequests:·{·_id:·string;·user:·{·_id:·string·}·}[];⏎·········

(prettier/prettier)

🧹 Nitpick comments (5)
src/components/OrganizationCard/OrganizationCard.tsx (2)

13-14: Consolidate duplicate imports.

You're importing from 'GraphQl/Queries/Queries' twice which can cause confusion and is flagged by ESLint. Consider merging these imports into a single statement.

-import { ORGANIZATION_LIST } from 'GraphQl/Queries/Queries';
-import { USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
+import { ORGANIZATION_LIST, USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
🧰 Tools
🪛 ESLint

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


70-70: Consistent formatting for refetchQueries arrays.

The refetchQueries arrays have inconsistent formatting, which is flagged by the linter. Consider standardizing the formatting to improve readability.

  const [sendMembershipRequest] = useMutation(SEND_MEMBERSHIP_REQUEST, {
    refetchQueries: [
-      { query: ORGANIZATION_LIST, variables: { id } },
+      { query: ORGANIZATION_LIST, variables: { id } }
    ],
  });

Also applies to: 75-75, 80-80

src/GraphQl/Queries/Queries.ts (1)

41-60: Improve query structure and formatting.

The GraphQL query structure has inconsistent indentation and spacing which impacts readability. The organization members query now includes pagination, which is a good practice, but the formatting should be improved.

  query {
    organizations {
      id
-       name
-       addressLine1
-       description
-       avatarURL
-       members(first: 32) {
-       edges {
-        node {
-           id   
-        }
-       }
-        pageInfo {
-          hasNextPage
-        }
-      
+      name
+      addressLine1
+      description
+      avatarURL
+      members(first: 32) {
+        edges {
+          node {
+            id
+          }
+        }
+        pageInfo {
+          hasNextPage
+        }
      }
    }
  }
🧰 Tools
🪛 ESLint

[error] 44-44: Delete ·

(prettier/prettier)


[error] 45-45: Delete ·

(prettier/prettier)


[error] 46-46: Delete ·

(prettier/prettier)


[error] 47-47: Delete ·

(prettier/prettier)


[error] 48-48: Delete ·

(prettier/prettier)


[error] 49-49: Insert ·

(prettier/prettier)


[error] 50-50: Insert ··

(prettier/prettier)


[error] 51-52: Replace id···⏎ with ·id⏎··

(prettier/prettier)


[error] 53-53: Insert ·

(prettier/prettier)


[error] 56-57: Delete ⏎······

(prettier/prettier)

src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (1)

13-14: Consolidate duplicate imports.

You're importing from 'GraphQl/Queries/Queries' twice which can cause confusion and is flagged by ESLint. Consider merging these imports into a single statement.

-import { ORGANIZATION_LIST } from 'GraphQl/Queries/Queries';
-import { USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
+import { ORGANIZATION_LIST, USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
🧰 Tools
🪛 ESLint

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)

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

146-146: Remove debugging console.log statement.

There's a console.log statement that was likely added for debugging purposes. This should be removed before merging to production.

-  console.log(data);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8709ef9 and fd0e06d.

📒 Files selected for processing (4)
  • src/GraphQl/Queries/Queries.ts (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (2 hunks)
  • src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (2 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (6 hunks)
🧰 Additional context used
🪛 ESLint
src/components/OrganizationCard/OrganizationCard.tsx

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 74-76: Replace ⏎······{·query:·ORGANIZATION_LIST,·variables:·{·id·}·},⏎···· with {·query:·ORGANIZATION_LIST,·variables:·{·id·}·}

(prettier/prettier)


[error] 79-81: Replace ⏎······{·query:·ORGANIZATION_LIST,·variables:·{·id·}·},⏎···· with {·query:·ORGANIZATION_LIST,·variables:·{·id·}·}

(prettier/prettier)

src/GraphQl/Queries/Queries.ts

[error] 44-44: Delete ·

(prettier/prettier)


[error] 45-45: Delete ·

(prettier/prettier)


[error] 46-46: Delete ·

(prettier/prettier)


[error] 47-47: Delete ·

(prettier/prettier)


[error] 48-48: Delete ·

(prettier/prettier)


[error] 49-49: Insert ·

(prettier/prettier)


[error] 50-50: Insert ··

(prettier/prettier)


[error] 51-52: Replace id···⏎ with ·id⏎··

(prettier/prettier)


[error] 53-53: Insert ·

(prettier/prettier)


[error] 56-57: Delete ⏎······

(prettier/prettier)

src/components/UserPortal/OrganizationCard/OrganizationCard.tsx

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 59-61: Replace ⏎······{·query:·ORGANIZATION_LIST,·variables:·{·id:·props.id·}·},⏎···· with {·query:·ORGANIZATION_LIST,·variables:·{·id:·props.id·}·}

(prettier/prettier)


[error] 64-66: Replace ⏎······{·query:·ORGANIZATION_LIST,·variables:·{·id:·props.id·}·},⏎···· with {·query:·ORGANIZATION_LIST,·variables:·{·id:·props.id·}·}

(prettier/prettier)

src/screens/UserPortal/Organizations/Organizations.tsx

[error] 258-259: Delete ⏎···

(prettier/prettier)


[error] 262-262: Replace ·members:·{·_id:·string;·}[];·membershipRequests:·{·_id:·string;·user:·{·_id:·string;·};·}[]; with ⏎············members:·{·_id:·string·}[];⏎············membershipRequests:·{·_id:·string;·user:·{·_id:·string·}·}[];⏎·········

(prettier/prettier)


[error] 474-474: Insert

(prettier/prettier)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (5)
src/GraphQl/Queries/Queries.ts (1)

63-65:

❓ Verification inconclusive

Verify the updated query parameter requirement.

The first parameter in USER_JOINED_ORGANIZATIONS_PG has been changed from optional to required (Int!). This is a breaking change that will affect all components using this query. Ensure that all consumers of this query are updated to provide this parameter.

Let's check if all usages of this query in the codebase provide the required first parameter:


🏁 Script executed:

#!/bin/bash
# Find all files that import and use USER_JOINED_ORGANIZATIONS_PG
echo "Searching for files that import USER_JOINED_ORGANIZATIONS_PG..."
rg "import.*USER_JOINED_ORGANIZATIONS_PG" --type ts --type tsx

echo "\nChecking query usage patterns..."
rg "useQuery\(USER_JOINED_ORGANIZATIONS_PG" -A 5 --type ts --type tsx

Length of output: 408


Below is an updated review comment that calls out the need to verify the query’s usage—and that manual or re-run verification is required due to the initial script’s file type issues:


Action Required: Verify the updated query parameter usage

The first parameter for USER_JOINED_ORGANIZATIONS_PG is now required (Int!), which is a breaking change for all consumers of this query. Since our initial search script failed to process TSX files (due to the “unrecognized file type: tsx” error), please verify (manually or by re-running an updated search) that all call sites—across both TS and TSX files—provide the first parameter when using this query.

For additional verification, consider re-running this improved shell script:

#!/bin/bash
# Add TSX file type support
rg --type-add 'tsx:*.tsx' --type ts --type tsx "import.*USER_JOINED_ORGANIZATIONS_PG" -n

echo -e "\nSearching for query usage in calls to useQuery..."
rg --type-add 'tsx:*.tsx' --type ts --type tsx "useQuery\(USER_JOINED_ORGANIZATIONS_PG" -n -A 5

Please confirm that no query consumers were missed and that they all correctly supply the first parameter.

src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (1)

68-70: Good implementation with required parameter.

This is a good implementation that properly includes the now required first parameter in the USER_JOINED_ORGANIZATIONS_PG query.

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

61-65: Update interface to use consistent field names.

The interface has been updated to use id instead of _id for membership requests, which is good for consistency with the new GraphQL schema.


431-432: Good field name update.

The property assignment correctly uses the new id field, which matches the updated schema.


259-260:

✅ Verification successful

Verify the data structure in the updated query.

The code now accesses data.organizations directly, which assumes a specific structure from the ORGANIZATION_LIST query. Ensure that this structure matches what's defined in the GraphQL schema.

Let's verify the query structure by examining the schema definition:


🏁 Script executed:

#!/bin/bash
# Find where the organizations query is defined in the GraphQL schema
fd -e graphql -e gql "type Query" | xargs cat | grep -A 10 "organizations"

# Also check the structure of the actual query
rg -A 10 "ORGANIZATION_LIST = gql\`" --type ts

Length of output: 1200


GraphQL Query Structure Verified

  • The ORGANIZATION_LIST query returns an organizations field with the expected fields (id, name, addressLine1, description, avatarURL, and members with edges and node), which aligns with the code's access of data.organizations.
  • No discrepancies were found between the query response structure and the code usage in src/screens/UserPortal/Organizations/Organizations.tsx.

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 4, 2025
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 (3)
src/screens/UserPortal/Organizations/Organizations.tsx (3)

89-94: 🛠️ Refactor suggestion

Update interface to use consistent property names.

The membershipRequests field in InterfaceOrganization uses _id while the same field in InterfaceOrganizationCardProps uses id. They should be consistent.

membershipRequests: {
-  _id: string;
+  id: string;
  user: {
-    _id: string;
+    id: string;
  };
}[];

229-252: ⚠️ Potential issue

Update property references in this useEffect.

This useEffect still uses _id to access organization and member properties, but it should be updated to use id to be consistent with the GraphQL schema changes.

useEffect(() => {
  if (data) {
    const organizations = data?.UserJoinedOrganizations?.map(
      (organization: InterfaceOrganization) => {
        let membershipRequestStatus = '';
        if (
          organization.members.find(
-            (member: { _id: string }) => member._id === userId,
+            (member: { id: string }) => member.id === userId,
          )
        )
          membershipRequestStatus = 'accepted';
        else if (
          organization.membershipRequests.find(
-            (request: { user: { _id: string } }) =>
-              request.user._id === userId,
+            (request: { user: { id: string } }) =>
+              request.user.id === userId,
          )
        )
          membershipRequestStatus = 'pending';
        return { ...organization, membershipRequestStatus };
      },
    );
    setOrganizations(organizations);
  }
}, [data]);

265-279: ⚠️ Potential issue

Update property references in the mapping function.

This code still references _id but should use id to be consistent with the GraphQL schema changes.

if (
  Array.isArray(organization.members) &&
  organization.members.some(
-    (member: { _id: string }) => member._id === userId,
+    (member: { id: string }) => member.id === userId,
  )
)
  membershipRequestStatus = 'accepted';
else if (
  organization.membershipRequests?.some(
-    (request: { _id: string; user: { _id: string } }) =>
-      request.user._id === userId,
+    (request: { id: string; user: { id: string } }) =>
+      request.user.id === userId,
  )
)
🧹 Nitpick comments (2)
src/components/OrganizationCard/OrganizationCard.tsx (1)

13-14: Combine duplicate imports from the same module.

These imports are coming from the same module and should be combined into a single import statement to follow best practices and resolve the ESLint warning.

-import { ORGANIZATION_LIST } from 'GraphQl/Queries/Queries';
-import { USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
+import { ORGANIZATION_LIST, USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
🧰 Tools
🪛 ESLint

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)

src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (1)

13-14: Combine duplicate imports from the same module.

These imports are coming from the same module and should be combined into a single import statement to follow best practices and resolve the ESLint warning.

-import { ORGANIZATION_LIST } from 'GraphQl/Queries/Queries';
-import { USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
+import { ORGANIZATION_LIST, USER_JOINED_ORGANIZATIONS_PG } from 'GraphQl/Queries/Queries';
🧰 Tools
🪛 ESLint

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd0e06d and d667831.

📒 Files selected for processing (4)
  • src/GraphQl/Queries/Queries.ts (1 hunks)
  • src/components/OrganizationCard/OrganizationCard.tsx (2 hunks)
  • src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (2 hunks)
  • src/screens/UserPortal/Organizations/Organizations.tsx (5 hunks)
🧰 Additional context used
🪛 ESLint
src/components/OrganizationCard/OrganizationCard.tsx

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)

src/components/UserPortal/OrganizationCard/OrganizationCard.tsx

[error] 13-13: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)


[error] 14-14: 'GraphQl/Queries/Queries' imported multiple times.

(import/no-duplicates)

🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
src/screens/UserPortal/Organizations/Organizations.tsx

[failure] 433-433:
Property 'id' does not exist on type 'InterfaceOrganization'.

🪛 GitHub Actions: PR Workflow
src/screens/UserPortal/Organizations/Organizations.tsx

[error] 433-433: error TS2339: Property 'id' does not exist on type 'InterfaceOrganization'.

🔇 Additional comments (4)
src/GraphQl/Queries/Queries.ts (2)

43-57: Well-structured query with pagination support.

The updated query correctly implements pagination for members using the edges/node pattern and includes pageInfo with hasNextPage. This is a good approach for handling potentially large member lists.


63-63:

✅ Verification successful

Verify all query usages with the required parameter.

The first parameter has been changed from optional (Int) to required (Int!). Make sure all usages of this query across the application include this parameter.


🏁 Script executed:

#!/bin/bash
# Check all usages of USER_JOINED_ORGANIZATIONS_PG to ensure they include the first parameter
rg "USER_JOINED_ORGANIZATIONS_PG" -A 10 | grep -B 5 -A 5 "variables:"

Length of output: 9294


Verification Successful: All Query Usages Include the Required Parameter

The executed script confirms that every call to USER_JOINED_ORGANIZATIONS_PG in the codebase now correctly supplies the first parameter. For instance:

  • In src/components/OrganizationCard/OrganizationCard.tsx and src/components/UserPortal/OrganizationCard/OrganizationCard.tsx, the query call uses:
    variables: { id: userId, first: 5 },
  • In src/screens/OrgList/OrgListMocks.ts, the query is invoked with first: 8 (along with the relevant parameters).
  • In src/screens/OrgList/OrgList.tsx and src/screens/UserPortal/Organizations/Organizations.tsx, similar usage patterns with the required first parameter are present.

No instances were found where the parameter was omitted.

src/components/UserPortal/OrganizationCard/OrganizationCard.tsx (1)

62-64: Correctly implemented required parameter.

You've properly included the required first parameter in the query after the schema change. This is good practice to ensure the query works as expected.

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

259-288: Updated data structure handling.

The implementation now correctly handles the new query structure by checking for data?.organizations and mapping over it. This aligns with the changes made to the GraphQL query.

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

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

258-288: ⚠️ Potential issue

Updated organization data mapping to match new query structure

The organization data mapping has been updated to work with the new data.organizations structure returned by the ORGANIZATION_LIST query. However, there's a mismatch between the property names used in the code and the interface definition.

  (organization: {
-   members: { _id: string }[];
-   membershipRequests: { _id: string; user: { _id: string } }[];
+   members: { id: string }[];
+   membershipRequests: { id: string; user: { id: string } }[];
  }) => {

And similarly the member check should use id instead of _id:

  if (
    Array.isArray(organization.members) &&
    organization.members.some(
-     (member: { _id: string }) => member._id === userId,
+     (member: { id: string }) => member.id === userId,
    )
  )

And for the membership requests:

  else if (
    organization.membershipRequests?.some(
-     (request: { _id: string; user: { _id: string } }) =>
-       request.user._id === userId,
+     (request: { id: string; user: { id: string } }) =>
+       request.user.id === userId,
    ) as boolean
  )

433-433: ⚠️ Potential issue

Fix type error with organization ID

The code is accessing organization._id, but if the new query returns id instead of _id, this will cause a TypeScript error.

-  id: organization._id,
+  id: organization.id,

You should also update the InterfaceOrganization interface (lines 72-95) to use id instead of _id:

interface InterfaceOrganization {
  isJoined: boolean;
-  _id: string;
+  id: string;
  name: string;
  image: string;
  description: string;
  // ... rest of the interface
}

And similarly update the membershipRequests interface property:

membershipRequests: {
-  _id: string;
-  user: {
-    _id: string;
-  };
+  id: string;
+  user: {
+    id: string;
+  };
}[];

The same update should be applied to InterfaceOrganizationCardProps (lines 44-67).


259-287: 💡 Verification agent

🧩 Analysis chain

Verify data consistency between old and new query responses

Ensure that all fields necessary for the component's functionality are present in the new query response. The query structure has changed from accessing nested data in UserJoinedOrganizations to directly accessing organizations.


🏁 Script executed:

#!/bin/bash
# Check both old and new queries to ensure all required fields are present

# Look for the definition of ORGANIZATION_LIST
echo "Checking ORGANIZATION_LIST query definition:"
rg -A 20 "const ORGANIZATION_LIST =" src/

# Look for the old query definition (likely USER_JOINED_ORGANIZATIONS)
echo "Checking previous query definition:"
rg -A 20 "const USER_JOINED_ORGANIZATIONS =" src/

# Verify organization structure references in OrganizationCard component
echo "Checking OrganizationCard component references:"
rg "_id|\.id" src/components/UserPortal/OrganizationCard/

Length of output: 5591


Data Consistency Issue – Update Query Fields and Transformations

The new ORGANIZATION_LIST query is missing the membershipRequests field, and its members field is structured as a connection (with edges containing nodes with an id) rather than a direct array of members with a _id. This mismatch can cause the membership status checks in src/screens/UserPortal/Organizations/Organizations.tsx (lines 259–287) to fail.

Action Items:

  • Membership Requests: Ensure that the new query (or its subsequent data transformation) provides the membershipRequests field, which is required for determining the pending membership status.
  • Members Field Transformation: Adjust the transformation logic so that the members list is converted into an array with the expected _id property (or change the membership check accordingly), since the GraphQL response returns member IDs as id within a connection.

Please verify and update the query definition or the data mapping in the component to maintain consistency with the component's functionality.

🧹 Nitpick comments (1)
src/screens/UserPortal/Organizations/Organizations.tsx (1)

277-277: Unnecessary boolean type assertion

The explicit boolean type assertion is redundant as the some() method already returns a boolean value.

- ) as boolean
+ )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d667831 and 7858541.

📒 Files selected for processing (1)
  • src/screens/UserPortal/Organizations/Organizations.tsx (4 hunks)
🔇 Additional comments (4)
src/screens/UserPortal/Organizations/Organizations.tsx (4)

7-7: Appropriate query import for retrieving all organizations

Adding the ORGANIZATION_LIST import aligns with the PR objective to replace the existing query with one that can fetch all organizations, not just those where the user is a member.


143-145: Query updated to fetch all organizations

The change from the previous query to ORGANIZATION_LIST implements the PR's primary objective of fetching all organizations rather than only those where the user is a member.


146-146: Remove debug console.log statement

This debug statement should be removed before merging to production.

-  console.log(data);

149-152: Proper parameter passing for paginated query

The update correctly specifies the required first parameter for the paginated organizations query, which is necessary for proper pagination functionality.

@mpdesai90
Copy link

Please fix the failing tests. Our test code coverage system will fail if any of these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. The code does not comply with our linting check or other related formatting requirements
  4. Sometimes the cause is that you have not merged your code with the latest upstream. In this case, merge your local branch with the latest upstream, commit and then push to your origin.

@gkbishnoi07
Copy link
Author

Please fix the failing tests. Our test code coverage system will fail if any of these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. The code does not comply with our linting check or other related formatting requirements
  4. Sometimes the cause is that you have not merged your code with the latest upstream. In this case, merge your local branch with the latest upstream, commit and then push to your origin.

Working on failed test

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