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 placeholder if select value is undefined #16462

Merged
merged 8 commits into from
Oct 21, 2024

Conversation

helgifr
Copy link
Member

@helgifr helgifr commented Oct 18, 2024

...

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:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Enhanced the IncomePlanForm to handle null values for income type and currency fields, improving data validation.
    • Updated the SelectController to gracefully manage undefined or null values, enhancing user experience during selection.
  • Bug Fixes

    • Improved error handling in SelectController for value management, ensuring correct behavior when no value is selected.

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 36.74%. Comparing base (e9edd28) to head (e4f4e68).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...elds/src/lib/SelectController/SelectController.tsx 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-api-files 56.86% <ø> (ø)
application-system-api 41.36% <ø> (ø)
application-template-api-modules 27.81% <ø> (+0.01%) ⬆️
application-templates-accident-notification 29.27% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-driving-license 18.32% <ø> (ø)
application-templates-estate 12.32% <0.00%> (-0.01%) ⬇️
application-templates-financial-aid 15.50% <ø> (ø)
application-templates-general-petition 23.44% <ø> (ø)
application-templates-inheritance-report 6.49% <ø> (ø)
application-templates-marriage-conditions 15.17% <ø> (ø)
application-templates-mortgage-certificate 43.82% <ø> (ø)
application-templates-parental-leave 29.96% <ø> (ø)
application-ui-components 1.28% <ø> (ø)
application-ui-shell 21.36% <0.00%> (-0.01%) ⬇️
shared-form-fields 31.60% <50.00%> (+0.01%) ⬆️
web 1.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...elds/src/lib/SelectController/SelectController.tsx 55.17% <50.00%> (-0.39%) ⬇️

... and 46 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9edd28...e4f4e68. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 18, 2024

Datadog Report

All test runs 0210db0 🔗

16 Total Test Services: 0 Failed, 15 Passed
🔻 Test Sessions change in coverage: 3 decreased, 2 increased, 73 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.64s 1 no change Link
application-api-files 0 0 0 12 0 6.94s 1 no change Link
application-system-api 0 0 0 120 2 3m 3.68s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 46.32s 1 increased (+0.01%) Link
application-templates-accident-notification 0 0 0 148 0 22.16s 1 no change Link
application-templates-driving-license 0 0 0 13 0 15.46s 1 no change Link
application-templates-financial-aid 0 0 0 11 0 14.41s 1 no change Link
application-templates-general-petition 0 0 0 5 0 10.65s 1 no change Link
application-templates-health-insurance 0 0 0 0 0 513.85ms 1 no change Link
application-templates-mortgage-certificate 0 0 0 3 0 22.73s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • application-templates-social-insurance-administration-income-plan - jest 30.4% (-0.12%) - Details
  • application-ui-shell - jest 27.99% (-0.01%) - Details
  • application-templates-estate - jest 18.93% (-0.01%) - Details

@ylfahfa ylfahfa marked this pull request as ready for review October 21, 2024 13:18
@ylfahfa ylfahfa requested review from a team as code owners October 21, 2024 13:18
@ylfahfa ylfahfa requested a review from johannaagma October 21, 2024 13:18
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Walkthrough

The pull request introduces modifications to the IncomePlanForm and SelectController components. In IncomePlanForm, updates to the valueModifier functions for the incomeType and currency fields change return values from empty strings to null. The updateValueObj for certain fields is refined for consistency in data types. In SelectController, the getValue function is enhanced to handle undefined or null values, improving the robustness of value processing.

Changes

File Change Summary
libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts Updated valueModifier functions for incomeType and currency to return null instead of empty strings; refined updateValueObj for consistency in certain fields.
libs/shared/form-fields/src/lib/SelectController/SelectController.tsx Modified getValue function to handle undefined and null values, enhancing error handling in the onChange handler.

Possibly related PRs

Suggested reviewers

  • Toti91

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 46d6329 and ae37c2b.

📒 Files selected for processing (1)
  • libs/shared/form-fields/src/lib/SelectController/SelectController.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/shared/form-fields/src/lib/SelectController/SelectController.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.

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

🧹 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 types

The change to return null instead of an empty string for foreign income types aligns with the improvements made to the incomeType 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 calculations

The updates to equalForeignIncomePerMonth and equalIncomePerMonth 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 and equalIncomePerMonth 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

📥 Commits

Files that changed from the base of the PR and between b97aca7 and 46d6329.

📒 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 simplification

The addition of explicit checks for undefined and null values improves the robustness of the getValue 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 from getValue 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 values

The 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.

Copy link
Member

@ylfahfa ylfahfa left a comment

Choose a reason for hiding this comment

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

lgtm 😄

@ylfahfa ylfahfa added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 21, 2024
@kodiakhq kodiakhq bot merged commit 16a862a into main Oct 21, 2024
80 checks passed
@kodiakhq kodiakhq bot deleted the fix/select-placeholder-for-undefined branch October 21, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants