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

feat(app-sys): national-id-with-name fetch form more endpoints #17101

Merged
merged 18 commits into from
Dec 3, 2024

Conversation

jonnigs
Copy link
Member

@jonnigs jonnigs commented Dec 2, 2024

What

Add in the options to fetch name by id for companies and vanished persons

Why

Expand shared components useability

Screenshot

Screenshot 2024-12-03 at 15 06 53

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 NationalIdWithNameField to support searching for both persons and companies.
    • Added new layout customization options including title variants and margin settings.
    • Introduced a new GraphQL query for retrieving company information.
  • Improvements

    • Updated the component to handle both individual and company national ID lookups with improved error handling and loading states.
  • Documentation

    • Adjusted descriptions and titles for better user guidance based on locale.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request primarily enhance the functionality of the NationalIdWithNameField across multiple files. New properties have been introduced to the buildNationalIdWithNameField function and the NationalIdWithNameField interface, allowing for more detailed configurations. The NationalIdWithName component has been updated to manage queries for both individuals and companies, and a new GraphQL query for company identity has been added. These modifications improve the capability and flexibility of national ID handling features.

Changes

File Path Change Summary
libs/application/core/src/lib/fieldBuilders.ts Updated buildNationalIdWithNameField to include new properties: searchPersons, searchCompanies, titleVariant, description, marginTop, marginBottom.
libs/application/types/src/lib/Fields.ts Modified NationalIdWithNameField interface to add properties: searchPersons, searchCompanies, titleVariant, marginTop, marginBottom.
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx Updated NationalIdWithNameProps interface to include searchPersons and searchCompanies. Enhanced logic for querying national IDs for persons and companies.
libs/application/ui-components/src/components/NationalIdWithName/graphql/queries.ts Added new GraphQL query COMPANY_IDENTITY_QUERY for retrieving company information.
libs/application/ui-fields/src/lib/NationalIdWithNameFormField/NationalIdWithNameFormField.tsx Modified component to include new imports, conditional rendering for title and description, and passed new props to NationalIdWithName.

Possibly related PRs

Suggested labels

deploy-feature

Suggested reviewers

  • Toti91
  • eirikurn
  • sigruntg

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

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 2.43902% with 40 lines in your changes missing coverage. Please review.

Project coverage is 35.68%. Comparing base (1dfbe91) to head (60d27cd).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...mponents/NationalIdWithName/NationalIdWithName.tsx 0.00% 35 Missing ⚠️
...dWithNameFormField/NationalIdWithNameFormField.tsx 0.00% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17101      +/-   ##
==========================================
- Coverage   35.69%   35.68%   -0.01%     
==========================================
  Files        6917     6917              
  Lines      147412   147445      +33     
  Branches    41952    41976      +24     
==========================================
+ Hits        52617    52618       +1     
- Misses      94795    94827      +32     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
application-api-files 62.01% <ø> (ø)
application-core 76.01% <ø> (ø)
application-system-api 38.76% <ø> (+<0.01%) ⬆️
application-template-api-modules 27.79% <ø> (ø)
application-templates-accident-notification 29.01% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.93% <ø> (ø)
application-templates-driving-license 18.18% <ø> (ø)
application-templates-estate 13.83% <2.94%> (-0.04%) ⬇️
application-templates-example-payment 24.85% <ø> (ø)
application-templates-financial-aid 14.42% <ø> (ø)
application-templates-general-petition 23.13% <ø> (ø)
application-templates-inheritance-report 6.54% <ø> (ø)
application-templates-marriage-conditions 15.11% <ø> (ø)
application-templates-mortgage-certificate 43.24% <ø> (ø)
application-templates-parental-leave 29.95% <ø> (ø)
application-types 6.57% <ø> (ø)
application-ui-components 1.24% <0.00%> (-0.04%) ⬇️
application-ui-shell 22.48% <2.56%> (-0.08%) ⬇️
clients-charge-fjs-v2 24.11% <ø> (ø)
web 2.43% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/application/core/src/lib/fieldBuilders.ts 41.14% <ø> (ø)
libs/application/types/src/lib/Fields.ts 100.00% <ø> (ø)
...c/components/NationalIdWithName/graphql/queries.ts 100.00% <100.00%> (ø)
...dWithNameFormField/NationalIdWithNameFormField.tsx 14.28% <0.00%> (-35.72%) ⬇️
...mponents/NationalIdWithName/NationalIdWithName.tsx 1.09% <0.00%> (-0.47%) ⬇️

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 1dfbe91...60d27cd. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 2, 2024

Datadog Report

All test runs 302db4e 🔗

21 Total Test Services: 0 Failed, 20 Passed
🔻 Test Sessions change in coverage: 3 decreased, 89 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 6.88s 1 no change Link
api 0 0 0 4 0 2.36s 1 no change Link
application-api-files 0 0 0 2 0 4.42s 1 no change Link
application-core 0 0 0 97 0 14.86s 1 no change Link
application-system-api 0 0 0 46 0 2m 16.34s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 4.81s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 15.32s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 9.89s 1 no change Link
application-templates-driving-license 0 0 0 13 0 13.3s 1 no change Link
application-templates-example-payment 0 0 0 2 0 10.37s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • application-ui-shell - jest 29.4% (-0.05%) - Details
  • application-templates-estate - jest 20.74% (-0.03%) - Details
  • application-ui-components - jest 1.63% (-0.02%) - Details

Copy link
Member

@norda-gunni norda-gunni left a comment

Choose a reason for hiding this comment

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

LGTM

@jonnigs jonnigs marked this pull request as ready for review December 3, 2024 15:38
@jonnigs jonnigs requested a review from a team as a code owner December 3, 2024 15:38
coderabbitai[bot]
coderabbitai bot previously requested changes Dec 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: 2

🧹 Outside diff range and nitpick comments (4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (4)

133-134: Simplify function call using optional chaining

You can simplify the conditional invocation of onNameChange by using optional chaining.

Suggested change:

-            onNameChange &&
-              onNameChange(companyData.companyRegistryCompany?.name ?? '')
+            onNameChange?.(companyData.companyRegistryCompany?.name ?? '')
🧰 Tools
🪛 Biome (1.9.4)

[error] 133-134: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


143-152: Remove unnecessary block statements

The curly braces around this code block are unnecessary and can be removed to simplify the code.

Suggested change:

-          {
-            searchPersons &&
-              getIdentity({
-                variables: {
-                  input: {
-                    nationalId: nationalIdInput,
-                  },
-                },
-              })
-          }
+          searchPersons &&
+            getIdentity({
+              variables: {
+                input: {
+                  nationalId: nationalIdInput,
+                },
+              },
+            })
🧰 Tools
🪛 Biome (1.9.4)

[error] 143-152: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


154-163: Remove unnecessary block statements

Similarly, the curly braces around this block are unnecessary and can be removed.

Suggested change:

-          {
-            searchCompanies &&
-              getCompanyIdentity({
-                variables: {
-                  input: {
-                    nationalId: nationalIdInput,
-                  },
-                },
-              })
-          }
+          searchCompanies &&
+            getCompanyIdentity({
+              variables: {
+                input: {
+                  nationalId: nationalIdInput,
+                },
+              },
+            })
🧰 Tools
🪛 Biome (1.9.4)

[error] 154-163: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


Line range hint 201-205: Handle loading state when both searches are active

When both searchPersons and searchCompanies are true, the loading prop may not accurately reflect both query loading states.

Consider updating the loading prop to account for both conditions:

-              loading={searchPersons ? queryLoading : companyQueryLoading}
+              loading={
+                (searchPersons && queryLoading) ||
+                (searchCompanies && companyQueryLoading)
+              }
🧰 Tools
🪛 Biome (1.9.4)

[error] 198-199: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 02f2aa4 and cd9188b.

📒 Files selected for processing (5)
  • libs/application/core/src/lib/fieldBuilders.ts (2 hunks)
  • libs/application/types/src/lib/Fields.ts (1 hunks)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (8 hunks)
  • libs/application/ui-components/src/components/NationalIdWithName/graphql/queries.ts (1 hunks)
  • libs/application/ui-fields/src/lib/NationalIdWithNameFormField/NationalIdWithNameFormField.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
libs/application/ui-components/src/components/NationalIdWithName/graphql/queries.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/types/src/lib/Fields.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/ui-fields/src/lib/NationalIdWithNameFormField/NationalIdWithNameFormField.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/core/src/lib/fieldBuilders.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/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🪛 Biome (1.9.4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx

[error] 133-134: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 143-152: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 154-163: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🪛 eslint
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx

[error] 180-180: React Hook useEffect has a missing dependency: 'application.answers'. Either include it or remove the dependency array.

(react-hooks/exhaustive-deps)

🔇 Additional comments (5)
libs/application/ui-components/src/components/NationalIdWithName/graphql/queries.ts (1)

10-16: LGTM

The COMPANY_IDENTITY_QUERY is correctly defined and extends the functionality to fetch company names.

libs/application/ui-fields/src/lib/NationalIdWithNameFormField/NationalIdWithNameFormField.tsx (2)

1-14: Enhance component with localization and layout

The added imports and use of Box, Text, FieldDescription, and useLocale effectively improve the component's layout and localization support.


26-63: LGTM

The integration of new props and conditional rendering for title and description enhances the component's flexibility.

libs/application/core/src/lib/fieldBuilders.ts (1)

Line range hint 751-778: Integrate new properties into field builder

The additional properties searchPersons, searchCompanies, titleVariant, description, marginTop, and marginBottom are correctly integrated into the buildNationalIdWithNameField function.

libs/application/types/src/lib/Fields.ts (1)

573-577: Extend NationalIdWithNameField interface with new options

The new optional properties enhance the NationalIdWithNameField interface, providing greater configurability.

@jonnigs jonnigs added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 3, 2024
@jonnigs jonnigs added deprecated:automerge (Disabled) Merge this PR as soon as all checks pass and removed deprecated:automerge (Disabled) Merge this PR as soon as all checks pass labels Dec 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 (2)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (2)

119-138: Simplify query execution blocks

The query execution logic can be simplified by removing unnecessary block statements and using optional chaining.

Consider this cleaner implementation:

- {
-   searchPersons &&
-     getIdentity({
-       variables: {
-         input: {
-           nationalId: nationalIdInput,
-         },
-       },
-     })
- }
- {
-   searchCompanies &&
-     getCompanyIdentity({
-       variables: {
-         input: {
-           nationalId: nationalIdInput,
-         },
-       },
-     })
- }
+ searchPersons && getIdentity({
+   variables: {
+     input: {
+       nationalId: nationalIdInput,
+     },
+   },
+ });
+ 
+ searchCompanies && getCompanyIdentity({
+   variables: {
+     input: {
+       nationalId: nationalIdInput,
+     },
+   },
+ });

Also, simplify the callback:

- onNameChange &&
-   onNameChange(companyData.companyRegistryCompany?.name ?? '')
+ onNameChange?.(companyData.companyRegistryCompany?.name ?? '')

Also applies to: 143-163

🧰 Tools
🪛 Biome (1.9.4)

[error] 133-134: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


173-180: Optimize name synchronization logic

The name synchronization effect could be simplified to reduce complexity.

Consider this more concise implementation:

  useEffect(() => {
    const nameInAnswers = getValueViaPath(application.answers, nameField)
-   if (personName && nameInAnswers !== personName) {
-     setValue(nameField, personName)
-   } else if (companyName && nameInAnswers !== companyName) {
-     setValue(nameField, companyName)
-   }
+   const newName = personName || companyName
+   if (newName && nameInAnswers !== newName) {
+     setValue(nameField, newName)
+   }
  }, [personName, companyName, setValue, nameField, application.answers])
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cd9188b and 60d27cd.

📒 Files selected for processing (1)
  • libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (8 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.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."
🪛 Biome (1.9.4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx

[error] 133-134: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 143-152: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 154-163: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🔇 Additional comments (4)
libs/application/ui-components/src/components/NationalIdWithName/NationalIdWithName.tsx (4)

11-15: LGTM: Type-safe interface extension

The new imports and interface properties properly support the addition of company lookup functionality while maintaining type safety.

Also applies to: 36-37


56-57: LGTM: Clean state separation

Good practice using separate state variables for person and company names, with sensible defaults that maintain backward compatibility.

Also applies to: 69-70


217-233: Refactor error handling for combined searches

The error handling logic remains complex and could be simplified for better maintainability.


Line range hint 1-243: LGTM: Component meets library guidelines

The component successfully:

  • Maintains reusability across NextJS apps
  • Uses TypeScript appropriately
  • Follows proper bundling practices
🧰 Tools
🪛 Biome (1.9.4)

[error] 113-113: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 133-134: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 143-152: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)


[error] 154-163: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

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