-
Notifications
You must be signed in to change notification settings - Fork 61
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 placeholder if select value is undefined #16462
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16462 +/- ##
==========================================
- Coverage 36.78% 36.74% -0.05%
==========================================
Files 6845 6847 +2
Lines 141747 141852 +105
Branches 40380 40446 +66
==========================================
- Hits 52139 52117 -22
- Misses 89608 89735 +127
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 46 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 16 Total Test Services: 0 Failed, 15 Passed Test ServicesThis report shows up to 10 services
🔻 Code Coverage Decreases vs Default Branch (3) |
WalkthroughThe pull request introduces modifications to the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
libs/shared/form-fields/src/lib/SelectController/SelectController.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 and nitpick comments (2)
libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (2)
149-149
: Consistent handling of unselected currency for foreign income typesThe change to return
null
instead of an empty string for foreign income types aligns with the improvements made to theincomeType
field. This enhances type safety and provides a more accurate representation of the form state.Consider extracting the condition for foreign income types into a separate function to improve readability:
+ const isForeignIncomeType = (incomeType) => [ + FOREIGN_BASIC_PENSION, + FOREIGN_PENSION, + FOREIGN_INCOME, + INTEREST_ON_DEPOSITS_IN_FOREIGN_BANKS, + DIVIDENDS_IN_FOREIGN_BANKS + ].includes(incomeType); updateValueObj: { valueModifier: (_, activeField) => { - const defaultCurrency = - activeField?.incomeType === FOREIGN_BASIC_PENSION || - activeField?.incomeType === FOREIGN_PENSION || - activeField?.incomeType === FOREIGN_INCOME || - activeField?.incomeType === INTEREST_ON_DEPOSITS_IN_FOREIGN_BANKS || - activeField?.incomeType === DIVIDENDS_IN_FOREIGN_BANKS - ? null - : ISK + const defaultCurrency = isForeignIncomeType(activeField?.incomeType) ? null : ISK return defaultCurrency }, watchValues: 'incomeType', },
Line range hint
201-251
: Improved consistency in income calculationsThe updates to
equalForeignIncomePerMonth
andequalIncomePerMonth
fields enhance data type consistency and streamline the conditions for updating these fields. This improves the overall form data handling and validation process.For consistency, consider using the same approach for both
equalForeignIncomePerMonth
andequalIncomePerMonth
fields. You could extract the common logic into a separate function:const calculateMonthlyIncome = (yearlyIncome: number) => Math.round(yearlyIncome / 12).toString(); // Then use it in both fields: updateValueObj: { valueModifier: (_, activeField) => { if ( activeField?.income === RatioType.MONTHLY && activeField?.currency !== ISK && unevenAndEmploymentIncome ) { return calculateMonthlyIncome(Number(activeField?.incomePerYear)); } return undefined; }, // ... rest of the code },This approach would make the code more DRY and easier to maintain.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
- libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (2 hunks)
- libs/shared/form-fields/src/lib/SelectController/SelectController.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
libs/shared/form-fields/src/lib/SelectController/SelectController.tsx (2)
Pattern
libs/shared/**/*
: "Confirm that the code adheres to the following:
- Cross-application utility functions, types, and constants.
- TypeScript best practices to ensure type safety and reusability.
- Documentation and examples for library consumers."
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (2)
libs/shared/form-fields/src/lib/SelectController/SelectController.tsx (1)
60-63
: Approve changes with a suggestion for simplificationThe addition of explicit checks for
undefined
andnull
values improves the robustness of thegetValue
function, aligning with TypeScript best practices and the PR objective. Good job on enhancing error handling!However, we can simplify this check further, as suggested in a previous review:
-if (value === undefined || value === null) { +if (!value) { return null }This change maintains the same functionality while making the code more concise.
To ensure this change doesn't introduce any unintended side effects, let's verify how
null
is handled in the component:This will help us confirm that returning
null
fromgetValue
is handled correctly throughout the component.libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (1)
121-124
: Improved handling of unselected valuesThe change from returning an empty string to
null
for unmatched options enhances type safety and aligns with the PR's objective. This modification makes the code more robust and semantically correct for representing unselected values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 😄
...
Attach a link to issue if relevant
What
Specify what you're trying to achieve
Why
Specify why you need to achieve this
Screenshots / Gifs
Attach Screenshots / Gifs to help reviewers understand the scope of the pull request
Checklist:
Summary by CodeRabbit
New Features
IncomePlanForm
to handle null values for income type and currency fields, improving data validation.SelectController
to gracefully manage undefined or null values, enhancing user experience during selection.Bug Fixes
SelectController
for value management, ensuring correct behavior when no value is selected.