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(AlertIcon): icon prop is an object type in v2 #954

Closed

Conversation

Ginioo
Copy link
Contributor

@Ginioo Ginioo commented Dec 5, 2024

User description

icon prop is an object type in v2, refering to migrating guide https://trendmicro-frontend.github.io/tonic-ui/react/v2/migrations/migrating-from-v1-to-v2.

image


PR Type

Bug fix


Description

  • Fixed the icon prop type in the AlertIcon component to correctly handle object types as per v2 specifications.
  • Updated the Icon component usage to align with the new iconProp type, ensuring compatibility with v2.

Changes walkthrough 📝

Relevant files
Bug fix
AlertIcon.js
Fix icon prop type and usage in AlertIcon component           

packages/react/src/alert/AlertIcon.js

  • Changed the type check for iconProp from string to object.
  • Updated the Icon component to use as prop instead of icon.
  • +2/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    codesandbox bot commented Dec 5, 2024

    Review or Edit in CodeSandbox

    Open the branch in Web EditorVS CodeInsiders

    Open Preview

    Copy link

    changeset-bot bot commented Dec 5, 2024

    ⚠️ No Changeset found

    Latest commit: ea067ba

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    @Ginioo Ginioo requested a review from cheton December 5, 2024 09:49
    @Ginioo Ginioo self-assigned this Dec 5, 2024
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Type Check
    The type check was changed from string to object, but there's no handling for string type inputs which could break backward compatibility if string values are still being passed

    Error Handling
    No error handling or validation for malformed icon prop objects which could lead to runtime errors

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add null check to prevent potential runtime errors when handling object type props

    Add a null check for iconProp before checking its type to prevent potential runtime
    errors when iconProp is null.

    packages/react/src/alert/AlertIcon.js [27-31]

    -if (typeof iconProp === 'object') {
    +if (iconProp !== null && typeof iconProp === 'object') {
       return (
         <Icon as={iconProp} />
       );
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a critical runtime safety issue by adding a null check, which is particularly important in React components where props can be null. This prevents potential crashes when accessing properties of null objects.

    8
    General
    Validate object props before rendering to prevent UI errors with invalid data

    Validate that iconProp is a valid icon object before rendering to prevent rendering
    errors with malformed icon data.

    packages/react/src/alert/AlertIcon.js [27-31]

    -if (typeof iconProp === 'object') {
    +if (typeof iconProp === 'object' && iconProp && Object.keys(iconProp).length > 0) {
       return (
         <Icon as={iconProp} />
       );
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion adds comprehensive validation for the iconProp object, ensuring it's not only an object but also contains data. This helps prevent rendering issues with empty or malformed icon objects, improving component reliability.

    7

    💡 Need additional feedback ? start a PR chat

    @Ginioo Ginioo requested a review from tinaClin December 5, 2024 09:50
    Copy link

    codesandbox-ci bot commented Dec 5, 2024

    This pull request is automatically built and testable in CodeSandbox.

    To see build info of the built libraries, click here or the icon next to each commit SHA.

    Copy link

    codecov bot commented Dec 5, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 78.44%. Comparing base (d797c22) to head (ea067ba).

    Additional details and impacted files
    @@           Coverage Diff           @@
    ##               v2     #954   +/-   ##
    =======================================
      Coverage   78.44%   78.44%           
    =======================================
      Files         406      406           
      Lines        6693     6693           
    =======================================
      Hits         5250     5250           
      Misses       1443     1443           

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @cheton
    Copy link
    Member

    cheton commented Dec 5, 2024

    I will close this PR since the approach for passing custom icons is already outlined in the documentation.

    https://trendmicro-frontend.github.io/tonic-ui/react/v2/components/alert#icons

    @cheton cheton closed this Dec 5, 2024
    @Ginioo Ginioo deleted the fix/tonic-ui-v2-alert-icon branch December 5, 2024 10:21
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants