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(income-plan): amend dynamic eligible messages #16918

Merged
merged 6 commits into from
Nov 18, 2024

Conversation

ylfahfa
Copy link
Member

@ylfahfa ylfahfa commented Nov 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

    • Introduced a new constant for handling scenarios with no active applications.
    • Enhanced eligibility messaging to provide clearer context and additional conditions for ineligibility.
  • Updates

    • Updated messages for better clarity regarding income plan eligibility.
    • Added new localized messages to improve user understanding of application status.

These changes aim to streamline user interactions and improve the overall experience with the income plan functionalities.

@ylfahfa ylfahfa requested a review from a team as a code owner November 18, 2024 10:59
Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes in this pull request primarily involve updates to the logic in the IncomePlanForm.ts, focusing on the handling of income plan data. The extraction of incomePlanConditions has been removed, simplifying the data structure to utilize only latestIncomePlan. Additionally, a new constant NO_ACTIVE_APPLICATIONS has been introduced, and the eligibility logic has been refined to accommodate this constant. Updates to message localization enhance clarity regarding eligibility statuses, ensuring users receive comprehensive information about their applications.

Changes

File Change Summary
libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts Modified buildTableRepeaterField logic to use latestIncomePlan.year; adjusted condition and updateValueObj for fields; updated currency options and incomePerYear calculations.
libs/application/templates/social-insurance-administration/income-plan/src/lib/constants.ts Added new constant NO_ACTIVE_APPLICATIONS.
libs/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.ts Updated eligibility logic in eligibleText to include NO_ACTIVE_APPLICATIONS for nuanced messaging.
libs/application/templates/social-insurance-administration/income-plan/src/lib/messages.ts Modified existing messages for clarity; added new message isNotEligibleNoActiveApplicationDescription.

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • Toti91

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.

@ylfahfa ylfahfa added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 18, 2024
Copy link
Member

@helgifr helgifr left a comment

Choose a reason for hiding this comment

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

LGTM

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

🧹 Outside diff range and nitpick comments (4)
libs/application/templates/social-insurance-administration/income-plan/src/lib/constants.ts (1)

13-13: LGTM! Consider enhancing type safety.

The new constant follows the established naming pattern and is well-placed among other status-related constants. The individual export enables effective tree-shaking.

Consider using a string literal union type for better type safety and autocompletion:

export type ApplicationStatus = 'INCOME_PLANS_CLOSED' | 'NO_ACTIVE_APPLICATIONS';
export const INCOME_PLANS_CLOSED: ApplicationStatus = 'INCOME_PLANS_CLOSED';
export const NO_ACTIVE_APPLICATIONS: ApplicationStatus = 'NO_ACTIVE_APPLICATIONS';
libs/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.ts (1)

138-139: Consider refactoring for better maintainability

While the logic is correct, the nested ternary operators make the code harder to read and maintain. Consider refactoring this function for better clarity and maintainability.

Here's a suggested improvement:

-export const eligibleText = (externalData: ExternalData) => {
+export const getEligibilityMessage = (externalData: ExternalData): string => {
   const { isEligible } = getApplicationExternalData(externalData)
-  return isEligible.reasonCode === INCOME_PLANS_CLOSED
-    ? incomePlanFormMessage.pre.isNotEligibleClosedDescription
-    : isEligible.reasonCode === NO_ACTIVE_APPLICATIONS
-    ? incomePlanFormMessage.pre.isNotEligibleNoActiveApplicationDescription
-    : incomePlanFormMessage.pre.isNotEligibleDescription
+  
+  switch (isEligible.reasonCode) {
+    case INCOME_PLANS_CLOSED:
+      return incomePlanFormMessage.pre.isNotEligibleClosedDescription
+    case NO_ACTIVE_APPLICATIONS:
+      return incomePlanFormMessage.pre.isNotEligibleNoActiveApplicationDescription
+    default:
+      return incomePlanFormMessage.pre.isNotEligibleDescription
+  }
 }

Changes suggested:

  1. Renamed function to better reflect its purpose (handling error messages)
  2. Added return type annotation
  3. Replaced nested ternaries with more readable switch statement
libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (2)

Line range hint 72-84: Fix potential null reference when accessing latestIncomePlan.year

There's a risk of a runtime error when accessing latestIncomePlan.year if latestIncomePlan is empty. The empty check is performed but not used when accessing the year property.

Apply this diff to fix the issue:

 return {
   ...baseMessage,
   values: {
-    incomePlanYear: latestIncomePlan.year,
+    incomePlanYear: hasLatestIncomePlan ? latestIncomePlan.year : undefined,
   },
 }

Line range hint 249-266: Extract repeated condition logic into a helper function

The condition for checking uneven employment income is duplicated across multiple fields. This should be extracted into a helper function for better maintainability.

Create a new helper function:

const isUnevenEmploymentIncome = (activeField: any) => 
  activeField?.unevenIncomePerYear?.[0] !== YES ||
  (activeField?.incomeCategory !== INCOME &&
    activeField?.unevenIncomePerYear?.[0] === YES)

Then use it in the conditions:

 condition: (_, activeField) => {
-  const unevenAndEmploymentIncome =
-    activeField?.unevenIncomePerYear?.[0] !== YES ||
-    (activeField?.incomeCategory !== INCOME &&
-      activeField?.unevenIncomePerYear?.[0] === YES)
-
   return (
     activeField?.income === RatioType.MONTHLY &&
     activeField?.currency !== ISK &&
-    unevenAndEmploymentIncome
+    isUnevenEmploymentIncome(activeField)
   )
 }

Also applies to: 288-305

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 74eaed4 and 46c391a.

📒 Files selected for processing (4)
  • libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (2 hunks)
  • libs/application/templates/social-insurance-administration/income-plan/src/lib/constants.ts (1 hunks)
  • libs/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.ts (2 hunks)
  • libs/application/templates/social-insurance-administration/income-plan/src/lib/messages.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
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/application/templates/social-insurance-administration/income-plan/src/lib/constants.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/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.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/application/templates/social-insurance-administration/income-plan/src/lib/messages.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."
🔇 Additional comments (4)
libs/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.ts (2)

11-11: LGTM! Clean import addition

The new constant import follows the existing pattern and is logically grouped with related constants.


11-11: Verify the impact of these changes

Let's ensure all usages of eligibleText are aware of the new message case.

Also applies to: 138-139

✅ Verification successful

No impact on consumers - constants are properly handled

The eligibleText function already handles both INCOME_PLANS_CLOSED and NO_ACTIVE_APPLICATIONS cases correctly, returning appropriate messages for each case. The function implementation shows proper handling of all scenarios:

  • When reasonCode is INCOME_PLANS_CLOSED
  • When reasonCode is NO_ACTIVE_APPLICATIONS
  • Default case for other scenarios

The only consumer found (Prerequisites.ts) uses the function as intended, simply displaying the returned message.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of eligibleText to ensure consumers handle all cases
rg "eligibleText" --type ts

# Search for tests to ensure new case is covered
rg -t test "eligibleText|NO_ACTIVE_APPLICATIONS"

Length of output: 585


Script:

#!/bin/bash
# Search for the function implementation and its test coverage
rg "eligibleText" -A 10 --type typescript

# Search for the constants usage
rg "NO_ACTIVE_APPLICATIONS|INCOME_PLANS_CLOSED" --type typescript

# Look for test files with .spec or .test extension
fd ".(spec|test)\.(ts|tsx)$" | xargs rg "eligibleText|NO_ACTIVE_APPLICATIONS"

Length of output: 259


Script:

#!/bin/bash
# Search for the function implementation and its test coverage
rg "eligibleText" -A 10

# Search for the constants usage
rg "NO_ACTIVE_APPLICATIONS|INCOME_PLANS_CLOSED"

# Look for test files
fd ".(spec|test)\.(ts|tsx)$"

Length of output: 76494


Script:

#!/bin/bash
# Search for the implementation of eligibleText function and its test coverage
rg -A 10 "export const eligibleText" libs/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.ts

# Search for the test file content
rg -A 10 "eligibleText" libs/application/templates/social-insurance-administration/income-plan/src/lib/incomePlanUtils.spec.ts

# Search for all usages of the constants
rg "NO_ACTIVE_APPLICATIONS|INCOME_PLANS_CLOSED" -A 2

Length of output: 2489

libs/application/templates/social-insurance-administration/income-plan/src/lib/messages.ts (1)

27-29: LGTM! Clear and consistent error message.

The modified error message maintains a clear structure and consistent formatting while improving clarity about the reason for ineligibility.

libs/application/templates/social-insurance-administration/income-plan/src/forms/IncomePlanForm.ts (1)

Line range hint 1-600: Implementation follows best practices and guidelines

The form implementation:

  • Uses TypeScript effectively for type safety
  • Is modular and reusable across different NextJS apps
  • Handles complex conditional logic in a structured way
  • Provides clear field labels and tooltips for better user experience

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 36.34%. Comparing base (8825823) to head (be4674a).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...inistration/income-plan/src/lib/incomePlanUtils.ts 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16918      +/-   ##
==========================================
- Coverage   36.46%   36.34%   -0.13%     
==========================================
  Files        6903     6904       +1     
  Lines      144575   146171    +1596     
  Branches    41282    42111     +829     
==========================================
+ Hits        52715    53120     +405     
- Misses      91860    93051    +1191     
Flag Coverage Δ
api 3.34% <ø> (ø)
application-system-api 41.01% <50.00%> (-0.01%) ⬇️
application-template-api-modules 27.73% <50.00%> (+0.02%) ⬆️
application-templates-inheritance-report 6.52% <ø> (ø)
application-ui-shell 20.83% <ø> (ø)

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

Files with missing lines Coverage Δ
...ce-administration/income-plan/src/lib/constants.ts 100.00% <100.00%> (ø)
...nce-administration/income-plan/src/lib/messages.ts 100.00% <ø> (ø)
...inistration/income-plan/src/lib/incomePlanUtils.ts 19.60% <33.33%> (-0.81%) ⬇️

... and 95 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 8825823...be4674a. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 18, 2024

Datadog Report

All test runs 5e929c7 🔗

32 Total Test Services: 0 Failed, 31 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.1%), 1 increased (+0.27%), 148 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
air-discount-scheme-web 0 0 0 2 0 7.99s 1 no change Link
api 0 0 0 4 0 3.45s 1 no change Link
application-api-files 0 0 0 2 0 5.51s 1 no change Link
application-core 0 0 0 97 0 21.57s 1 decreased (-0.1%) Link
application-system-api 0 0 0 112 2 4m 0.72s 1 no change Link
application-template-api-modules 0 0 0 113 0 2m 35.47s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 20.52s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 13.16s 1 no change Link
application-templates-driving-license 0 0 0 13 0 16.57s 1 no change Link
application-templates-example-payment 0 0 0 2 0 11.7s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-core - jest 78.59% (-0.1%) - Details

@kodiakhq kodiakhq bot merged commit 16e6804 into main Nov 18, 2024
39 checks passed
@kodiakhq kodiakhq bot deleted the feat/ip-dynamic-eligible-messages branch November 18, 2024 13:52
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* use correct variable to determine ip year

* add option to dynamic eligible text

* format

* fix text

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Jan 16, 2025
6 tasks
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.

2 participants