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

Website: Clean up RecipientStatsCalculator and various small fixes/adjustments #1045

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

mkue
Copy link
Contributor

@mkue mkue commented Feb 13, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted redirection on the recipient selection page to prevent unintended navigation.
  • Refactor

    • Improved recipient statistics calculations for a more accurate and detailed breakdown across partner and financial transparency views.
  • Style

    • Reorganized the navigation dropdown to display the Journal link first and position the My Profile link at the bottom with enhanced spacing.

Copy link

vercel bot commented Feb 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
public ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 13, 2025 8:37am

Copy link

coderabbitai bot commented Feb 13, 2025

📝 Walkthrough

Walkthrough

The changes enhance type safety, refactor recipient statistics processing, adjust test cases, and update UI components. The campaign_path now explicitly references a Campaign. The recipient statistics calculator and its tests have been renamed and streamlined to use new Firestore references. Additionally, the GlowHoverCard component no longer uses ref forwarding, and several website components have been modified to integrate the updated statistics logic, enforce conditional redirects based on currency, and reorder navigation dropdown items.

Changes

File(s) Change Summary
shared/.../contribution.ts Updated campaign_path type from DocumentReference to DocumentReference<Campaign> in BaseContribution.
shared/.../RecipientStatsCalculator.ts
shared/.../RecipientStatsCalculator.test.ts
Renamed methods and interfaces in the recipient statistics calculator and refactored tests to use Firestore collection references and simplified test data insertion.
ui/.../glow-hover-card.tsx Changed component declaration from React.forwardRef to React.FC, removing ref forwarding while retaining the displayName.
website/.../ngolist.tsx
website/.../section-1.tsx
website/.../page.tsx
website/.../navbar-client.tsx
Updated recipient statistics access and calculations, introduced conditional redirect logic based on the currency, and reordered navigation dropdown links with adjusted spacing.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant Calculator as RecipientStatsCalculator
    UI->>Calculator: Call allStats()
    Calculator->>Calculator: Compute recipientsCountByStatus()
    Calculator->>Calculator: Compute recipientsCountByOrganisationAndStatus()
    Calculator-->>UI: Return aggregated stats
Loading
sequenceDiagram
    participant Page
    participant Redirector
    Page->>Page: Evaluate currency value
    alt Currency is truthy
        Page->>Redirector: Invoke redirect()
    else Currency is falsy
        Note right of Page: No redirect occurs
    end
Loading

Suggested labels

feature

Suggested reviewers

  • andrashee
  • socialincome-dev
  • ssandino
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 2

🧹 Nitpick comments (1)
ui/src/components/card/glow-hover-card.tsx (1)

13-13: Consider using modern ref patterns.

The LegacyRef type casting could be replaced with React.RefObject for better type safety.

-ref={refCard as LegacyRef<HTMLDivElement>}
+ref={refCard as React.RefObject<HTMLDivElement>}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a127f8 and c2dbcf3.

📒 Files selected for processing (8)
  • shared/src/types/contribution.ts (2 hunks)
  • shared/src/utils/stats/RecipientStatsCalculator.test.ts (6 hunks)
  • shared/src/utils/stats/RecipientStatsCalculator.ts (1 hunks)
  • ui/src/components/card/glow-hover-card.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/partners/(sections)/ngolist.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx (1 hunks)
  • website/src/components/navbar/navbar-client.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx (1)
Learnt from: DarkMenacer
PR: socialincome-san/public#1001
File: website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx:10-12
Timestamp: 2025-01-08T15:36:41.682Z
Learning: In Next.js, when implementing redirects where you don't want the current URL to be stored in browser history (e.g., intermediate pages), use `redirect` from 'next/navigation' instead of `useRouter.push()`. This prevents the back button from getting stuck in a redirect loop and provides a more intuitive navigation experience.
🪛 Biome (1.9.4)
shared/src/utils/stats/RecipientStatsCalculator.ts

[error] 42-42: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 54-54: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 57-57: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Test website
  • GitHub Check: Test shared code
  • GitHub Check: Test functions
  • GitHub Check: Test admin
  • GitHub Check: Prettify
  • GitHub Check: Security checks (typescript)
🔇 Additional comments (8)
shared/src/types/contribution.ts (2)

2-2: LGTM!

Clean import addition for Campaign type.


37-37: LGTM! Type safety improvement.

Good refinement of campaign_path to explicitly reference Campaign documents.

website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx (1)

10-12: LGTM! Good use of conditional redirect.

The code correctly uses redirect from 'next/navigation' and includes a proper currency check.

website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx (1)

41-44: LGTM! Good use of type-safe enums.

The calculation correctly excludes waitlisted recipients using the RecipientProgramStatus enum.

website/src/app/[lang]/[region]/(website)/partners/(sections)/ngolist.tsx (1)

48-49: LGTM: Enhanced recipient statistics access

The change to use recipientsCountByOrganisationAndStatus provides more detailed recipient data by status.

shared/src/utils/stats/RecipientStatsCalculator.test.ts (2)

31-41: LGTM: Improved organization references

Using proper Firestore references instead of inline objects enhances type safety and maintainability.


135-167: LGTM: Comprehensive test coverage

The test cases thoroughly verify:

  • Total recipient counts
  • Distribution by status
  • Organization-specific counts
  • Edge cases (undefined statuses)
website/src/components/navbar/navbar-client.tsx (1)

292-296: LGTM: Improved navigation structure

The reordering of links and addition of spacing enhances the visual hierarchy and user experience.

@mkue mkue enabled auto-merge (squash) February 13, 2025 08:34
@mkue mkue disabled auto-merge February 13, 2025 08:35
Copy link

Visit the preview URL for this PR (updated for commit c2dbcf3):

https://si-admin-staging--pr1045-michael-cleanup-reci-95krfwp3.web.app

(expires Thu, 20 Feb 2025 08:36:46 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

@mkue mkue merged commit dd2e3fb into main Feb 13, 2025
19 checks passed
@mkue mkue deleted the michael/cleanup-recipients-stats-calculator branch February 13, 2025 08:37
<div className="absolute left-0 mt-[50px] hidden flex-col justify-start overflow-visible whitespace-nowrap group-hover/navbar:flex group-active/navbar:flex">
<NavbarLink href={`/${lang}/${region}/me`}>{translations.myProfile}</NavbarLink>
<div className="absolute left-0 mt-[50px] hidden flex-col justify-start space-y-2 overflow-visible whitespace-nowrap group-hover/navbar:flex group-active/navbar:flex">
<NavbarLink href={`/${lang}/${region}/journal`}>{translations.journal}</NavbarLink>
Copy link
Member

Choose a reason for hiding this comment

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

Placing the journal link at the top level was intentional (discussed with @Gavriil-Tzortzakis, @ssandino and Katie, who made the changes in the Figma). However, we can revisit this in a later commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, sorry🙃 The spacing is too narrow imo, and also the Donate with the yellow font in the middle looks a bit strange in my eyes. I'll revert.

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