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

Added dynamic breadcrumbs & Removed support for Removing Fund/Campaigns #2248

Merged

Conversation

GlenDsza
Copy link

@GlenDsza GlenDsza commented Sep 7, 2024

What kind of change does this PR introduce?

refactoring

Issue Number:

Fixes #2247

Did you add tests for your changes?

Yes

Snapshots/Videos:

breadcrumbs.mp4

Summary

  • Added Dynamic text in breadcrumbs for Funds/Campaigns/Pledges
  • Removed support for removing funds & campaigns

Does this PR introduce a breaking change?

No

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Enhanced data retrieval for fund-related queries, including fund names and archived status.
    • Improved display of fund names in the FundCampaignPledge component.
  • Bug Fixes

    • Removed deletion functionality for campaigns and funds, streamlining user interactions.
  • Documentation

    • Updated comments to reflect changes in modal management and deletion functionality.
  • Chores

    • Refined mock data structure to align with current application requirements, removing obsolete deletion references.

Copy link

coderabbitai bot commented Sep 7, 2024

Walkthrough

The changes involve the removal of GraphQL mutations for deleting campaigns and funds, reflecting a shift in functionality towards managing campaigns and funds without deletion capabilities. Additionally, enhancements were made to GraphQL queries to provide more detailed information about funds and campaigns. Mock data and interfaces were updated to align with these changes, ensuring consistency across the application.

Changes

Files Change Summary
src/GraphQl/Mutations/CampaignMutation.ts, src/GraphQl/Mutations/FundMutation.ts Removed DELETE_CAMPAIGN_MUTATION and REMOVE_FUND_MUTATION, eliminating deletion capabilities.
src/GraphQl/Queries/fundQueries.ts Enhanced FUND_CAMPAIGN and FUND_CAMPAIGN_PLEDGE queries to include additional fields for better data retrieval.
src/screens/FundCampaignPledge/FundCampaignPledge.tsx, src/screens/FundCampaignPledge/PledgesMocks.ts Introduced fundName to enhance UI and mock data structure by adding fundId with a name property.
src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx, src/screens/OrganizationFunds/OrganizationFunds.tsx Simplified modal management by removing delete modals and related states, focusing only on create/edit functionalities.
src/utils/interfaces.ts Updated interfaces to include new properties for better data representation regarding funds and campaigns.

Assessment against linked issues

Objective Addressed Explanation
Remove support for Fund/Campaign Deletion (2247)
Add Dynamic text for Breadcrumbs in Fund/Campaign/Pledges (2247) Unclear if breadcrumb functionality was addressed.

🐰 "In fields of green, I hop with glee,
No more deletions, just let it be!
Funds and campaigns, they flourish and thrive,
With names that sparkle, they come alive!
A joyful change, oh what a sight,
Hopping through code, everything feels right!" 🌼


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if 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. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

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

@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, codebase verification and nitpick comments (2)
src/screens/FundCampaignPledge/FundCampaignPledge.tsx (2)

Line range hint 133-146: Overall Assessment of Dynamic Breadcrumbs

The changes made to implement dynamic breadcrumbs are well-integrated within the component. The use of React's useMemo for deriving fundName and its subsequent use in the Breadcrumbs component enhances the application's usability by providing context-specific navigation paths.

It's recommended to add further comments in the code explaining the choice of history.go(-2) and history.back() for future maintainability.

Also applies to: 397-408


Line range hint 133-146: Refactor Suggestion for useMemo Hook

While the current implementation of the useMemo hook is functional, consider refactoring it for better readability and efficiency. Specifically, the nested function calls and operations within the filter callback can be simplified or broken down into smaller, more manageable functions.

Here's a suggested refactor for clarity:

- const { pledges, totalPledged, fundName } = useMemo(() => {
-   let totalPledged = 0;
-   const pledges =
-     pledgeData?.getFundraisingCampaigns[0].pledges.filter((pledge) => {
-       totalPledged += pledge.amount;
-       const search = searchTerm.toLowerCase();
-       return pledge.users.some((user) => {
-         const fullName = `${user.firstName} ${user.lastName}`;
-         return fullName.toLowerCase().includes(search);
-       });
-     }) ?? [];
-   const fundName =
-     pledgeData?.getFundraisingCampaigns[0].fundId.name ?? tCommon('Funds');
-   return { pledges, totalPledged, fundName };
- }, [pledgeData, searchTerm]);
+ const calculatePledges = (pledges, searchTerm) => {
+   let total = 0;
+   const filteredPledges = pledges.filter((pledge) => {
+     total += pledge.amount;
+     const search = searchTerm.toLowerCase();
+     return pledge.users.some((user) => {
+       const fullName = `${user.firstName} ${user.lastName}`;
+       return fullName.toLowerCase().includes(search);
+     });
+   });
+   return { filteredPledges, total };
+ };
+ const { pledges, totalPledged, fundName } = useMemo(() => {
+   const { filteredPledges, total } = calculatePledges(
+     pledgeData?.getFundraisingCampaigns[0].pledges ?? [],
+     searchTerm
+   );
+   const fundName =
+     pledgeData?.getFundraisingCampaigns[0].fundId.name ?? tCommon('Funds');
+   return { pledges: filteredPledges, totalPledged: total, fundName };
+ }, [pledgeData, searchTerm]);

This refactor separates the logic for filtering pledges and calculating the total pledged amount into a separate function, improving the readability and maintainability of the code.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 190e5e3 and 778fc7b.

Files selected for processing (12)
  • src/GraphQl/Mutations/CampaignMutation.ts (1 hunks)
  • src/GraphQl/Mutations/FundMutation.ts (1 hunks)
  • src/GraphQl/Queries/fundQueries.ts (2 hunks)
  • src/screens/FundCampaignPledge/FundCampaignPledge.tsx (4 hunks)
  • src/screens/FundCampaignPledge/PledgesMocks.ts (5 hunks)
  • src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx (8 hunks)
  • src/screens/OrganizationFundCampaign/OrganizationFundCampaign.test.tsx (1 hunks)
  • src/screens/OrganizationFundCampaign/OrganizationFundCampaignMocks.ts (10 hunks)
  • src/screens/OrganizationFunds/OrganizationFunds.test.tsx (1 hunks)
  • src/screens/OrganizationFunds/OrganizationFunds.tsx (7 hunks)
  • src/screens/OrganizationFunds/OrganizationFundsMocks.ts (3 hunks)
  • src/utils/interfaces.ts (2 hunks)
Files skipped from review due to trivial changes (3)
  • src/screens/OrganizationFundCampaign/OrganizationFundCampaign.test.tsx
  • src/screens/OrganizationFunds/OrganizationFunds.test.tsx
  • src/screens/OrganizationFunds/OrganizationFundsMocks.ts
Additional context used
Learnings (5)
src/GraphQl/Mutations/FundMutation.ts (1)
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFunds/FundDeleteModal.tsx:1-2
Timestamp: 2024-06-30T21:44:39.912Z
Learning: The folder containing mutation queries in the codebase is named `GraphQl`, not `graphql`.
src/GraphQl/Mutations/CampaignMutation.ts (1)
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFundCampaign/CampaignDeleteModal.tsx:4-5
Timestamp: 2024-06-30T21:17:16.481Z
Learning: The folder containing mutation queries in the codebase is named `GraphQl`, not `graphql`.
src/screens/OrganizationFundCampaign/OrganizationFundCampaignMocks.ts (2)
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFundCampaign/CampaignDeleteModal.tsx:4-5
Timestamp: 2024-06-30T21:17:16.481Z
Learning: The folder containing mutation queries in the codebase is named `GraphQl`, not `graphql`.
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFunds/FundDeleteModal.tsx:1-2
Timestamp: 2024-06-30T21:44:39.912Z
Learning: The folder containing mutation queries in the codebase is named `GraphQl`, not `graphql`.
src/screens/OrganizationFunds/OrganizationFunds.tsx (4)
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFunds/OrganizationFunds.tsx:66-72
Timestamp: 2024-06-30T21:27:17.104Z
Learning: Renaming the Enum `Modal` to `ModalState` in the `organizationFunds` component is unnecessary and does not change the functionality.
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFunds/FundDeleteModal.tsx:30-42
Timestamp: 2024-06-30T21:45:15.681Z
Learning: GlenDsza prefers using direct server response messages for error handling in toast notifications without additional contextual strings.
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFunds/FundDeleteModal.tsx:1-2
Timestamp: 2024-06-30T21:44:39.912Z
Learning: The folder containing mutation queries in the codebase is named `GraphQl`, not `graphql`.
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx:43-46
Timestamp: 2024-06-30T21:50:22.966Z
Learning: GlenDsza prefers descriptive and consistent naming for enum values in modal states, as demonstrated in the PR PalisadoesFoundation/talawa-admin#2064.
src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx (2)
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFunds/OrganizationFunds.tsx:66-72
Timestamp: 2024-06-30T21:27:17.104Z
Learning: Renaming the Enum `Modal` to `ModalState` in the `organizationFunds` component is unnecessary and does not change the functionality.
Learnt from: GlenDsza
PR: PalisadoesFoundation/talawa-admin#2064
File: src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx:43-46
Timestamp: 2024-06-30T21:50:22.966Z
Learning: GlenDsza prefers descriptive and consistent naming for enum values in modal states, as demonstrated in the PR PalisadoesFoundation/talawa-admin#2064.
Additional comments not posted (23)
src/GraphQl/Mutations/FundMutation.ts (2)

Line range hint 8-20: LGTM!

The CREATE_FUND_MUTATION is well-documented and correctly implemented.


Line range hint 22-38: LGTM!

The UPDATE_FUND_MUTATION is well-documented and correctly implemented.

src/GraphQl/Mutations/CampaignMutation.ts (2)

Line range hint 8-22: LGTM!

The CREATE_CAMPAIGN_MUTATION is well-documented and correctly implemented.


Line range hint 24-40: LGTM!

The UPDATE_CAMPAIGN_MUTATION is well-documented and correctly implemented.

src/GraphQl/Queries/fundQueries.ts (3)

Line range hint 10-34: LGTM!

The FUND_LIST query is well-documented and correctly implemented.


Line range hint 36-47: Enhanced Data Retrieval: Approved!

The modifications to the FUND_CAMPAIGN query, including the addition of name and isArchived fields, enhance the data retrieval capabilities and align with the PR objectives.


Line range hint 59-68: Enhanced Contextual Data: Approved!

The modifications to the FUND_CAMPAIGN_PLEDGE query, including the addition of a nested field fundId that retrieves the name of the associated fund, provide more context about the fundraising campaigns and enhance the overall utility of the query.

src/screens/OrganizationFundCampaign/OrganizationFundCampaignMocks.ts (6)

20-21: Approved: Addition of name and isArchived fields.

The addition of name and isArchived fields to the mock data is consistent with the PR's objectives to enhance the detail and usability of the data. Ensure that these fields are consistently used across all relevant mock data instances.


56-57: Approved: Consistent addition of fields in mock data.

The name and isArchived fields are consistently added here as in the first instance, which is crucial for maintaining uniform behavior across tests and components using this mock data.


84-85: Approved: Consistent addition of fields in mock data.

The addition of name and isArchived fields here is consistent with other instances, ensuring uniform behavior across the application's components and tests.


120-121: Approved: Consistent addition of fields in mock data.

The consistent addition of name and isArchived fields across all instances ensures that the mock data accurately reflects the intended changes and supports the dynamic nature of the application's UI.


156-157: Approved: Consistent addition of fields in mock data.

The addition of name and isArchived fields here is consistent with other instances, ensuring uniform behavior across the application's components and tests.


192-193: Approved: Consistent addition of fields in mock data.

The addition of name and isArchived fields here is consistent with other instances, ensuring uniform behavior across the application's components and tests.

src/utils/interfaces.ts (2)

288-289: Approved: Interface additions for better data handling.

The additions of name and isArchived to the InterfaceQueryOrganizationFundCampaigns are well-aligned with the PR's objectives to enhance data representation. Ensure these new fields are utilized appropriately across the application.

Run the following script to verify the usage of the new fields:

Verification successful

Verified: Fields name and isArchived are well-integrated.

The fields name and isArchived are extensively used across the application, including in interfaces, test files, screen components, and GraphQL queries and mutations. This confirms their appropriate integration into the application's data model and logic. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `name` and `isArchived` fields in the application.

# Test: Search for the usage of the new fields. Expect: References in queries and components.
rg --type typescript -A 5 $'name' | rg --type typescript -A 5 $'isArchived'

Length of output: 141


Script:

#!/bin/bash
# Description: Verify the usage of `name` and `isArchived` fields in the application.

# Corrected Test: Search for the usage of the new fields. Expect: References in queries and components.
rg --type ts -A 5 'name' | rg --type ts -A 5 'isArchived'

Length of output: 13979


309-311: Approved: Enhanced linkage between pledges and funds.

The addition of the fundId object with a name property in the InterfaceQueryFundCampaignsPledges interface enhances data clarity by explicitly linking pledges to their respective funds. Verify that this new structure is integrated correctly in the application's data handling.

Run the following script to verify the integration of the new fundId structure:

Verification successful

Integration of fundId is consistent and successful across the application.

The fundId structure is well-integrated into the application's routing, data handling, and UI components. This includes its presence in GraphQL queries and mutations, test files, and various components. The integration aligns with the application's architecture and data handling strategy.

  • Files with fundId references:
    • src/App.tsx
    • src/GraphQl/Queries/fundQueries.ts
    • src/GraphQl/Mutations/CampaignMutation.ts
    • src/screens/OrganizationFundCampaign/CampaignModal.test.tsx
    • src/screens/OrganizationFundCampaign/OrganizationFundCampaignMocks.ts
    • src/screens/OrganizationFunds/OrganizationFunds.tsx
    • src/screens/FundCampaignPledge/FundCampaignPledge.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `fundId` structure in the application.

# Test: Search for the usage of `fundId`. Expect: References in queries and components.
rg --type typescript -A 5 $'fundId'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify the integration of `fundId` structure in the application.

# Test: Search for the usage of `fundId`. Expect: References in queries and components.
rg --type ts -A 5 $'fundId'

Length of output: 28429

src/screens/FundCampaignPledge/PledgesMocks.ts (2)

65-67: Consistent addition of fundId, but verify flexibility.

The addition of fundId with a hardcoded value 'Fund 1' across multiple instances in the MOCKS array is consistent and appears correctly implemented. However, consider verifying if this hardcoded value limits the flexibility of the mock data, especially in diverse testing scenarios.

Also applies to: 124-126, 183-185, 296-298


403-405: Consistent addition of fundId in EMPTY_MOCKS.

The addition of fundId with a hardcoded value 'Fund 1' in the EMPTY_MOCKS array is consistent with the changes made in the MOCKS array. This change enhances the structure of the mock data by associating a fund identifier with each campaign. However, ensure that this hardcoded value does not limit the flexibility of the mock data in testing scenarios.

src/screens/FundCampaignPledge/FundCampaignPledge.tsx (2)

Line range hint 133-146: Dynamic Breadcrumbs Implementation

The implementation of dynamic breadcrumbs using the fundName variable is well done. The useMemo hook efficiently calculates fundName based on the available pledgeData. This change aligns with the PR objectives to make breadcrumb navigation dynamic and context-aware.

However, it's important to ensure that the fallback text (tCommon('Funds')) is appropriate and that all translations are available for this text to maintain i18n standards.


Line range hint 397-408: Usage of Dynamic Breadcrumbs in JSX

The dynamic text for breadcrumbs is correctly implemented in the JSX. The fundName and campaignInfo.name are used to render the breadcrumb links dynamically. This is a crucial part of enhancing user navigation as per the PR objectives.

Ensure that the onClick handlers for these links are correctly managing navigation history. The use of history.go(-2) and history.back() might need careful testing to ensure they behave as expected across different browsers and navigation scenarios.

Consider adding automated tests to verify the correct behavior of these navigation handlers across different user navigation paths and browser environments.

src/screens/OrganizationFunds/OrganizationFunds.tsx (2)

94-105: Approved: Updated modal handling logic.

The handleOpenModal function has been simplified to directly manage the modal state, making the component easier to maintain and understand. The use of useCallback with an empty dependency array is appropriate here, ensuring the function is not recreated unnecessarily.


43-47: Approved: Removal of deletion functionality and simplification of modal management.

The changes correctly implement the PR's objectives by removing the deletion functionality and simplifying the modal management to a boolean state. The documentation has been updated accordingly.

Run the following script to ensure that no other parts of the codebase are attempting to use the removed handleDeleteClick function or ModalState enum:

Also applies to: 66-66, 94-94, 103-103, 372-373

src/screens/OrganizationFundCampaign/OrganizationFundCampagins.tsx (2)

94-105: Approved: Updated modal handling logic.

The handleOpenModal function has been simplified to directly manage the modal state, making the component easier to maintain and understand. The use of useCallback with an empty dependency array is appropriate here, ensuring the function is not recreated unnecessarily.


47-53: Approved: Removal of deletion functionality and simplification of modal management.

The changes correctly implement the PR's objectives by removing the deletion functionality and simplifying the modal management to a boolean state. The documentation has been updated accordingly.

Run the following script to ensure that no other parts of the codebase are attempting to use the removed handleDeleteClick function or ModalState enum:

Also applies to: 60-60, 94-94, 103-103, 442-443

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.44%. Comparing base (190e5e3) to head (778fc7b).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2248      +/-   ##
===========================================
- Coverage    97.45%   97.44%   -0.02%     
===========================================
  Files          241      239       -2     
  Lines         6887     6841      -46     
  Branches      2000     2006       +6     
===========================================
- Hits          6712     6666      -46     
  Misses         161      161              
  Partials        14       14              

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

@GlenDsza
Copy link
Author

GlenDsza commented Sep 7, 2024

@tasneemkoushar Pls Review

@tasneemkoushar tasneemkoushar merged commit 07870fd into PalisadoesFoundation:develop Sep 8, 2024
12 checks passed
@GlenDsza GlenDsza deleted the fcp_suggestion branch September 8, 2024 12:53
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