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

[Lexical] Create initial Gallery View with Emoji Plugin Example #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

korbit-ai[bot]
Copy link

@korbit-ai korbit-ai bot commented Aug 15, 2024

User description

WHAT

Create initial Gallery View with Emoji Plugin Example

Description

  • Added initial Gallery View to have list of cards from Intern and Extern

  • TODO Have a details view for a card with description, right now it just kinda opens the example in a separate sandbox

Test plan

https://lexical-agv4wnh6m-fbopensource.vercel.app/gallery

Screenshot 2024-07-04 at 1 38 19 PM

Description by Korbit AI

Note

This feature is in early access. You can enable or disable it in the Korbit Console.

What change is being made?

Create an initial Gallery View with an example of the Emoji Plugin, including new components for the gallery and updates to the Docusaurus configuration.

Why are these changes being made?

This change introduces a new Gallery section to showcase various plugins, starting with the Emoji Plugin. It enhances the documentation site by providing visual examples and interactive demos, making it easier for users to understand and utilize the plugins.


PR Type

enhancement, documentation


Description

  • Introduced a new Gallery feature with an example of the Emoji Plugin.
  • Added new components (Card, GalleryCards, GalleryPage) to support the Gallery view.
  • Updated Docusaurus configuration to include a Gallery link in the navigation.
  • Defined a list of plugins for the Gallery, starting with the Emoji Plugin.
  • Added CSS styles for the Gallery layout and card components.

Changes walkthrough 📝

Relevant files
Configuration changes
docusaurus.config.js
Update Docusaurus configuration for Gallery integration   

packages/lexical-website/docusaurus.config.js

  • Removed internal plugin configuration.
  • Added a new 'Gallery' link to the navigation.
  • +5/-26   
    Enhancement
    Card.js
    Add Card component for Gallery items                                         

    packages/lexical-website/src/components/Gallery/Card.js

  • Created a new Card component for displaying gallery items.
  • Utilized clsx for conditional class names.
  • +48/-0   
    GalleryCards.js
    Implement GalleryCards component for displaying plugin cards

    packages/lexical-website/src/components/Gallery/GalleryCards.js

  • Introduced GalleryCards component to render a list of cards.
  • Integrated plugins list for dynamic card generation.
  • +38/-0   
    GalleryPage.js
    Create GalleryPage component for main gallery display       

    packages/lexical-website/src/components/Gallery/GalleryPage.js

    • Created GalleryPage component to serve as the main gallery page.
    +17/-0   
    pluginList.js
    Define plugin list for Gallery display                                     

    packages/lexical-website/src/components/Gallery/pluginList.js

  • Defined a list of plugins for the gallery.
  • Included EmojiPlugin as an initial example.
  • +14/-0   
    styles.module.css
    Add styles for Gallery components and layout                         

    packages/lexical-website/src/components/Gallery/styles.module.css

  • Added styles for the gallery card layout and appearance.
  • Included responsive grid layout for cards.
  • +68/-0   
    Miscellaneous
    sdoc-cache.json
    Add generated sdoc-cache.json file                                             

    packages/lexical-website/fb/sdoc-cache.json

    • Added a generated cache file for snippets.
    +4/-0     
    Documentation
    gallery.md
    Update gallery page to use new GalleryPage component         

    packages/lexical-website/src/pages/gallery.md

  • Updated import path for GalleryPage.
  • Removed WIP label from Gallery title.
  • +2/-2     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Summary by CodeRabbit

    • New Features

      • Introduced a new Gallery section with card UI elements to display items dynamically.
      • Added responsive styling for gallery items to enhance visual presentation.
      • Simplified the documentation structure by removing unnecessary configuration options.
      • Updated the gallery page to reflect a cleaner import structure and improved heading.
    • Bug Fixes

      • Ensured unconditional rendering of the 'Gallery' navigation item for better accessibility.
    • Chores

      • Created a new configuration file for documentation caching to streamline build processes.

    Copy link
    Author

    korbit-ai bot commented Aug 15, 2024

    Clone of the PR facebook/lexical#6369

    Copy link
    Author

    korbit-ai bot commented Aug 15, 2024

    My review is in progress 📖 - I will have feedback for you in a few minutes!

    Copy link

    coderabbitai bot commented Aug 15, 2024

    Important

    Review skipped

    Auto reviews are disabled on this repository.

    Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

    You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

    Walkthrough

    The recent modifications to the lexical website enhance its structure and functionality by simplifying the configuration, introducing new React components for a gallery, and improving styling. The removal of the conditional plugin logic streamlines the setup, while new components like Card, GalleryCards, and GalleryPage establish a clearer presentation of items. These changes together contribute to a more intuitive and visually appealing user experience.

    Changes

    Files Change Summary
    packages/lexical-website/docusaurus.config.js Removed conditional logic for plugins and documentation structure, enhancing visibility of 'Gallery' navigation.
    packages/lexical-website/fb/sdoc-cache.json Introduced a configuration cache file with an empty "snippets" object.
    packages/lexical-website/src/components/Gallery/Card.js Added a new Card component for displaying item details; optimized with React.memo.
    packages/lexical-website/src/components/Gallery/GalleryCards.js Implemented GalleryCards component to manage and render a collection of Card components.
    packages/lexical-website/src/components/Gallery/GalleryPage.js Created GalleryPage as a container for the gallery interface, rendering the GalleryCards component.
    packages/lexical-website/src/components/Gallery/pluginList.js Added plugins constant to manage plugin definitions dynamically.
    packages/lexical-website/src/components/Gallery/styles.module.css Introduced styling for the gallery component to enhance layout and visual presentation.
    packages/lexical-website/src/pages/gallery.md Updated import path for GalleryPage and simplified the heading.

    Sequence Diagram(s)

    sequenceDiagram
        participant User
        participant GalleryPage
        participant GalleryCards
        participant Card
    
        User->>GalleryPage: Request gallery
        GalleryPage->>GalleryCards: Fetch card data
        GalleryCards->>Card: Render individual cards
        Card->>User: Display gallery items
    
    Loading

    Poem

    🐇 In the garden where the rabbits play,
    Changes sprout like blooms in May.
    Cards and galleries, bright and new,
    A joyful leap, our dreams come true!
    With styles that dance and plugins that sing,
    Hooray for the wonders that these changes bring! 🌼✨


    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>.
      • 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 generate interesting stats about this repository and render them as a table.
      • @coderabbitai show all the console.log statements in this repository.
      • @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 as 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.

    Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

    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
    Author

    @korbit-ai korbit-ai bot left a comment

    Choose a reason for hiding this comment

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

    I have reviewed your code and found 5 potential issues.

    const image = getCardImage(item);
    return (
    <li key={item.title} className="card shadow--md">
    <a href={item.uri} target="_blank">
    Copy link
    Author

    Choose a reason for hiding this comment

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

    category Functionality

    The external link in the Card component is missing important attributes for security and accessibility. When opening links in a new tab (target="_blank"), it's recommended to add rel="noopener noreferrer" to prevent potential security vulnerabilities. Additionally, consider adding an aria-label to the link for better accessibility, especially since it only contains an image.

    Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

    Comment on lines +16 to +26
    function CardList({cards}) {
    return (
    <div className="container">
    <ul className={clsx('clean-list', styles.cardList)}>
    {cards.map((item) => (
    <Card key={item.title} item={item} />
    ))}
    </ul>
    </div>
    );
    }
    Copy link
    Author

    Choose a reason for hiding this comment

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

    category Functionality

    In the CardList component, it's important to add error handling for the 'cards' prop. Currently, if 'cards' is undefined or not an array, the component will throw an error when trying to map over it. Consider adding a check to ensure 'cards' is defined and is an array before mapping, and provide a fallback UI if it's not. This will improve the robustness of the component and prevent potential runtime errors.

    Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

    Comment on lines +25 to +45
    function Card({item}) {
    const image = getCardImage(item);
    return (
    <li key={item.title} className="card shadow--md">
    <a href={item.uri} target="_blank">
    <div className={clsx('card__image', styles.showcaseCardImage)}>
    <img src={image} alt={item.title} />
    </div>
    </a>
    <div className="card__body">
    <div className={clsx(styles.showcaseCardHeader)}>
    <Heading as="h4" className={styles.showcaseCardTitle}>
    <Link href={item.website} className={styles.showcaseCardLink}>
    {item.title}
    </Link>
    </Heading>
    </div>
    <p className={styles.showcaseCardBody}>{item.description}</p>
    </div>
    </li>
    );
    Copy link
    Author

    Choose a reason for hiding this comment

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

    category Functionality

    I noticed that the Card component doesn't handle cases where some properties of the item object might be missing. This could lead to errors if, for example, item.uri or item.website are undefined. Consider adding checks for these properties and providing fallback values. For instance, you could use the optional chaining operator (?.) and nullish coalescing operator (??) to safely access these properties and provide default values.

    Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

    Comment on lines +11 to +17
    export default function GalleryPage() {
    return (
    <main className="margin-vert--lg">
    <GalleryCards />
    </main>
    );
    }
    Copy link
    Author

    Choose a reason for hiding this comment

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

    category Functionality

    The GalleryPage component currently lacks a title or heading. Consider adding an <h1> or <h2> element with an appropriate title (e.g., 'Plugin Gallery') before the <GalleryCards /> component. This will improve the page structure and provide better context for users.

    Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

    Comment on lines +9 to +14
    export const plugins = (customFields) => [
    {
    title: 'EmojiPlugin',
    uri: `${customFields.STACKBLITZ_PREFIX}examples/vanilla-js-plugin?embed=1&file=src%2Femoji-plugin%2FEmojiPlugin.ts&terminalHeight=0&ctl=1`,
    },
    ];
    Copy link
    Author

    Choose a reason for hiding this comment

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

    category Functionality

    The plugins function assumes that customFields.STACKBLITZ_PREFIX is always defined, which may not be the case. To improve robustness, consider adding a check for the existence of customFields and STACKBLITZ_PREFIX, or provide a default value. For example:

    export const plugins = (customFields = {}) => [
      {
        title: 'EmojiPlugin',
        uri: `${customFields.STACKBLITZ_PREFIX || ''}examples/vanilla-js-plugin?embed=1&file=src%2Femoji-plugin%2FEmojiPlugin.ts&terminalHeight=0&ctl=1`,
      },
    ];

    This change will prevent potential runtime errors if customFields or STACKBLITZ_PREFIX is undefined.

    Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

    @furwellness
    Copy link
    Owner

    /review

    Copy link

    codiumai-pr-agent-free bot commented Aug 20, 2024

    PR Reviewer Guide 🔍

    (Review updated until commit 080f5c3)

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Accessibility Concern
    The Card component uses an anchor tag () with an onClick handler, which may not be accessible to keyboard users. Consider using a button element instead or ensuring proper keyboard accessibility.

    Hardcoded Data
    The plugins list is currently hardcoded with only one item. Consider making this more dynamic or extensible for future additions.

    Copy link

    Persistent review updated to latest commit 080f5c3

    @furwellness furwellness reopened this Aug 21, 2024
    @furwellness furwellness changed the base branch from cloned_main_a7a6a to main August 21, 2024 12:41
    @codiumai-pr-agent-free codiumai-pr-agent-free bot added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 21, 2024
    @furwellness
    Copy link
    Owner

    @coderabbitai full review

    Copy link

    Persistent review updated to latest commit 080f5c3

    Copy link

    coderabbitai bot commented Aug 21, 2024

    Actions performed

    Full review triggered.

    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Security
    Enhance security for links opening in new tabs

    Add a rel="noopener noreferrer" attribute to the anchor tag that opens in a new tab.
    This is a security best practice to prevent potential exploitation of the
    window.opener API.

    packages/lexical-website/src/components/Gallery/Card.js [30]

    -<a href={item.uri} target="_blank">
    +<a href={item.uri} target="_blank" rel="noopener noreferrer">
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Adding rel="noopener noreferrer" to links that open in new tabs is a security best practice, preventing potential exploitation of the window.opener API.

    9
    Possible issue
    Add error handling for potential undefined values

    Consider adding error handling for the case where customFields might be undefined.
    This can prevent potential runtime errors and improve the robustness of the
    component.

    packages/lexical-website/src/components/Gallery/GalleryCards.js [28-37]

     export default function GalleryCards() {
       const {
         siteConfig: {customFields},
       } = useDocusaurusContext();
    +
    +  if (!customFields) {
    +    return null; // or some fallback UI
    +  }
     
       return (
         <section className="margin-top--lg margin-bottom--xl">
           <CardList cards={plugins(customFields)} />
         </section>
       );
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding error handling for potentially undefined customFields improves the robustness of the component and prevents runtime errors, which is important for stability.

    8
    Enhancement
    Enhance plugin information for a more comprehensive gallery display

    Consider adding more properties to the plugin object, such as description, to
    provide more information about the plugin. This would allow for a richer display in
    the gallery.

    packages/lexical-website/src/components/Gallery/pluginList.js [9-13]

     export const plugins = (customFields) => [
       {
         title: 'EmojiPlugin',
    +    description: 'A plugin for adding emoji support to your editor',
         uri: `${customFields.STACKBLITZ_PREFIX}examples/vanilla-js-plugin?embed=1&file=src%2Femoji-plugin%2FEmojiPlugin.ts&terminalHeight=0&ctl=1`,
       },
     ];
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Adding a description property to the plugin object enriches the information available for display, improving user experience, but it is not essential for functionality.

    6
    Improve variable naming for better code readability

    Consider using a more descriptive variable name instead of item in the Card
    component. This would make the code more self-explanatory and easier to understand.

    packages/lexical-website/src/components/Gallery/Card.js [25-29]

    -function Card({item}) {
    -  const image = getCardImage(item);
    +function Card({galleryItem}) {
    +  const image = getCardImage(galleryItem);
       return (
    -    <li key={item.title} className="card shadow--md">
    -      <a href={item.uri} target="_blank">
    +    <li key={galleryItem.title} className="card shadow--md">
    +      <a href={galleryItem.uri} target="_blank">
     
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: The suggestion to rename the variable from item to galleryItem improves code readability and clarity, but it is not crucial for functionality.

    5

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

    Outside diff range, codebase verification and nitpick comments (1)
    packages/lexical-website/src/components/Gallery/styles.module.css (1)

    17-21: Consider using CSS variables for colors.

    Using CSS variables for colors can improve maintainability and consistency across the styles.

    Example:

    :root {
      --background-light: #f6fdfd;
      --background-dark: #232525;
    }
    
    .showcaseFavorite {
      background-color: var(--background-light);
    }
    
    html[data-theme='dark'] .showcaseFavorite {
      background-color: var(--background-dark);
    }
    Review details

    Configuration used: CodeRabbit UI
    Review profile: CHILL

    Commits

    Files that changed from the base of the PR and between 4cbb85f and 080f5c3.

    Files selected for processing (8)
    • packages/lexical-website/docusaurus.config.js (3 hunks)
    • packages/lexical-website/fb/sdoc-cache.json (1 hunks)
    • packages/lexical-website/src/components/Gallery/Card.js (1 hunks)
    • packages/lexical-website/src/components/Gallery/GalleryCards.js (1 hunks)
    • packages/lexical-website/src/components/Gallery/GalleryPage.js (1 hunks)
    • packages/lexical-website/src/components/Gallery/pluginList.js (1 hunks)
    • packages/lexical-website/src/components/Gallery/styles.module.css (1 hunks)
    • packages/lexical-website/src/pages/gallery.md (1 hunks)
    Additional comments not posted (5)
    packages/lexical-website/fb/sdoc-cache.json (1)

    1-4: LGTM!

    The file appears to be a generated configuration or cache file. No issues found.

    packages/lexical-website/src/pages/gallery.md (1)

    6-8: LGTM!

    The import path update and heading change are appropriate and improve the organization and clarity of the documentation.

    packages/lexical-website/src/components/Gallery/Card.js (2)

    29-29: Add security attributes to external links.

    When using target="_blank", add rel="noopener noreferrer" for security reasons.

    Use this diff to add the attributes:

      <a href={item.uri} target="_blank" rel="noopener noreferrer">

    Likely invalid or redundant comment.


    25-45: Handle potential undefined properties in Card.

    Ensure that properties like item.uri and item.website are defined before use to prevent runtime errors.

    Use optional chaining and nullish coalescing operators:

      const image = getCardImage(item);
      return (
        <li key={item.title} className="card shadow--md">
    -     <a href={item.uri} target="_blank">
    +     <a href={item.uri ?? '#'} target="_blank" rel="noopener noreferrer">
          <div className={clsx('card__image', styles.showcaseCardImage)}>
            <img src={image} alt={item.title} />
          </div>
        </a>
        <div className="card__body">
          <div className={clsx(styles.showcaseCardHeader)}>
            <Heading as="h4" className={styles.showcaseCardTitle}>
    -         <Link href={item.website} className={styles.showcaseCardLink}>
    +         <Link href={item.website ?? '#'} className={styles.showcaseCardLink}>
                {item.title}
              </Link>
            </Heading>
          </div>
          <p className={styles.showcaseCardBody}>{item.description}</p>
        </div>
      </li>

    Likely invalid or redundant comment.

    packages/lexical-website/docusaurus.config.js (1)

    389-392: Verify the impact of removing conditional logic.

    Ensure that the removal of conditional logic for plugins and configuration does not affect necessary functionality in different environments.

    Run the following script to verify the impact:

    Comment on lines +16 to +23
    function getCardImage(item) {
    return (
    item.preview ??
    `https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
    item.uri,
    )}/showcase`
    );
    }
    Copy link

    Choose a reason for hiding this comment

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

    Ensure item.uri is defined before use.

    Consider adding a check to ensure item.uri is defined before using it to construct the URL. This will prevent potential errors if item.uri is undefined.

    Use this diff to add a check:

      return (
        item.preview ??
    +   (item.uri &&
          `https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
            item.uri,
          )}/showcase`)
      );
    Committable suggestion

    ‼️ IMPORTANT
    Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    Suggested change
    function getCardImage(item) {
    return (
    item.preview ??
    `https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
    item.uri,
    )}/showcase`
    );
    }
    function getCardImage(item) {
    return (
    item.preview ??
    (item.uri &&
    `https://slorber-api-screenshot.netlify.app/${encodeURIComponent(
    item.uri,
    )}/showcase`)
    );
    }

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request issue-evaluation korbit-code-analysis Review effort [1-5]: 3
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants