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: small cleanups #1046

Merged
merged 2 commits into from
Feb 13, 2025
Merged

Website: small cleanups #1046

merged 2 commits into from
Feb 13, 2025

Conversation

mkue
Copy link
Contributor

@mkue mkue commented Feb 13, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined the partners page by switching to a predefined list of NGO identifiers with improved data handling.
    • Updated the desktop navigation dropdown so that the profile link now appears above the journal link.
    • Enhanced error handling in the finances page by adding a conditional check for the currency variable before redirection.
  • Bug Fixes
    • Improved type safety in tests by adding non-null assertions to property accesses.
  • New Features
    • Updated the appearance of the Badge component in the finances section.

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 9:24am

Copy link

coderabbitai bot commented Feb 13, 2025

📝 Walkthrough

Walkthrough

The pull request removes the recipientNGOs constant from the shared types and updates its usage in the NGO list component. The NGO list file now uses a hardcoded array of NGO slugs with a streamlined mapping function and added error handling. Additionally, the type definition in the recipient statistics calculator has been updated for increased flexibility, and the navigation component has been adjusted by reordering links.

Changes

File(s) Change Summary
shared/src/…/recipient.ts
website/src/app/[lang]/[region]/…/ngolist.tsx
Removed the recipientNGOs constant and its import. In the NGO list, replaced dynamic import with a hardcoded array, refactored the iteration using map, and added a conditional check for recipient stats.
shared/src/…/RecipientStatsCalculator.ts Updated the type signature for OrganisationRecipientsByStatus to use a partial record with a required total property, allowing for optional keys.
website/src/components/navbar/…/navbar-client.tsx Reordered navigation links in the dropdown, moving the profile link above the journal link without affecting overall functionality.
shared/src/…/RecipientStatsCalculator.test.ts Added non-null assertion operators to enhance type safety when accessing properties of stats.recipientsCountByOrganisationAndStatus.
website/src/app/[lang]/[region]/…/transparency/finances/[currency]/section-1.tsx Modified the Badge component's variant prop and added a size prop, altering its appearance.
website/src/app/[lang]/[region]/…/transparency/finances/page.tsx Updated the useEffect logic to conditionally call redirect only when currency is truthy, improving error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Page
    participant NgoList
    participant StatsChecker
    participant Translator
    Page->>NgoList: Render component
    NgoList->>NgoList: Initialize hardcoded NGO list
    loop For each NGO
        NgoList->>StatsChecker: Retrieve recipient stats
        alt Stats exist
            StatsChecker-->>NgoList: Return stats
            NgoList->>Translator: Translate NGO info
            Translator-->>NgoList: Return translated info
        else No stats
            NgoList->>NgoList: Skip processing
        end
    end
    NgoList->>Page: Render NGO list
Loading

Possibly related PRs

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

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

39-40: Consider making NGO slugs configurable.

While hardcoding simplifies the code, consider moving the NGO slugs to a configuration file for better maintainability.

-const ngos = ['aurora', 'jamil', 'reachout', 'equal-rights', 'united-polio', 'slaes'];
+import { NGO_SLUGS } from '@/config/ngo-config';
+const ngos = NGO_SLUGS;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c70ce9a and 0fad18a.

📒 Files selected for processing (4)
  • shared/src/types/recipient.ts (0 hunks)
  • shared/src/utils/stats/RecipientStatsCalculator.ts (1 hunks)
  • website/src/app/[lang]/[region]/(website)/partners/(sections)/ngolist.tsx (3 hunks)
  • website/src/components/navbar/navbar-client.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • shared/src/types/recipient.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Test functions
  • GitHub Check: Test admin
  • GitHub Check: Test shared code
  • GitHub Check: Test website
  • GitHub Check: Prettify
  • GitHub Check: Security checks (typescript)
🔇 Additional comments (3)
shared/src/utils/stats/RecipientStatsCalculator.ts (1)

14-14: LGTM! Type definition improvement.

The change to Partial<Record> makes the type more flexible while maintaining the required total property.

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

49-49: LGTM! Good error handling.

The null check prevents runtime errors when organization stats are missing.

website/src/components/navbar/navbar-client.tsx (1)

292-301: LGTM! Navigation links reordered.

The reordering of navigation links improves the UI flow.

Copy link

github-actions bot commented Feb 13, 2025

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

https://si-admin-staging--pr1046-michael-cleanups-xvv87d8v.web.app

(expires Thu, 20 Feb 2025 09:24:12 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

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

🧹 Nitpick comments (3)
website/src/app/[lang]/[region]/(website)/transparency/finances/page.tsx (1)

7-12: Consider handling loading and error states.

The component could benefit from explicit loading and error state handling to improve user experience.

 export default function Page() {
 	const { currency } = useI18n();
+	const [isLoading, setIsLoading] = useState(true);
 
 	useEffect(() => {
+		setIsLoading(true);
 		if (currency) redirect('./finances/' + currency.toLowerCase());
+		setIsLoading(false);
 	}, [currency]);
+
+	if (isLoading) return <div>Loading...</div>;
+	if (!currency) return <div>Error: Currency not available</div>;
+
+	return null;
 }
shared/src/utils/stats/RecipientStatsCalculator.test.ts (2)

148-148: Consider using optional chaining instead of non-null assertions.

The non-null assertions (!) are used to bypass TypeScript's type checking. While this works, it's not the safest approach as it could lead to runtime errors if the properties are actually undefined.

Consider using optional chaining for safer property access:

-expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]!['total']).toEqual(1);
+expect(stats.recipientsCountByOrganisationAndStatus[org1Ref.id]?.['total']).toEqual(1);

Also applies to: 151-151, 156-162, 167-168


135-169: Add test coverage for edge cases.

The test covers the happy path but lacks coverage for edge cases such as:

  • Organizations with no recipients
  • Invalid organization IDs
  • All possible recipient statuses

Would you like me to generate additional test cases to cover these scenarios?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0fad18a and 3bb7a89.

📒 Files selected for processing (3)
  • shared/src/utils/stats/RecipientStatsCalculator.test.ts (1 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/[currency]/section-1.tsx (1 hunks)
  • website/src/app/[lang]/[region]/(website)/transparency/finances/page.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Test admin
  • GitHub Check: Test website
  • GitHub Check: Test functions
  • GitHub Check: Test shared code
  • GitHub Check: Prettify
  • GitHub Check: Security checks (typescript)
🔇 Additional comments (2)
website/src/app/[lang]/[region]/(website)/transparency/finances/page.tsx (1)

11-11: Good addition of the null check!

The conditional check prevents unnecessary redirects when currency is not available.

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

47-47: LGTM! UI refinement improves clarity.

The Badge styling changes improve the component's purpose as an informative label by removing unnecessary interactivity and ensuring consistent sizing.

@mkue mkue merged commit 23ef67c into main Feb 13, 2025
19 checks passed
@mkue mkue deleted the michael/cleanups branch February 13, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant