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

fix: show correct unit type for manage projects list screen #2344

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

sunilsabatp
Copy link
Contributor

#FIxes -
This PR ensures the correct unit type is used for restoration projects (unit type: m²; purpose: trees) in the "Manage Project" section.

Copy link

vercel bot commented Dec 27, 2024

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

Name Status Preview Comments Updated (UTC)
planet-webapp-multi-tenancy-setup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2025 6:30am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
planet-webapp ⬜️ Ignored (Inspect) Jan 14, 2025 6:30am
planet-webapp-temp ⬜️ Ignored (Inspect) Jan 14, 2025 6:30am

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/eslint
npm error dev eslint@"^8.26.0" from the root project
npm error peer eslint@"6 || 7 || 8" from @emotion/[email protected]
npm error node_modules/@emotion/eslint-plugin
npm error dev @emotion/eslint-plugin@"^11.12.0" from the root project
npm error 15 more (@eslint-community/eslint-utils, ...)
npm error
npm error Could not resolve dependency:
npm error peer eslint@"^5.16.0 || ^6.8.0 || ^7.2.0" from [email protected]
npm error node_modules/eslint-config-airbnb
npm error dev eslint-config-airbnb@"^18.2.0" from the root project
npm error
npm error Conflicting peer dependency: [email protected]
npm error node_modules/eslint
npm error peer eslint@"^5.16.0 || ^6.8.0 || ^7.2.0" from [email protected]
npm error node_modules/eslint-config-airbnb
npm error dev eslint-config-airbnb@"^18.2.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /root/.npm/_logs/2025-01-14T06_12_39_731Z-eresolve-report.txt
npm error A complete log of this run can be found in: /root/.npm/_logs/2025-01-14T06_12_39_731Z-debug-0.log

Walkthrough

The pull request modifies the ProjectsContainer component and the Properties interface in the project type definitions. The changes include updating the UserProjectsType interface to allow properties to be either TreeProperties or ConservProperties. The SingleProject function is adjusted to handle these new types, with added logic for counting units based on the unitType. Additionally, the unitType property in the Properties interface is refined to a specific union type, and new interfaces for TreeProperties and ConservProperties are introduced.

Changes

File Change Summary
src/features/user/ManageProjects/ProjectsContainer.tsx Updated UserProjectsType to use `TreeProperties
src/features/common/types/project.d.ts Changed unitType from string to `'tree'

Possibly related PRs

Suggested labels

PR: reviewed-approved

Suggested reviewers

  • mohitb35

Poem

🌳 A rabbit's tale of trees and code so neat,
Flexible labels make the display complete!
From static to dynamic, a clever design,
Where 'm2' and 'trees' now smoothly align,
Coding magic with a furry delight! 🐰


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7055719 and 3af0095.

📒 Files selected for processing (1)
  • src/features/user/ManageProjects/ProjectsContainer.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
src/features/user/ManageProjects/ProjectsContainer.tsx (3)

3-6: LGTM! Type safety improvements.

The changes improve type safety by using specific TreeProperties and ConservProperties types instead of a generic Properties type.

Also applies to: 30-30


78-79: LGTM! Improved unit type display.

The implementation correctly follows the suggested approach of using translations for unit types, making the display more maintainable and consistent.


78-79: Verify translation keys for unit types.

Please ensure that the translation keys for both unit types are properly set up in the translation files:

  • unitTypes.tree
  • unitTypes.m2
✅ Verification successful

Translation keys for unit types are properly configured

The translation system is correctly set up with:

  • Proper keys for both unit types (tree, m2)
  • Pluralization support for tree counts
  • Consistent implementation across all supported languages
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if translation keys exist for both unit types
rg -g '*.json' -l "unitTypes.tree|unitTypes.m2"

Length of output: 49


Script:

#!/bin/bash
# First, find translation-related files
echo "=== Looking for translation files ==="
fd -e json -e yaml -e yml . | grep -i "translation\|locale\|lang"

echo -e "\n=== Searching for unit type related strings ==="
# Search with more variations of unit type translations
rg -g '*.{json,yaml,yml}' -i "unit.*type|tree|m2|meter|square"

Length of output: 72382


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
Collaborator

@mohitb35 mohitb35 left a comment

Choose a reason for hiding this comment

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

@sunilsabatp Please go through my feedback

Comment on lines 65 to 71
Number(project.countPlanted),
1
)}{' '}
{tCommon('tree', { count: Number(project.countPlanted) })}
{project.unitType === 'm2'
? tCommon(project.unitType)
: tCommon('tree', { count: Number(project.countPlanted) })}
</p>
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. I suggest simply using something like
    tCommon(project.unitType, {formattedCount, count})
    instead of handling different unitTypes in different ways. Make sure to not affect places that use the existing translation keys - you probably need new keys.

  2. API needs to be updated to return countPlanted / areaConserved etc. for unitType = 'm2'. This should consider conservation projects as well. Discuss this with @jmiridis

  3. Show the total units value if unitType is 'trees' or 'm2'.

  4. Update the type of project to reflect the API response. Be specific about the values unitType can take.

- Simplified translation key structure for unit types (tree, m2).
- Updated `TreeProperties` and `ConservProperties` interfaces to improve type safety.
- Refined count and formatted count logic using `useMemo` and conditional rendering.
- Enhanced translation key lookup for unit types using dynamic `unitTypes` object.
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

🧹 Nitpick comments (1)
src/features/common/types/project.d.ts (1)

121-133: Consider reusing the Units type for ConservProperties.

The separation of tree and conservation properties is well-structured. However, the ConservProperties interface could potentially reuse the Units type to maintain consistency and DRY principle.

Consider this alternative for ConservProperties:

 export interface ConservProperties extends Properties {
-  unitsContributed: {
-    m2: number;
-  };
-  unitsTargeted: {
-    m2: number;
-  };
+  unitsContributed: Pick<Units, 'm2'>;
+  unitsTargeted: Pick<Units, 'm2'>;
 }

This approach:

  1. Maintains consistency with TreeProperties
  2. Reuses the existing Units type
  3. Still enforces the m² requirement through Pick
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4629ba and 7055719.

⛔ Files ignored due to path filters (1)
  • public/static/locales/en/common.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • src/features/common/types/project.d.ts (2 hunks)
  • src/features/user/ManageProjects/ProjectsContainer.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/features/user/ManageProjects/ProjectsContainer.tsx
🔇 Additional comments (1)
src/features/common/types/project.d.ts (1)

104-104: LGTM! Verify the impact of this type restriction.

The change from string to literal union type improves type safety by restricting unitType to valid values.

Let's verify all usages of this property to ensure compatibility:

✅ Verification successful

Type restriction is safe and well-aligned with existing usage

The change from string to 'tree' | 'm2' is safe as all implementations already use these specific literals. The restriction improves type safety without breaking existing code:

  • Form controls in BasicDetails.tsx enforce the same literals
  • ProjectSnippet component uses compatible type definitions
  • Type definitions across the codebase are consistent with this change
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for unitType usage in the codebase
rg "unitType" --type ts --type tsx

Length of output: 62


Script:

#!/bin/bash
# Search for unitType usage without file type restrictions
rg "unitType" -l

# Use ast-grep to find property access and type annotations
ast-grep --pattern 'unitType:'
ast-grep --pattern '.unitType'

Length of output: 2848


Script:

#!/bin/bash
# Check type definitions in related .d.ts files
cat src/features/common/types/myForest.d.ts src/features/common/types/user.d.ts src/features/common/types/payments.d.ts src/features/common/types/map.d.ts src/features/common/types/redeem.d.ts

# Check implementation in key components
cat src/features/user/ManageProjects/components/BasicDetails.tsx src/features/projectsV2/ProjectSnippet/index.tsx

Length of output: 54332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants