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(service-portal): Use full name instead of display name #16497

Merged
merged 4 commits into from
Oct 22, 2024

Conversation

thordurhhh
Copy link
Member

@thordurhhh thordurhhh commented Oct 21, 2024

What

Use full name instead of display name

Why

We are currently using display-name (birtingarnafn) in a few places where we should be using fullName.

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 GraphQL query UserInfoDashboardName for enhanced user information retrieval.
    • Added a new query UserInfoOverviewName to fetch the fullName more efficiently.
  • Improvements

    • Updated data structure for accessing fullName, now nested within a name object for various entities.
    • Enhanced user display in the UserInfo and UserInfoOverview components to reflect the updated data structure.
  • Bug Fixes

    • Corrected the source of the user's full name in the SubjectInfo and InfoLine components for better accuracy.

@thordurhhh thordurhhh requested a review from a team as a code owner October 21, 2024 15:32
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Walkthrough

This pull request introduces several changes related to the handling of user information within the application. A new GraphQL query, UserInfoDashboardName, is added to retrieve user names conditionally. Additionally, modifications are made to existing GraphQL queries and models to accommodate a new displayName field and to restructure how names are accessed within the response objects. The changes also enhance the data formatting functions to ensure consistent retrieval of user names across different components.

Changes

File Change Summary
apps/portals/my-pages/src/components/Greeting/userInfoData.graphql Added a new GraphQL query UserInfoDashboardName that accepts an optional useFakeData argument and retrieves fullName from the nationalRegistryPerson field.
libs/api/domains/national-registry/src/lib/shared/models/name.model.ts Introduced an optional displayName field in the Name class, defined as a nullable String GraphQL field.
libs/api/domains/national-registry/src/lib/shared/models/personBase.model.ts Updated the fullName field in the PersonBase class to include a deprecationReason, indicating a shift to using the name object.
libs/api/domains/national-registry/src/lib/v3/mapper.ts Enhanced the formatPerson function to return a new name property with detailed name information, and updated the formatUser function to align with this new structure. Added a deprecation comment for the legalResidence field.
libs/service-portal/information/src/screens/UserInfo/UserInfo.graphql Modified the NationalRegistryPerson query to remove fullName from the top level and nest it within the name object, while retaining it in the spouse and domicileInhabitants objects.
libs/service-portal/information/src/screens/UserInfo/UserInfo.tsx Updated the SubjectInfo component to retrieve the user's full name from nationalRegistryPerson.name.fullName instead of userInfo.profile.name.
libs/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.graphql Modified the UserInfoOverview query to nest fullName within the name object and added a new query UserInfoOverviewName to retrieve fullName specifically.
libs/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.tsx Changed the way the full name is accessed in the UserInfoOverview component to data.nationalRegistryPerson?.name?.fullName, maintaining existing logic for child custody and biological children.

Possibly related PRs

Suggested labels

automerge, deploy-feature

Suggested reviewers

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

🧹 Outside diff range and nitpick comments (6)
libs/api/domains/national-registry/src/lib/shared/models/name.model.ts (1)

16-18: LGTM! Consider adding JSDoc comment for the new field.

The addition of the displayName field is well-implemented and aligns with the PR objectives. The field is correctly defined using the @Field decorator and follows the same pattern as other fields in the class.

Consider adding a JSDoc comment to explain the purpose and usage of the displayName field. This would improve code documentation and maintainability. For example:

/**
 * The display name of the person, which may differ from the full name.
 * This field can be used for presentation purposes where a shortened or alternate name is preferred.
 */
@Field(() => String, { nullable: true })
displayName?: string | null
libs/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.graphql (1)

22-28: Approve new query with minor suggestion

The addition of the UserInfoOverviewName query is a good approach to retrieve only the name information when needed. This aligns well with the PR objective and provides a more focused way to fetch data.

Consider adding a comment to explain the purpose of this query for better maintainability:

+# Query to retrieve only the full name of the national registry person
 query UserInfoOverviewName($useFakeData: Boolean) {
   nationalRegistryPerson(useFakeData: $useFakeData) {
     name {
       fullName
     }
   }
 }
libs/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.tsx (2)

116-116: LGTM! Consider adding a fallback for empty name.

The change correctly accesses the full name through the new nested structure, aligning with the PR objectives. The use of optional chaining is a good practice for handling potentially undefined properties.

Consider adding a fallback string for cases where the full name might be empty:

-title={data.nationalRegistryPerson?.name?.fullName || ''}
+title={data.nationalRegistryPerson?.name?.fullName || 'N/A'}

This ensures that a meaningful value is always displayed, improving user experience.


Line range hint 1-143: Overall, the changes look good and adhere to the project guidelines.

The modification successfully implements the PR objective of using the full name instead of the display name. The component maintains its reusability across different NextJS apps, effectively uses TypeScript for type safety, and its structure supports efficient tree-shaking and bundling.

Consider extracting the child data fetching logic into a custom hook to improve modularity and reusability. This would separate concerns and make the component easier to test and maintain.

libs/service-portal/information/src/screens/UserInfo/UserInfo.tsx (1)

42-42: LGTM! Consider using null coalescing for consistency.

The change correctly implements the use of full name from the national registry, aligning with the PR objectives. Good use of optional chaining to handle potential undefined values.

For consistency with TypeScript best practices, consider using null coalescing (??) instead of logical OR (||):

title={nationalRegistryPerson?.name?.fullName ?? ''}

This ensures that only null or undefined values are replaced with an empty string, whereas || would also replace falsy values like 0 or false.

libs/api/domains/national-registry/src/lib/v3/mapper.ts (1)

93-99: Approve changes with a minor suggestion

The new name property provides a more structured approach to handling person names, which is a good improvement. The fallback mechanism for fullName ensures data consistency.

However, consider adding a comment explaining the difference between fullName and displayName to improve code clarity.

Consider adding a comment like this:

name: {
  // ... existing properties ...
  fullName: individual.fulltNafn?.fulltNafn ?? individual.nafn,
  displayName: individual.nafn, // Used for display purposes, may differ from fullName
},
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e9edd28 and 00e066e.

📒 Files selected for processing (8)
  • apps/portals/my-pages/src/components/Greeting/userInfoData.graphql (1 hunks)
  • libs/api/domains/national-registry/src/lib/shared/models/name.model.ts (1 hunks)
  • libs/api/domains/national-registry/src/lib/shared/models/personBase.model.ts (1 hunks)
  • libs/api/domains/national-registry/src/lib/v3/mapper.ts (1 hunks)
  • libs/service-portal/information/src/screens/UserInfo/UserInfo.graphql (1 hunks)
  • libs/service-portal/information/src/screens/UserInfo/UserInfo.tsx (2 hunks)
  • libs/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.graphql (2 hunks)
  • libs/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
apps/portals/my-pages/src/components/Greeting/userInfoData.graphql (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."
libs/api/domains/national-registry/src/lib/shared/models/name.model.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/api/domains/national-registry/src/lib/shared/models/personBase.model.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/api/domains/national-registry/src/lib/v3/mapper.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/service-portal/information/src/screens/UserInfo/UserInfo.graphql (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/service-portal/information/src/screens/UserInfo/UserInfo.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/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.graphql (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/service-portal/information/src/screens/UserInfoOverview/UserInfoOverview.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."
🔇 Additional comments (8)
apps/portals/my-pages/src/components/Greeting/userInfoData.graphql (1)

1-7: LGTM! The new query aligns with PR objectives and best practices.

The UserInfoDashboardName query is well-structured and consistent with GraphQL best practices. It correctly implements the change from "display-name" to "fullName" as per the PR objectives. The optional useFakeData parameter provides flexibility for different environments.

To ensure consistency across the codebase, let's verify the usage of fullName:

libs/api/domains/national-registry/src/lib/shared/models/personBase.model.ts (2)

Line range hint 1-24: Overall, changes align with guidelines and PR objectives

The modifications to the PersonBase class adhere to the coding guidelines for libs/**/* files:

  1. The class remains reusable across different NextJS apps.
  2. TypeScript is used effectively for defining props and types.
  3. The structure supports efficient tree-shaking and bundling.

The changes to the fullName field introduce a deprecation notice, which is a good practice for managing API evolution. However, ensure that the apparent contradiction in the deprecation message is addressed and that documentation is updated accordingly.


8-12: Approved changes, but clarification needed on deprecation message

The addition of the deprecation reason for the fullName field is a good practice and aligns with the PR objectives. It adheres to TypeScript usage and supports effective tree-shaking.

However, there seems to be a contradiction:

  1. The PR aims to use full name instead of display name.
  2. The deprecation message suggests this field might return a display name.

Could you clarify this apparent contradiction?

Also, consider updating the relevant documentation to reflect these changes and guide developers on using the recommended name object.

To ensure consistency across the codebase, let's check for other occurrences of fullName:

✅ Verification successful

Deprecation of 'fullName' field is valid and intentional

The deprecation of the 'fullName' field in the PersonBase model is part of a controlled refactoring effort within the national-registry domain. The change promotes using a more detailed name object structure, which aligns with best practices for handling personal names.

While 'fullName' is used widely in the codebase, this specific deprecation affects models directly extending PersonBase, primarily within the national-registry domain. The deprecation message provides clear guidance for future development.

Consider updating documentation to reflect this change and plan for gradual migration in affected models.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for other occurrences of fullName field in GraphQL types
# Expected: Similar deprecation messages or updated usage

rg -t ts 'fullName.*Field\(' libs

Length of output: 35


Script:

#!/bin/bash
# Description: Comprehensive search for `fullName` field across all TypeScript files in libs
# Expected: List all occurrences of `fullName` field declarations to ensure consistent deprecation or usage

rg -t ts 'fullName' libs --context 3

Length of output: 292022


Script:

#!/bin/bash
# Search for files that import or extend PersonBase
rg "import.*PersonBase|extends PersonBase" --type ts

Length of output: 1143

libs/service-portal/information/src/screens/UserInfo/UserInfo.graphql (1)

11-11: LGTM: Addition of fullName to the name object aligns with PR objectives.

The addition of the fullName field within the name object is consistent with the PR's goal of using the full name instead of the display name. This change enhances the query's flexibility by providing access to both individual name components and the full name.

To ensure this change is consistently applied across the codebase, let's verify the usage:

libs/service-portal/information/src/screens/UserInfo/UserInfo.tsx (2)

Line range hint 1-231: Overall assessment: Changes align with PR objectives and coding guidelines.

The modifications in this file successfully implement the use of full name instead of display name, as per the PR objectives. The code adheres to TypeScript best practices and maintains consistency with the coding guidelines for the libs/**/* pattern.

Key points:

  1. Reusability of the component is preserved.
  2. TypeScript usage for props and types is maintained.
  3. Changes don't negatively impact tree-shaking or bundling.

63-63: LGTM! Verify data structure consistency.

The change correctly implements the use of full name from the national registry, aligning with the PR objectives. Good use of optional chaining and null coalescing.

To ensure consistency across the codebase, let's verify that this new structure (name.fullName) is used consistently:

This will help identify any places where the old structure might still be in use and need updating.

libs/api/domains/national-registry/src/lib/v3/mapper.ts (2)

Line range hint 293-293: LGTM: Consistent fullName handling

The update to the fullName property in the formatUser function aligns well with the changes made in formatPerson. This ensures consistency in how full names are handled across the codebase and supports the PR objective of using full names.


Line range hint 1-393: Overall assessment: Changes align with guidelines and improve code quality

The modifications in this file enhance the handling of user names, providing a more structured and consistent approach across different functions. These changes align well with the PR objectives and adhere to the coding guidelines for libs/**/* files:

  1. Reusability: The new name property in formatPerson and the updated fullName in formatUser improve consistency and reusability across different NextJS apps.
  2. TypeScript usage: The changes maintain proper TypeScript usage for defining props and exporting types.
  3. Tree-shaking and bundling: The modifications don't introduce any obvious issues that would affect tree-shaking or bundling practices.

These improvements contribute to better maintainability and consistency in handling user information throughout the application.

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.75%. Comparing base (f05a38e) to head (164e4ad).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16497      +/-   ##
==========================================
- Coverage   36.77%   36.75%   -0.02%     
==========================================
  Files        6847     6810      -37     
  Lines      141871   140920     -951     
  Branches    40422    40105     -317     
==========================================
- Hits        52167    51793     -374     
+ Misses      89704    89127     -577     
Flag Coverage Δ
api 3.37% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
nest-core ?

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

Files with missing lines Coverage Δ
...rtal/information/src/screens/UserInfo/UserInfo.tsx 0.00% <ø> (ø)
.../src/screens/UserInfoOverview/UserInfoOverview.tsx 0.00% <ø> (ø)

... and 270 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 f05a38e...164e4ad. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 21, 2024

Datadog Report

All test runs 93a1c25 🔗

2 Total Test Services: 0 Failed, 2 Passed
➡️ Test Sessions change in coverage: 8 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 2.73s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 12.74s 1 no change Link

Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

Cool

@thordurhhh thordurhhh added the automerge Merge this PR as soon as all checks pass label Oct 22, 2024
@kodiakhq kodiakhq bot merged commit dd03c10 into main Oct 22, 2024
35 checks passed
@kodiakhq kodiakhq bot deleted the service-portal/proper-full-name branch October 22, 2024 10:46
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