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(web): Generic list - External url field #16348

Merged
merged 5 commits into from
Oct 15, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Oct 10, 2024

Generic list - External url field

What

  • Now generic list items can point to an external url

Why

  • This is needed for organizations that have published material on external urls

Screenshots / Gifs

Screenshot 2024-10-10 at 10 14 28

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 the ClickableItem component to dynamically display icons based on item URLs.
    • Expanded the generic list data to include external URLs for each item.
  • Bug Fixes

    • Streamlined logic for generating links in the ClickableItem component.
  • Documentation

    • Updated GraphQL schema to reflect the addition of the externalUrl field in the GenericListItem class.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Oct 10, 2024
@RunarVestmann RunarVestmann requested review from a team as code owners October 10, 2024 10:18
Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces enhancements to the GenericList component, specifically the ClickableItem subcomponent. A new variable for managing icon display based on item URL properties is added, improving flexibility in icon assignment. Additionally, the GET_GENERIC_LIST_ITEMS_QUERY is updated to include an externalUrl field, and the GenericListItem model is modified to accommodate this new field, allowing for better data retrieval and representation.

Changes

File Path Change Summary
apps/web/components/GenericList/GenericList.tsx Added icon variable in ClickableItem to manage icon display based on URLs; updated logic for href assignment.
apps/web/screens/queries/GenericList.ts Updated GET_GENERIC_LIST_ITEMS_QUERY to include externalUrl in the items selection set.
libs/cms/src/lib/models/genericListItem.model.ts Added optional externalUrl field in GenericListItem class; updated mapGenericListItem function to return this field.

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.

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 (3)
libs/cms/src/lib/models/genericListItem.model.ts (2)

34-36: LGTM! Consider adding a JSDoc comment for consistency.

The addition of the externalUrl field aligns well with the PR objectives and follows TypeScript best practices. It's correctly defined as nullable, which is appropriate for optional data.

For consistency with other fields in the class, consider adding a JSDoc comment to describe the purpose of this field. For example:

/**
 * The URL to an external resource related to this list item.
 */
@Field(() => String, { nullable: true })
externalUrl?: string

68-68: LGTM! Consider using a consistent approach for default values.

The addition of the externalUrl field to the mapped object is correct and aligns with the PR objectives. The use of optional chaining and nullish coalescing is a good practice for handling potentially undefined values.

For consistency with how other fields are handled (e.g., title), consider using the ?? operator instead of relying on the truthiness of the value. This would make the code more explicit:

externalUrl: fields.externalLink?.fields?.url ?? '',

This change ensures that falsy values like null or undefined are also replaced with an empty string, maintaining consistency with other field mappings.

apps/web/components/GenericList/GenericList.tsx (1)

130-138: LGTM: Improved icon and link logic

The introduction of the icon variable and the updated logic for determining icons and href values enhance the component's flexibility and maintainability. This change aligns well with best practices for reusable components.

Consider using a switch statement or object literal for icon mapping if more icon types are expected in the future:

const iconMap = {
  assetUrl: 'document',
  externalUrl: 'open',
} as const;

const icon = Object.entries(iconMap).find(([key]) => item[key as keyof typeof item])?.[1] || null;

This approach would be more scalable if additional URL types and corresponding icons are added in the future.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dcba071 and 9821445.

⛔ Files ignored due to path filters (1)
  • libs/cms/src/lib/generated/contentfulTypes.d.ts is excluded by !**/generated/**
📒 Files selected for processing (3)
  • apps/web/components/GenericList/GenericList.tsx (3 hunks)
  • apps/web/screens/queries/GenericList.ts (1 hunks)
  • libs/cms/src/lib/models/genericListItem.model.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/web/components/GenericList/GenericList.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."
apps/web/screens/queries/GenericList.ts (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/cms/src/lib/models/genericListItem.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."
🔇 Additional comments (4)
apps/web/screens/queries/GenericList.ts (1)

27-27: LGTM! Consider updating related TypeScript types.

The addition of the externalUrl field to the GET_GENERIC_LIST_ITEMS_QUERY aligns well with the PR objective of enabling generic list items to link to external URLs. This change enhances the flexibility of the generic list component, allowing for better integration with externally hosted content.

To ensure type safety, please verify that the corresponding TypeScript types or interfaces have been updated to include this new field. Run the following script to check for potential type definitions that might need updating:

If any types are found, please ensure they include the externalUrl field to maintain type consistency across the application.

apps/web/components/GenericList/GenericList.tsx (3)

19-19: LGTM: Improved type safety for icon properties

The addition of IconProps import enhances type safety when working with icon-related properties in the component.


161-166: LGTM: Dynamic icon rendering

The update to dynamically set the icon prop in the Icon component is consistent with the earlier logic changes and improves the component's flexibility. This change adheres to TypeScript best practices by leveraging the IconProps type.


Line range hint 130-166: Overall assessment: Improved component flexibility and type safety

The changes to the ClickableItem component enhance its flexibility and type safety without affecting the overall structure or NextJS-specific functionality. The modifications align well with TypeScript and React best practices, improving the component's maintainability and reusability.

Key improvements:

  1. Introduction of a flexible icon assignment logic
  2. Dynamic href generation based on item properties
  3. Improved type safety with the use of IconProps

These changes contribute positively to the codebase and align with the PR objectives of enabling generic list items to link to external URLs.

Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 11.11111% with 8 lines in your changes missing coverage. Please review.

Project coverage is 36.75%. Comparing base (c21a58f) to head (ba03f37).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
apps/web/components/GenericList/GenericList.tsx 0.00% 6 Missing ⚠️
libs/cms/src/lib/models/genericListItem.model.ts 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16348      +/-   ##
==========================================
+ Coverage   36.73%   36.75%   +0.02%     
==========================================
  Files        6808     6809       +1     
  Lines      141061   141104      +43     
  Branches    40217    40194      -23     
==========================================
+ Hits        51817    51862      +45     
+ Misses      89244    89242       -2     
Flag Coverage Δ
api 3.37% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.91% <33.33%> (-0.01%) ⬇️
application-system-api 41.42% <33.33%> (-0.01%) ⬇️
application-template-api-modules 27.87% <33.33%> (-0.02%) ⬇️
cms 0.43% <0.00%> (-0.01%) ⬇️
cms-translations 39.04% <33.33%> (-0.01%) ⬇️
judicial-system-api 18.39% <ø> (ø)
judicial-system-backend 55.19% <33.33%> (-0.01%) ⬇️
services-user-notification 47.02% <33.33%> (-0.01%) ⬇️
web 1.82% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
apps/web/screens/queries/GenericList.ts 0.00% <ø> (ø)
libs/cms/src/lib/models/genericListItem.model.ts 41.46% <33.33%> (-0.65%) ⬇️
apps/web/components/GenericList/GenericList.tsx 0.00% <0.00%> (ø)

... and 40 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 4a1d731...ba03f37. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 10, 2024

Datadog Report

All test runs 9b5caad 🔗

11 Total Test Services: 0 Failed, 10 Passed
➡️ Test Sessions change in coverage: 32 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
api 0 0 0 4 0 2.75s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 12.79s 1 no change Link
api-domains-communications 0 0 0 5 0 30.71s 1 no change Link
api-domains-license-service 0 0 0 0 0 679.75ms 1 no change Link
application-system-api 0 0 0 120 2 3m 10.75s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 32.78s 1 no change Link
cms-translations 0 0 0 3 0 24.78s 1 no change Link
judicial-system-api 0 0 0 57 0 6.28s 1 no change Link
judicial-system-backend 0 0 0 20964 0 20m 24s 1 no change Link
services-user-notification 0 0 0 51 0 1m 26.41s 1 no change Link

@kodiakhq kodiakhq bot merged commit f560cd2 into main Oct 15, 2024
70 checks passed
@kodiakhq kodiakhq bot deleted the feature/web-generic-list-item-external-url-field branch October 15, 2024 16:09
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