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

chore(driving-license): add delivery price if pickup = post selected #16194

Merged
merged 10 commits into from
Oct 3, 2024

Conversation

stjanilofts
Copy link
Member

@stjanilofts stjanilofts commented Sep 27, 2024

image

Summary by CodeRabbit

  • New Features

    • Enhanced payment charge calculation for driving license applications, improving clarity and handling of pickup scenarios.
    • Introduced constants for better management of charge item codes, including a new DELIVERY_FEE.
  • Bug Fixes

    • Adjusted logic to prevent potential errors from undefined values in total price calculations.
  • Refactor

    • Simplified method signatures for improved data access and readability.

@stjanilofts stjanilofts requested a review from a team as a code owner September 27, 2024 13:24
Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Walkthrough

The changes involve modifications to two files related to the driving license application forms. The subSectionSummary.ts file has updated the method signature and logic for calculating payment charges based on a new application data structure, simplifying data access and enhancing the handling of pickup options. The drivingLicenseTemplate.ts file has introduced a new variable for retrieving pickup information and adjusted the logic for determining charge item codes, returning an array of codes instead of a single value.

Changes

File(s) Change Summary
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts Updated method signature and logic for payment charge calculation, simplifying access to application data.
libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts Introduced a new variable for pickup options and modified the return value of the getCodes function to include a codes array.

Possibly related PRs

  • chore(driving-license): minor text changes  #16186: This PR modifies the logic for calculating and displaying price amounts in the subSectionSummary function, which is directly related to the changes made in the main PR regarding payment charge calculations and the handling of pickup options.

Suggested labels

automerge

Suggested reviewers

  • kksteini

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

🧹 Outside diff range and nitpick comments (1)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (1)

162-162: Add TypeScript type annotation to the application parameter

For better type safety and code clarity, consider adding a type annotation to the application parameter in the value function.

You can modify the function signature as:

-value: (application) => {
+value: (application: Application) => {

Ensure that Application is imported from @island.is/application/types if it's not already imported.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a8b2817 and 0a0fb8a.

📒 Files selected for processing (3)
  • libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts (0 hunks)
  • libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (1 hunks)
  • libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts
🧰 Additional context used
📓 Path-based instructions (2)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.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/driving-license/src/lib/drivingLicenseTemplate.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 (3)
libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (3)

36-36: LGTM: Import statement correctly updated

The addition of the Pickup import is consistent with the changes in the getCodes function and follows the TypeScript usage guideline for importing types.


55-76: LGTM: Delivery price logic correctly implemented

The changes in the getCodes function successfully implement the new functionality for adding a delivery price when the pickup option is set to post. The code is well-structured, maintains error handling, and adheres to TypeScript usage guidelines. It also preserves the reusability of the component across different NextJS apps.

A few observations:

  1. The pickup variable is correctly retrieved using getValueViaPath.
  2. The codes array is used to collect charge item codes, allowing for multiple codes.
  3. The conditional check for Pickup.POST is correctly implemented.
  4. The return statement is properly updated to return the codes array.

Line range hint 1-76: Summary: Changes align with PR objectives and maintain code quality

The modifications to the drivingLicenseTemplate.ts file are focused and effective in implementing the delivery price functionality when the pickup option is set to post. The changes are minimal, affecting only the getCodes function and its related import, without disrupting the overall structure or functionality of the template.

The implementation adheres to the project's coding guidelines, maintaining:

  1. Reusability of components across different NextJS apps
  2. Proper TypeScript usage for defining types
  3. Consistency with existing code style and structure

The changes successfully fulfill the PR objectives while preserving the quality and integrity of the codebase.

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 6.06061% with 31 lines in your changes missing coverage. Please review.

Project coverage is 36.92%. Comparing base (55e2b70) to head (3e3ec7e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...iving-license/src/forms/draft/subSectionSummary.ts 0.00% 16 Missing ⚠️
.../driving-license/src/lib/drivingLicenseTemplate.ts 0.00% 14 Missing ⚠️
...s/driving-license/src/fields/HealthDeclaration.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16194      +/-   ##
==========================================
- Coverage   36.92%   36.92%   -0.01%     
==========================================
  Files        6781     6781              
  Lines      140014   140030      +16     
  Branches    39811    39815       +4     
==========================================
+ Hits        51703    51705       +2     
- Misses      88311    88325      +14     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.63% <ø> (+<0.01%) ⬆️
application-template-api-modules 24.38% <ø> (ø)
application-templates-driving-license 18.63% <6.06%> (-0.08%) ⬇️
application-ui-shell 21.29% <ø> (ø)

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

Files with missing lines Coverage Δ
...ving-license/src/forms/draft/subSectionDelivery.ts 0.00% <ø> (ø)
...ion/templates/driving-license/src/lib/constants.ts 100.00% <100.00%> (ø)
...s/driving-license/src/fields/HealthDeclaration.tsx 0.00% <0.00%> (ø)
.../driving-license/src/lib/drivingLicenseTemplate.ts 7.69% <0.00%> (-1.40%) ⬇️
...iving-license/src/forms/draft/subSectionSummary.ts 0.00% <0.00%> (ø)

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 55e2b70...3e3ec7e. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 27, 2024

Datadog Report

All test runs 7be6603 🔗

7 Total Test Services: 0 Failed, 6 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.23%), 31 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.12s 1 no change Link
application-system-api 0 0 0 120 2 3m 23.31s 1 no change Link
application-template-api-modules 0 0 0 135 0 2m 3.23s 1 no change Link
application-templates-driving-license 0 0 0 13 0 16.31s 1 decreased (-0.23%) Link
application-ui-shell 0 0 0 74 0 35.48s 1 no change Link
service-portal-core 0 0 0 5 0 1.79s N/A Link
service-portal-health 0 0 0 0 0 565.67ms 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • application-templates-driving-license - jest 24.55% (-0.23%) - Details

@stjanilofts stjanilofts added the automerge Merge this PR as soon as all checks pass label Sep 27, 2024
@kksteini kksteini removed the automerge Merge this PR as soon as all checks pass label Sep 27, 2024
@stjanilofts stjanilofts force-pushed the chore/dl-postageprice branch from fe09c7c to 14ddd61 Compare October 3, 2024 11:12
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 (1)
libs/application/templates/driving-license/src/lib/constants.ts (1)

19-25: LGTM: CHARGE_ITEM_CODES constant added with a minor suggestion

The new CHARGE_ITEM_CODES constant is well-structured and includes all necessary mappings, including the new DELIVERY_FEE. The use of Record<string, string> is a good TypeScript practice.

Consider using a more specific type for better type safety:

export const CHARGE_ITEM_CODES: Record<typeof B_TEMP | typeof B_FULL | typeof B_FULL_RENEWAL_65 | typeof BE | typeof DELIVERY_FEE, string> = {
  // ... (rest of the code remains the same)
}

This change would ensure that only valid keys can be used when accessing CHARGE_ITEM_CODES.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0a0fb8a and 14ddd61.

📒 Files selected for processing (5)
  • libs/application/templates/driving-license/src/fields/HealthDeclaration.tsx (1 hunks)
  • libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts (0 hunks)
  • libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (2 hunks)
  • libs/application/templates/driving-license/src/lib/constants.ts (1 hunks)
  • libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • libs/application/templates/driving-license/src/forms/draft/subSectionDelivery.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts
🧰 Additional context used
📓 Path-based instructions (3)
libs/application/templates/driving-license/src/fields/HealthDeclaration.tsx (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/driving-license/src/forms/draft/subSectionSummary.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/driving-license/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."
🔇 Additional comments (10)
libs/application/templates/driving-license/src/lib/constants.ts (2)

12-12: LGTM: DELIVERY_FEE constant added

The new DELIVERY_FEE constant is well-defined and consistent with the existing coding style. It's appropriately exported for use in other modules.


12-25: Compliance with coding guidelines confirmed

The changes in this file adhere to the specified coding guidelines for libs/**/*:

  1. The new constants (DELIVERY_FEE and CHARGE_ITEM_CODES) are reusable across different NextJS apps.
  2. TypeScript is used appropriately for defining types (e.g., Record<string, string>).
  3. The constants are exported, allowing for effective tree-shaking and bundling.
libs/application/templates/driving-license/src/fields/HealthDeclaration.tsx (4)

14-14: Approved: Component declaration updated to arrow function

The change from a function declaration to an arrow function is a good modernization of the code. This approach:

  1. Aligns with current React best practices.
  2. Potentially improves tree-shaking, which is important as per the coding guidelines for files in the libs directory.
  3. Maintains correct TypeScript typing for props and return value.

Line range hint 9-12: Approved: Proper TypeScript usage for props and component

The TypeScript implementation in this file is excellent:

  1. The PropTypes interface is well-defined, extending FieldBaseProps and including the custom field prop.
  2. The component's props are correctly typed using the PropTypes interface.
  3. The return type of the component is explicitly set to JSX.Element.

This adheres to the coding guidelines for TypeScript usage in the libs directory.

Also applies to: 14-14


Line range hint 1-7: Approved: Component demonstrates good reusability potential

The HealthDeclaration component shows excellent reusability characteristics:

  1. It uses shared UI components from @island.is/island-ui/core, promoting consistent design across applications.
  2. Utility functions from @island.is/application/core are used, enabling shared functionality.
  3. The component's logic is not tightly coupled to a specific application, allowing for use in various contexts.
  4. Use of react-hook-form and custom hooks (useLocale) provides flexibility for integration in different NextJS apps.

These aspects align well with the coding guideline for reusability of components across different NextJS apps in the libs directory.

Also applies to: 14-89


Line range hint 18-89: Suggestions for improving component logic

While the overall logic of the HealthDeclaration component is sound, there are a few areas that could be improved:

  1. Consider extracting the checkForGlassesMismatch function outside the component for better testability and potential reuse.

  2. The BE license-specific logic in the onSelect callback could be moved to a separate function for improved readability and maintainability.

  3. There's a TODO comment regarding health certificate support for BE license. It would be beneficial to create a ticket to track this item for future implementation.

Would you like assistance in implementing these suggestions?

Regarding the TODO comment, let's check if there's an existing issue for this:

libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (4)

16-25: Improved code organization with centralized constants

The addition of these imports from a centralized constants file is a positive change. It enhances code maintainability and reusability across different NextJS apps, aligning well with our coding guidelines.


171-172: Simplified function signature improves flexibility

The change from destructuring externalData and answers to using a single application parameter is a good improvement. It simplifies the function signature and allows for more flexible access to the application data, enhancing code readability without affecting functionality.


178-181: Improved charge code lookup with centralized mapping

Great job implementing the suggestion from the past review comment. The use of CHARGE_ITEM_CODES mapping improves maintainability and readability. The default fallback to CHARGE_ITEM_CODES[B_FULL] ensures robustness. This change aligns well with our TypeScript usage guidelines and enhances code maintainability.


182-200: Enhanced price calculation with improved robustness

Excellent improvements in the price calculation logic:

  1. The introduction of pickupItem correctly handles the Pickup.POST scenario.
  2. The total price calculation now includes both the main item price and the delivery price when applicable.
  3. The use of optional chaining and nullish coalescing operators (??) improves code robustness by handling potential undefined values.

These changes successfully address the PR objective of adding delivery price for post pickup and enhance the overall functionality of the pricing logic.

@stjanilofts stjanilofts added the automerge Merge this PR as soon as all checks pass label Oct 3, 2024
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 (1)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (1)

171-204: Improved payment charge calculation logic

The changes in this section significantly enhance the clarity and robustness of the payment charge calculation. The use of CHARGE_ITEM_CODES mapping and the addition of the delivery fee calculation for postal pickup are particularly noteworthy improvements.

However, the targetCode determination could be simplified further:

const targetCode = CHARGE_ITEM_CODES[application.answers.applicationFor as keyof typeof CHARGE_ITEM_CODES] || DEFAULT_ITEM_CODE;

This approach eliminates the nested ternary operators, making the code more readable and maintainable.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 14ddd61 and 4746e44.

📒 Files selected for processing (2)
  • libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (2 hunks)
  • libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/application/templates/driving-license/src/lib/drivingLicenseTemplate.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.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 (2)
libs/application/templates/driving-license/src/forms/draft/subSectionSummary.ts (2)

16-25: Improved code organization with centralized constants

The addition of these imports from a centralized constants file is a positive change. It enhances code maintainability and aligns with best practices for effective tree-shaking and bundling. This approach makes it easier to manage and update constants across the application.


Line range hint 1-214: Overall improvement in code quality and functionality

The changes in this file significantly enhance the payment charge calculation logic for the driving license application process. The use of centralized constants and improved type safety aligns well with the coding guidelines for reusability and TypeScript usage. These modifications make the code more maintainable and robust, particularly in handling different license types and pickup options.

The refactoring maintains the overall structure of the subSectionSummary, ensuring that the changes integrate seamlessly with the existing code. This approach demonstrates a good balance between improving functionality and maintaining code stability.

@kodiakhq kodiakhq bot merged commit fa89e26 into main Oct 3, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the chore/dl-postageprice branch October 3, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants