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

refactor(ActionMenuItem): expose ActionMenuItem as a standalone component #1457

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

Conversation

JoannaSikora
Copy link
Contributor

@JoannaSikora JoannaSikora commented Dec 19, 2024

Resolves: n/a

Description

This pull request reorganizes the ActionMenuItem component by moving it to its own directory and updating its references throughout the codebase. Additionally, it introduces new documentation and storybook entries for the ActionMenuItem component. The most important changes include updating imports, adding new documentation, and creating new storybook entries.

Storybook

https://feature-move-actionmenuitem--613a8e945a5665003a05113b.chromatic.com

Checklist

Obligatory:

  • Self review (use this as your final check for proposed changes before requesting the review)
  • Add correct label
  • Assign pull request with the correct issue

Summary by CodeRabbit

  • New Features

    • Introduced new documentation for the ActionMenuItem component.
    • Added new stories for the ActionMenuItem component showcasing different options.
    • Added a new CSS class for better styling of the action menu preview.
  • Bug Fixes

    • Restructured import statements for ActionMenuItem to improve modularity.
  • Documentation

    • Created documentation file for ActionMenuItem with usage examples and API details.
  • Chores

    • Updated exports to remove Alert and include ActionMenuItem in the main index.

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

Walkthrough

This pull request introduces a refactoring of the ActionMenuItem component, separating it from the ActionMenu module into its own dedicated module. The changes include updating import statements across multiple files, creating new documentation, stories, and type definitions, and adjusting the main package exports. The restructuring enhances modularity and clarity within the React components library.

Changes

File Change Summary
packages/react-components/src/components/ActionBar/ActionBar.tsx Updated import for ActionMenuItem from separate module
packages/react-components/src/components/ActionMenu/ActionMenu.stories.tsx Updated import path for ActionMenuItem, removed subcomponents declaration
packages/react-components/src/components/ActionMenu/index.ts Removed ActionMenuItem export
packages/react-components/src/components/ActionMenu/types.ts Removed ActionMenuItemProps interface
packages/react-components/src/components/ActionMenuItem/* New module with documentation, stories, types, and component
packages/react-components/src/components/InviteAgents/InviteAgents.tsx Updated import for ActionMenuItem from separate module
packages/react-components/src/index.ts Removed Alert export, added ActionMenuItem export
packages/react-components/src/components/ActionMenuItem/ActionMenuItem.tsx Updated type declaration for ActionMenuItem

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • VadymBezpalko
  • vladko-uxds

🪧 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.

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.

@JoannaSikora JoannaSikora marked this pull request as ready for review December 19, 2024 08:03
@JoannaSikora JoannaSikora added the documentation Documentation of any kind label Dec 19, 2024
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

🧹 Nitpick comments (4)
packages/react-components/src/components/ActionMenuItem/types.ts (1)

3-16: Consider expanding the 'kind' prop options

The 'kind' prop only supports 'warning'. Consider adding more semantic variants like 'danger', 'info', or 'success' for better flexibility.

packages/react-components/src/components/ActionMenu/stories-constants.tsx (1)

Line range hint 46-52: Simplify story examples

Using Array spread to generate multiple similar items makes the stories less meaningful. Consider showing fewer, more diverse examples instead.

-  ...[...Array(10)].map((_, index) => ({
-    key: `option${index + 8}`,
-    element: <ActionMenuItem>{`Menu item #${index + 8}`}</ActionMenuItem>,
-    onClick: noop,
-  })),
+  {
+    key: 'more',
+    element: <ActionMenuItem>More options...</ActionMenuItem>,
+    onClick: noop,
+  }
packages/react-components/src/components/ActionMenuItem/ActionMenuItem.mdx (1)

22-26: Enhance example implementation

Add real-world examples demonstrating common use cases and accessibility best practices.

// Add examples like:
<ActionMenuItem 
  leftNode={<Icon source={Delete} />} 
  kind="warning"
  aria-label="Delete item permanently"
>
  Delete permanently
</ActionMenuItem>
packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.tsx (1)

27-45: Consider using action handlers instead of noop

Replace noop with Storybook's action handlers to enable click tracking in the Storybook UI.

-import noop from '../../utils/noop';
+import { action } from '@storybook/addon-actions';

 const defaultOptions = [
   {
     key: 'one',
     element: <ActionMenuItem>Simple Item 1</ActionMenuItem>,
-    onClick: noop,
+    onClick: action('clicked-item-1'),
   },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8736e71 and 28ee338.

📒 Files selected for processing (12)
  • packages/react-components/src/components/ActionBar/ActionBar.tsx (1 hunks)
  • packages/react-components/src/components/ActionMenu/ActionMenu.stories.tsx (1 hunks)
  • packages/react-components/src/components/ActionMenu/index.ts (0 hunks)
  • packages/react-components/src/components/ActionMenu/stories-constants.tsx (1 hunks)
  • packages/react-components/src/components/ActionMenu/types.ts (0 hunks)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.mdx (1 hunks)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.css (1 hunks)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.tsx (1 hunks)
  • packages/react-components/src/components/ActionMenuItem/index.ts (1 hunks)
  • packages/react-components/src/components/ActionMenuItem/types.ts (1 hunks)
  • packages/react-components/src/components/InviteAgents/InviteAgents.tsx (1 hunks)
  • packages/react-components/src/index.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/react-components/src/components/ActionMenu/index.ts
  • packages/react-components/src/components/ActionMenu/types.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/react-components/src/components/ActionMenuItem/index.ts
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.css
  • packages/react-components/src/components/ActionBar/ActionBar.tsx
🔇 Additional comments (4)
packages/react-components/src/index.ts (1)

11-11: LGTM: Export follows alphabetical order

The new export for ActionMenuItem is correctly placed in alphabetical order among other component exports.

packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.tsx (1)

23-23: Verify if chromatic delay is necessary

The 300ms delay parameter might affect test execution time. Verify if it's required for proper rendering.

✅ Verification successful

The 300ms chromatic delay is consistently used across interactive components

The delay is used in all popup/interactive components (ActionMenu, Picker, AutoComplete, Popover, Tooltip) to ensure proper visual testing of animations and transitions. This is a standardized pattern in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other menu components use similar delay
rg -l 'chromatic.*delay' packages/react-components/src/components/**/stories.tsx

Length of output: 180


Script:

#!/bin/bash
# Let's try a more accurate search for stories files with chromatic delay
fd "stories\.tsx$" packages/react-components/src/components/ -x rg -l "chromatic.*delay" {}

# Also search for any chromatic configuration in the codebase
rg -l "chromatic.*delay"

Length of output: 1006


Script:

#!/bin/bash
# Let's check the actual delay values in these components
rg "chromatic.*delay" packages/react-components/src/components/*/stories.tsx -C 1

Length of output: 180


Script:

#!/bin/bash
# Let's check the actual delay values using exact paths we found earlier
rg "chromatic.*delay" packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.tsx packages/react-components/src/components/Tooltip/Tooltip.stories.tsx packages/react-components/src/components/Popover/Popover.stories.tsx packages/react-components/src/components/Picker/Picker.stories.tsx packages/react-components/src/components/AutoComplete/AutoComplete.stories.tsx packages/react-components/src/components/ActionMenu/ActionMenu.stories.tsx -C 2

Length of output: 3259

packages/react-components/src/components/ActionMenu/ActionMenu.stories.tsx (1)

6-6: Verify all ActionMenuItem imports are updated

The import path has been updated correctly. Let's verify all other files have been updated consistently.

✅ Verification successful

The previous search might have been too specific. Let's broaden it to find all ActionMenuItem imports and analyze their patterns.


All ActionMenuItem imports are correctly updated

All files importing ActionMenuItem are using the correct relative path ../ActionMenuItem or local imports within the ActionMenuItem component directory itself.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining old imports
rg -l "from ['\"].*ActionMenu['\"].*ActionMenuItem" packages/react-components/src/

Length of output: 88


Script:

#!/bin/bash
# Search for any ActionMenuItem imports using ripgrep
rg "import.*ActionMenuItem" packages/react-components/src/

# Also search for potential relative imports
rg "from ['\"]\..*ActionMenuItem" packages/react-components/src/

Length of output: 2752

packages/react-components/src/components/InviteAgents/InviteAgents.tsx (1)

14-15: LGTM! Import changes align with component restructuring.

The separation of imports reflects the new standalone nature of ActionMenuItem.

Let's verify the new import paths are working:

✅ Verification successful

Import changes are correctly implemented across the codebase

All files importing ActionMenuItem are now using the correct standalone path. The component exists in its dedicated location with proper test, story, and implementation files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the ActionMenuItem component exists in its new location
fd -e tsx -e ts "ActionMenuItem" packages/react-components/src/components/

# Verify no other files still import ActionMenuItem from ActionMenu
rg "import.*ActionMenuItem.*from.*ActionMenu" packages/react-components/src/

Length of output: 1291

Comment on lines +28 to +30
## Component API <a id="ComponentAPI" />

<ArgTypes of={ActionMenuItemStories.Default} sort="requiredFirst" />
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add accessibility documentation

Include a section about ARIA attributes, keyboard navigation, and screen reader considerations.

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

🧹 Nitpick comments (2)
packages/react-components/src/components/ActionMenuItem/ActionMenuItem.tsx (2)

13-18: Consider adding JSDoc comments

Adding JSDoc comments would improve the component's documentation, especially for the kind prop values.

Example:

+/**
+ * A menu item component that supports left/right nodes and different variants
+ * @param {Object} props
+ * @param {ReactNode} props.leftNode - Content to render on the left side
+ * @param {ReactNode} props.rightNode - Content to render on the right side
+ * @param {'warning' | undefined} props.kind - Variant of the menu item
+ */
export const ActionMenuItem: FC<PropsWithChildren<ActionMenuItemProps>> = ({

Line range hint 19-36: Add accessibility attributes

Consider enhancing accessibility by adding appropriate ARIA attributes and keyboard interaction support.

   <div
     className={cx(styles[baseClass], {
       [styles[`${baseClass}--warning`]]: kind === 'warning',
     })}
+    role="menuitem"
+    tabIndex={0}
   >
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 28ee338 and 20fe36f.

📒 Files selected for processing (4)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.css (1 hunks)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.tsx (1 hunks)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.tsx (2 hunks)
  • packages/react-components/src/components/ActionMenuItem/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.css
  • packages/react-components/src/components/ActionMenuItem/types.ts
  • packages/react-components/src/components/ActionMenuItem/ActionMenuItem.stories.tsx
🔇 Additional comments (1)
packages/react-components/src/components/ActionMenuItem/ActionMenuItem.tsx (1)

Line range hint 1-11: LGTM! Clean import structure

The imports are well-organized and follow best practices with proper separation of concerns.

Copy link

@vladko-uxds vladko-uxds left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation of any kind
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants