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

♻️ Refacto link (breaking) #253

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

♻️ Refacto link (breaking) #253

wants to merge 1 commit into from

Conversation

FelixLgr
Copy link
Collaborator

@FelixLgr FelixLgr commented Dec 20, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new markup prop for the Link component, allowing flexible rendering options.
  • Bug Fixes

    • Removed icon rendering test case and updated router link test case to use the new markup prop.
  • Documentation

    • Updated documentation to reflect changes in the LinkProps interface and component structure.
  • Refactor

    • Simplified the Link component by removing unnecessary props and streamlining rendering logic.

@FelixLgr FelixLgr self-assigned this Dec 20, 2024
Copy link

coderabbitai bot commented Dec 20, 2024

Warning

Rate limit exceeded

@FelixLgr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7ea64f8 and ddefd33.

📒 Files selected for processing (6)
  • examples/react-template/screens/Link.tsx (2 hunks)
  • packages/react/components/link/Link.native.tsx (2 hunks)
  • packages/react/components/link/Link.stories.tsx (1 hunks)
  • packages/react/components/link/Link.tsx (2 hunks)
  • packages/react/components/link/LinkProps.ts (1 hunks)
  • packages/react/components/link/test/link.test.tsx (1 hunks)

Walkthrough

The pull request introduces significant modifications to the Link component across multiple files in the packages/react/components/link directory and an example React template. The changes primarily involve removing the iconName and inline props, introducing a new markup prop, and simplifying the component's structure. These updates streamline the link component's implementation, providing more flexibility in rendering and reducing complexity.

Changes

File Change Summary
examples/react-template/screens/Link.tsx Updated import statements, removed iconName prop, introduced Icon component
packages/react/components/link/Link.native.tsx Removed inline and iconName props, simplified rendering logic
packages/react/components/link/Link.stories.tsx Minor formatting changes, updated story configurations
packages/react/components/link/Link.tsx Removed iconName prop, added markup prop, consolidated rendering logic
packages/react/components/link/LinkProps.ts Removed routerLink, iconName, and inline props, added markup prop
packages/react/components/link/test/link.test.tsx Removed icon rendering test, updated router link test

Suggested labels

Ready

Suggested reviewers

  • air-one-x

Poem

🐰 A link's journey, props stripped away,
Simplicity dancing in code's ballet
Markup and style, now light and free
A rabbit's code, lean as can be! 🔗✨


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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

🧹 Nitpick comments (7)
packages/react/components/link/Link.stories.tsx (1)

20-20: Consider adding a comment to explain markup usage

The story demonstrates the new markup prop usage, but it would be helpful to add a comment explaining when to use 'span' vs default markup.

+      {/* Use markup='span' for inline links within text content */}
       Je suis dans un paragraphe et ceci est un <Link markup='span'>lien standard</Link>
packages/react/components/link/LinkProps.ts (1)

11-11: LGTM! Good architectural improvement.

The addition of the markup prop and removal of specialized props like iconName and inline makes the Link component more focused and flexible. This change follows the single responsibility principle by delegating icon rendering to the consumer.

packages/react/components/link/test/link.test.tsx (1)

32-34: Consider adding test cases for different markup types.

While the test covers the basic markup='a' case, consider adding test cases for other common element types (button, div, etc.) to ensure the markup prop works correctly with different elements.

Example test case to add:

test('should render with different markup elements', () => {
  const { container } = render(
    <>
      <Link markup="button">Button Link</Link>
      <Link markup="div">Div Link</Link>
    </>
  );
  expect(container.querySelector('button')).toBeInTheDocument();
  expect(container.querySelector('div')).toBeInTheDocument();
});
packages/react/components/link/Link.tsx (2)

4-4: Remove unnecessary space in import statement

The import statement contains extra spaces between curly braces.

-import {  is } from '@/services/classify'
+import { is } from '@/services/classify'

40-51: Component rendering has been effectively simplified

The new rendering approach with LinkComponent is more flexible and maintainable:

  • Proper spreading of props
  • Clean conditional handling of blank target
  • Appropriate aria-label implementation

However, consider adding prop-types or TypeScript validation for the markup prop to ensure only valid HTML elements or components are passed.

+const validMarkups = ['a', 'button', 'div', 'span'] as const
+type ValidMarkup = typeof validMarkups[number]
+
 const Link = ({
   children,
   className,
   accessibilityLabel,
-  markup: LinkComponent = 'a',
+  markup: LinkComponent = 'a' as ValidMarkup,
   inverted,
   blank,
   ...others
-}: LinkProps): JSX.Element => {
+}: LinkProps & { markup?: ValidMarkup | React.ComponentType }): JSX.Element => {
packages/react/components/link/Link.native.tsx (2)

24-28: Review hardcoded padding and margin values

The removal of dynamic padding based on inline prop has led to hardcoded values. Consider:

  1. Using design tokens for these values
  2. Making these values configurable through theme
+const LINK_STYLES = {
+  padding: 8,
+  marginTop: 0,
+  marginBottom: -10,
+  paddingHorizontal: 0,
+} as const

 const styles = StyleSheet.create({
   container: {
-    padding: 8,
-    marginTop: 0,
-    marginBottom: -10,
-    paddingLeft: 0,
-    paddingRight: 0,
+    ...LINK_STYLES,
   },
   androidContainer: {
-    paddingLeft: 0,
-    paddingRight: 0,
+    paddingHorizontal: LINK_STYLES.paddingHorizontal,
   },

Also applies to: 31-32


90-96: Text component implementation is clean but could be more accessible

The Text component implementation is clean, but consider enhancing accessibility:

 <Text
   accessibilityLabel={accessibilityLabel}
+  accessibilityRole="link"
+  accessible={true}
   style={Platform.OS === 'android' ? [styles.androidLink] : [styles.link]}
   {...others}
 >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b26dbb and 7ea64f8.

📒 Files selected for processing (6)
  • examples/react-template/screens/Link.tsx (2 hunks)
  • packages/react/components/link/Link.native.tsx (2 hunks)
  • packages/react/components/link/Link.stories.tsx (1 hunks)
  • packages/react/components/link/Link.tsx (2 hunks)
  • packages/react/components/link/LinkProps.ts (1 hunks)
  • packages/react/components/link/test/link.test.tsx (1 hunks)
🔇 Additional comments (7)
packages/react/components/link/Link.stories.tsx (2)

31-31: LGTM! Good demonstration of markup prop usage

The story correctly demonstrates how to use the markup prop for inline links.


44-51: LGTM! Clear demonstration of inverted prop

The story effectively shows how to use the inverted prop with appropriate background context.

examples/react-template/screens/Link.tsx (2)

2-3: LGTM! Clean import organization.

Good separation of concerns by splitting the imports between core components and icon-specific imports.


19-22: Verify icon positioning matches previous behavior.

The icon is now explicitly composed within the Link component. While this provides more flexibility, ensure that the visual presentation (spacing, alignment) matches the previous implementation where iconName was used.

packages/react/components/link/Link.tsx (2)

28-35: Props interface has been effectively simplified

The removal of iconName and addition of markup prop with a default value of 'a' improves the component's flexibility while reducing complexity. The destructuring is clean and well-organized.


38-38: Verify the impact of removing iconName from classes

The class construction has been simplified, but we should verify that this doesn't break existing styles that might depend on icon-related classes.

✅ Verification successful

Removal of icon-related classes is safe to proceed

Based on the comprehensive review of the changes and related files:

  • The iconName prop and related code has been completely removed from the Link component
  • The test files don't contain any icon-specific test cases that would break
  • The stories don't showcase any icon-related use cases
  • The LinkProps interface has been cleaned up to remove icon-related props
  • No CSS/SCSS files were found that depend on the icon-related classes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any CSS/SCSS files that might reference icon-related classes
rg -t css -t scss 'link.*icon|icon.*link' 

Length of output: 72


Script:

#!/bin/bash
# Search for any CSS/SCSS files that might reference icon-related classes
# Using fd to find style files first, then grep through them
fd -e css -e scss -e sass | xargs rg 'link.*icon|icon.*link'

# Also check for styled-components usage with icon in Link component
ast-grep --pattern 'styled.$_`
  $_icon$_
`'

Length of output: 109


Script:

#!/bin/bash
# Let's check the history of the Link component to understand the icon-related changes
git show HEAD -- packages/react/components/link/Link.tsx

# Also search for any tests or stories that might show icon usage
fd -e test.tsx -e test.ts -e stories.tsx -e stories.ts | xargs rg -l 'Link.*icon|icon.*Link'

# Check for any styled components or CSS modules directly related to Link
fd -g '*link*' -t f packages/react/components/link/

Length of output: 3982


Script:

#!/bin/bash
# Let's check the test files and stories to see if there were any icon-related test cases
cat packages/react/components/link/test/link.test.tsx
cat packages/react/components/link/Link.stories.tsx

# Also check LinkProps to understand the complete removal of icon-related props
cat packages/react/components/link/LinkProps.ts

Length of output: 3235

packages/react/components/link/Link.native.tsx (1)

17-17: Props interface aligns with web version

The props interface has been effectively simplified to match the web version, maintaining consistency across platforms.

packages/react/components/link/Link.stories.tsx Outdated Show resolved Hide resolved
packages/react/components/link/Link.stories.tsx Outdated Show resolved Hide resolved
@FelixLgr FelixLgr changed the title ♻️ Refacto link ♻️ Refacto link (breaking) Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant