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(web): Pension calculator results - Only fetch preview if selected year is the most recent one #16751

Merged

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Nov 6, 2024

Pension calculator results - Only fetch preview if selected year is the most recent one

What

  • Only show 2025 comparison for the most recent year

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 pension calculation logic for improved data handling.
    • Introduced a utility for comparing years in date strings.
  • Bug Fixes

    • Improved error handling for missing organization data.
  • Refactor

    • Updated component structure for better clarity and reliability in data processing.

@RunarVestmann RunarVestmann added the deploy-feature Deploys features to dev label Nov 6, 2024
@RunarVestmann RunarVestmann requested a review from a team as a code owner November 6, 2024 19:52
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes in this pull request focus on the PensionCalculatorResults.tsx file, enhancing the logic for pension calculation data handling. A new utility function, isSameYear, is introduced to compare date strings for year validation. The logic for fetching pension calculations for 2025 has been refined to ensure accurate data retrieval based on the dateOfCalculationsOptions variable. Additionally, the handling of calculationInput has been adjusted to set a specific date when conditions are met. Overall, these modifications improve data validation and the reliability of the component.

Changes

File Change Summary
apps/web/screens/Organization/SocialInsuranceAdministration/PensionCalculatorResults.tsx Introduced isSameYear function, updated dateOfCalculationsOptions in getProps, refined logic for 2025 calculations, and adjusted calculationInput handling for specific date setting. Error handling for missing organization data retained.

Possibly related PRs

Suggested reviewers

  • mannipje

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.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 6, 2024

Datadog Report

Branch report: fix/web-pension-calculator-result-preview-only-for-current-year
Commit report: b41cfb1
Test service: web

✅ 0 Failed, 84 Passed, 0 Skipped, 25.43s Total Time
➡️ Test Sessions change in coverage: 1 no change

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Affected services are: web,
Feature deployment of your services will begin shortly. Your feature will be accessible here:
https://fixweb-pension-calculator-result-preview--beta.dev01.devland.is/

Deployed services: web.
Excluded services: ``

@RunarVestmann RunarVestmann added automerge Merge this PR as soon as all checks pass and removed deploy-feature Deploys features to dev labels Nov 6, 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 (2)
apps/web/screens/Organization/SocialInsuranceAdministration/PensionCalculatorResults.tsx (2)

658-662: Consider refactoring complex conditional logic for clarity

The conditional statement in lines 658-662 is quite complex, which might affect readability and maintainability. Refactoring it into a well-named variable or helper function could enhance clarity.

Example:

+ const shouldFetch2025Calculation =
+   calculationInput.typeOfBasePension ===
+     SocialInsurancePensionCalculationBasePensionType.Disability &&
+   is2025PreviewActive(customPageData) &&
+   dateOfCalculationsOptions.length > 0 &&
+   calculationInput.dateOfCalculations &&
+   new Date(calculationInput.dateOfCalculations).getFullYear() ===
+     new Date(dateOfCalculationsOptions[0].value).getFullYear();

- calculationInput.typeOfBasePension ===
-   SocialInsurancePensionCalculationBasePensionType.Disability &&
- is2025PreviewActive(customPageData) &&
- dateOfCalculationsOptions.length > 0 &&
- calculationInput.dateOfCalculations &&
- new Date(calculationInput.dateOfCalculations).getFullYear() ===
-   new Date(dateOfCalculationsOptions[0].value).getFullYear()
+ shouldFetch2025Calculation
  ? apolloClient.query<Query, QueryGetPensionCalculationArgs>({
      query: GET_PENSION_CALCULATION,
      variables: {
        input: {
          ...calculationInput,
          dateOfCalculations: new Date(2025, 8, 1).toISOString(),
          typeOfBasePension:
            SocialInsurancePensionCalculationBasePensionType.NewSystem,
        },
      },
    })
  : {
      data: {
        getPensionCalculation: {
          groups: [],
          highlightedItems: [],
        },
      },
    },

668-668: Extract hardcoded date into a constant for maintainability

Using a descriptive constant for the hardcoded date improves code readability and makes future updates easier.

Example:

+ const SEPTEMBER_FIRST_2025 = new Date(2025, 8, 1).toISOString();
                    ...calculationInput,
-                   dateOfCalculations: new Date(2025, 8, 1).toISOString(),
+                   dateOfCalculations: SEPTEMBER_FIRST_2025,
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3856383 and 968b90f.

📒 Files selected for processing (1)
  • apps/web/screens/Organization/SocialInsuranceAdministration/PensionCalculatorResults.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/web/screens/Organization/SocialInsuranceAdministration/PensionCalculatorResults.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/web/screens/Organization/SocialInsuranceAdministration/PensionCalculatorResults.tsx (2)

617-617: Adding dateOfCalculationsOptions enhances data validation

Including dateOfCalculationsOptions improves the component's ability to handle date validations effectively.


707-707: Including dateOfCalculationsOptions in the return enhances functionality

Adding dateOfCalculationsOptions to the returned props ensures that the component has access to the necessary date options for rendering and logic.

Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 36.53%. Comparing base (f117a85) to head (43090a7).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...suranceAdministration/PensionCalculatorResults.tsx 0.00% 7 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16751      +/-   ##
==========================================
- Coverage   36.53%   36.53%   -0.01%     
==========================================
  Files        6888     6888              
  Lines      143674   143568     -106     
  Branches    40940    40908      -32     
==========================================
- Hits        52497    52456      -41     
+ Misses      91177    91112      -65     
Flag Coverage Δ
web 1.80% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...suranceAdministration/PensionCalculatorResults.tsx 0.00% <0.00%> (ø)

... 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 6516039...43090a7. Read the comment docs.

@kodiakhq kodiakhq bot merged commit 7e8abb4 into main Nov 7, 2024
30 checks passed
@kodiakhq kodiakhq bot deleted the fix/web-pension-calculator-result-preview-only-for-current-year branch November 7, 2024 14:05
RunarVestmann added a commit that referenced this pull request Nov 8, 2024
… year is the most recent one (#16751)

* Only fetch preview if selected year is the most recent one

* Overwrite what date gets sent to backend

* Add function for comparing years

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Nov 8, 2024
… year (#16751) (#16769)

* Only fetch preview if selected year is the most recent one

* Overwrite what date gets sent to backend

* Add function for comparing years

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
robertaandersen pushed a commit that referenced this pull request Nov 11, 2024
… year is the most recent one (#16751)

* Only fetch preview if selected year is the most recent one

* Overwrite what date gets sent to backend

* Add function for comparing years

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
jonnigs pushed a commit that referenced this pull request Nov 12, 2024
… year is the most recent one (#16751)

* Only fetch preview if selected year is the most recent one

* Overwrite what date gets sent to backend

* Add function for comparing years

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
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