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: Transparency page (fixing bugs) #972

Merged
merged 4 commits into from
Dec 10, 2024

Conversation

dnhn
Copy link
Member

@dnhn dnhn commented Dec 6, 2024

Fixes #728

i18next currency options inherits number options from Intl.NumberFormat
https://www.i18next.com/translation-function/formatting#currency
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

I have also fixed the rounding function to avoid NaN if the value does not exist, we can see it happens on the staging site.
https://staging.socialincome.org/en/int/transparency/finances/usd

Screenshot 2024-12-06 at 14 05 46

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in amount rounding to prevent issues with invalid inputs.
    • Updated formatting for displayed contributions and financial amounts to show whole numbers without decimals across multiple sections.
  • Bug Fixes

    • Improved robustness of the financial calculations by ensuring proper handling of falsy values.
  • Documentation

    • Clarified context properties in translation functions for better numerical output formatting.

Copy link

vercel bot commented Dec 6, 2024

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 Dec 6, 2024 3:26pm

Copy link

vercel bot commented Dec 6, 2024

@dnhn is attempting to deploy a commit to the Social Income Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Dec 6, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the roundAmount function for better error handling by returning 0 for falsy inputs. Additionally, it modifies several sections (Section1, Section2, Section3, and Section4) to include a maximumFractionDigits: 0 property in the context objects for translation functions. This ensures that all displayed amounts are rounded to whole numbers, improving the formatting of numerical outputs across the transparency page.

Changes

File Path Change Summary
website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx Updated roundAmount function to return 0 for falsy values.
website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-2.tsx Added maximumFractionDigits: 0 to various contexts for contribution amounts.
website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-3.tsx Added maximumFractionDigits: 0 to translation context for total amounts, removing contributorsCount.
website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-4.tsx Enhanced translation contexts with maximumFractionDigits: 0 for various financial amounts and updated reserves title.

Assessment against linked issues

Objective Addressed Explanation
Remove decimal places on transparency page (#728)

Suggested labels

website

Suggested reviewers

  • andrashee
  • ssandino
  • mkue
  • socialincome-dev

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c400a35 and 24bea76.

📒 Files selected for processing (1)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai 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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 43c070f and dc1994f.

📒 Files selected for processing (4)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx (2 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-2.tsx (7 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-3.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-4.tsx (13 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx

[error] 6-6: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

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

25-25: LGTM: Currency formatting configuration

The addition of maximumFractionDigits: 0 correctly implements the requirement to remove decimal places.

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

21-25: LGTM: Consistent currency formatting across all displays

The addition of maximumFractionDigits: 0 is consistently applied to all currency amounts, ensuring uniform display without decimal places throughout the section.

Also applies to: 37-37, 52-52, 63-63, 78-78, 93-93, 102-102

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

37-40: LGTM: Currency formatting in country cards

The addition of maximumFractionDigits: 0 maintains consistent currency formatting across country cards.

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

32-32: LGTM: Expenses formatting aligns with requirements

The addition of maximumFractionDigits: 0 correctly implements the decimal place removal requirement.


Line range hint 45-68: LGTM: Payment amounts consistently formatted

All payment-related amounts (total payments, last month's payments, and future payments) now consistently use maximumFractionDigits: 0.


83-83: LGTM: Project costs and fees formatting standardized

All financial metrics (project costs, donation fees, delivery fees, exchange rate loss, account fees) consistently implement the decimal place removal.

Also applies to: 93-93, 110-110, 127-127, 144-144


215-219: LGTM: Reserves formatting matches specification

The reserves amount formatting correctly implements the decimal removal requirement while maintaining the calculation logic.


Line range hint 1-255: Verify consistency across other sections

Let's ensure this decimal place removal is consistently implemented across all other sections of the transparency page.

✅ Verification successful

All sections consistently use maximumFractionDigits: 0

The search results confirm that all sections (1-4) in the transparency/finances pages consistently implement maximumFractionDigits: 0 for currency formatting.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other currency formatting implementations
rg "maximumFractionDigits" --type ts

Length of output: 2755


159-163: Verify staff costs calculation

While the formatting is correct, let's ensure the staff costs calculation is accurate since it affects transparency reporting.

✅ Verification successful

Let me search for the calculation logic to verify this properly.


Staff costs calculation is correctly implemented

The calculation is accurate and well-structured:

  • Expenses are stored in CHF and properly converted using exchange rates
  • Staff costs are aggregated using lodash's sumBy function
  • The type system ensures proper categorization via ExpenseType enum
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for staff costs calculation logic
rg -A 5 "staff.*costs" --type ts

Length of output: 1603


Script:

#!/bin/bash
# Search for the expenses stats type definition and calculation
rg -l "totalExpensesByType" --type ts

# Then cat the relevant files to see the calculation logic
ast-grep --pattern 'interface $_ {
  totalExpensesByType: {
    $$$
  }
}'

Length of output: 342


Script:

#!/bin/bash
# Let's examine the expenses calculator implementation
cat shared/src/utils/stats/ExpensesStatsCalculator.ts

Length of output: 2183


Script:

#!/bin/bash
# Let's check the expense type definition
cat shared/src/types/expense.ts

Length of output: 443

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@ssandino
Copy link
Member

ssandino commented Dec 6, 2024

@dnhn Great. Getting rid of the decimal places is working. The Check amount to avoid NaN seems not yet to catch the NaN

Left = new
Screenshot 2024-12-06 at 14 13 24

@ssandino
Copy link
Member

ssandino commented Dec 6, 2024

Great @dnhn that fixed it: https://public-git-fork-dnhn-nhan-transparency-decimal-social-income.vercel.app/en/ch/transparency/finances/chf

@ssandino ssandino added the website Issues concerning Website label Dec 6, 2024
Copy link
Contributor

@mkue mkue left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks for picking this up :)

@mkue mkue merged commit 9014645 into socialincome-san:main Dec 10, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
website Issues concerning Website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Website Refactor]: Remove decimal places on transparency page
3 participants