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: added an ads entity context menu template component #39358

Merged
merged 3 commits into from
Feb 20, 2025

Conversation

alex-golovanov
Copy link
Contributor

@alex-golovanov alex-golovanov commented Feb 19, 2025

Description

Extracted EntityContextMenu, used in EntityItems, into ADS templates.

Fixes #39355

Automation

/ok-to-test tags="@tag.IDE"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13416528173
Commit: dd82e81
Cypress dashboard.
Tags: @tag.IDE
Spec:


Wed, 19 Feb 2025 16:15:34 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced an interactive context menu component featuring options such as Rename, Copy, and Delete with a tooltip display.
    • Added a demonstration story to preview the new component in an interactive development environment.
    • Enhanced styling to provide a refined and consistent user interface for the context menu.
    • Expanded accessibility of the EntityContextMenu by integrating it into various components within the application.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

This pull request introduces the new EntityContextMenu feature. It adds the React component along with its styled components and an associated enumeration for class names. A Storybook story is provided to showcase the component with a tooltip and several menu items. Additionally, export statements have been updated to include the new module in the design system's templates.

Changes

File(s) Summary
app/client/.../EntityContextMenu/EntityContextMenu.stories.tsx Added Storybook story (Basic) for EntityContextMenu showcasing tooltip and menu items ("Rename", "Copy", "Delete") with console log actions.
app/client/.../EntityContextMenu/EntityContextMenu.styles.ts Introduced styled components: MenuContent (with fixed width and no max height) and ButtonContainer (with relative positioning).
app/client/.../EntityContextMenu/EntityContextMenu.tsx Created the EntityContextMenu React component using useToggle for state management, integrating a tooltip and rendering menu content based on children props.
app/client/.../EntityContextMenu/constants.ts Added new enum EntityClassNames with constants for class names used in the context menu.
app/client/.../EntityContextMenu/index.ts
app/client/.../Templates/index.ts
Updated export statements to expose the EntityContextMenu component for broader usage.
app/client/.../JSEntityItem/JSEntityItem.tsx Updated import of EntityContextMenu to source from @appsmith/ads, maintaining existing functionality.
app/client/.../QueryEntityItem/QueryEntityItem.tsx Modified import of EntityContextMenu to use the version from @appsmith/ads, preserving component logic.
app/client/.../AppJSEditorContextMenu.tsx Consolidated import statements for MenuSeparator and EntityContextMenu from @appsmith/ads.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant ECM as EntityContextMenu
    participant M as Menu
    participant T as Tooltip

    U->>ECM: Click on MenuTrigger button
    ECM->>ECM: Toggle menu open state (useToggle)
    ECM->>T: Disable tooltip when menu is open
    ECM->>M: Render Menu with MenuContent (children)
    M-->>U: Display menu options ("Rename", "Copy", "Delete")
Loading

Suggested labels

skip-changelog

Suggested reviewers

  • hetunandu
  • ankitakinger

Poem

In the realm of code so bright,
A menu dances into sight.
Toggled states and tooltips play,
Guiding clicks in a whimsical way.
Styled and structured with artful cheer,
Our context menu shines ever clear.
Happy coding, now and here!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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.

@github-actions github-actions bot added Design System Product Appsmith design system related issues Frontend This label marks the issue or pull request to reference client code IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo Enhancement New feature or request labels Feb 19, 2025
@alex-golovanov alex-golovanov added the ok-to-test Required label for CI label Feb 19, 2025
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 (5)
app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts (1)

1-4: LGTM! Consider adding JSDoc comments.

The enum values follow a consistent naming pattern and are descriptive.

Add JSDoc comments to document the purpose of each class name:

 export enum EntityClassNames {
+  /** Class name for the context menu container */
   CONTEXT_MENU = "entity-context-menu",
+  /** Class name for the context menu content wrapper */
   CONTEXT_MENU_CONTENT = "entity-context-menu-content",
 }
app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts (1)

5-8: Consider making the width more flexible.

A fixed width of 220px might be too restrictive for different content lengths. Consider using min-width or max-width instead.

 export const MenuContent = styled(ADSMenuContent)`
-  width: 220px;
+  min-width: 220px;
+  max-width: 300px;
   max-height: unset;
 `;
app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx (1)

22-24: Replace console.log with action handlers.

While console.log is fine for stories, consider using Storybook's action handlers for better debugging.

+import { action } from '@storybook/addon-actions';
+
 export const Basic: Story = {
   args: {
     tooltipContent: "More actions",
     children: (
       <>
-        <MenuItem onClick={console.log} startIcon="edit-line">
+        <MenuItem onClick={action('rename-clicked')} startIcon="edit-line">
           Rename
         </MenuItem>
-        <MenuItem onClick={console.log} startIcon="copy-control">
+        <MenuItem onClick={action('copy-clicked')} startIcon="copy-control">
           Copy
         </MenuItem>
-        <MenuItem onClick={console.log} startIcon="delete">
+        <MenuItem onClick={action('delete-clicked')} startIcon="delete">
           Delete
         </MenuItem>
       </>
     ),
   },
 };

Also applies to: 25-27, 28-30

app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx (2)

11-14: Add JSDoc documentation and improve type specificity.

Consider adding documentation for the props and being more specific about the children type if possible.

+/**
+ * Props for the EntityContextMenu component
+ * @param children - Menu items to be rendered inside the context menu
+ * @param tooltipContent - Content to be displayed in the tooltip
+ */
 interface Props {
-  children?: React.ReactNode[] | React.ReactNode;
+  children?: React.ReactElement | React.ReactElement[];
   tooltipContent: React.ReactNode;
 }

16-49: Consider adding error boundary and loading states.

The component implementation is solid with good accessibility features and test coverage. Consider adding error boundaries and loading states for better user experience.

 export const EntityContextMenu = (props: Props) => {
   const { children, tooltipContent } = props;
   const [isMenuOpen, toggleMenuOpen] = useToggle();
+  const [isLoading, setIsLoading] = React.useState(false);
 
   return (
     <Menu onOpenChange={toggleMenuOpen} open={isMenuOpen}>
       <MenuTrigger className="t--context-menu">
         <Styled.ButtonContainer>
           <Tooltip
             content={tooltipContent}
             isDisabled={isMenuOpen}
             mouseLeaveDelay={0}
             placement="right"
           >
             <Button
               className={EntityClassNames.CONTEXT_MENU}
               data-testid="t--more-action-trigger"
               isIconButton
               kind="tertiary"
               startIcon="more-2-fill"
+              isLoading={isLoading}
             />
           </Tooltip>
         </Styled.ButtonContainer>
       </MenuTrigger>
       <Styled.MenuContent
         align="start"
         className={`t--entity-context-menu ${EntityClassNames.CONTEXT_MENU_CONTENT}`}
         side="right"
       >
+        <React.Suspense fallback={<div>Loading...</div>}>
           {children}
+        </React.Suspense>
       </Styled.MenuContent>
     </Menu>
   );
 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b61634 and 7296773.

📒 Files selected for processing (6)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/index.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
  • GitHub Check: chromatic-deployment
🔇 Additional comments (4)
app/client/packages/design-system/ads/src/Templates/index.ts (1)

7-7: LGTM!

The export follows the established pattern and maintains alphabetical ordering.

app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.styles.ts (1)

10-12: LGTM!

The ButtonContainer styling is appropriate for positioning the context menu trigger.

app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.stories.tsx (1)

8-11: LGTM! Story setup is well-structured.

The story metadata is properly configured with appropriate title and component reference.

app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx (1)

1-9: LGTM! Well-organized imports.

Imports are properly organized with external dependencies first, followed by internal components and local imports.

@alex-golovanov alex-golovanov enabled auto-merge (squash) February 19, 2025 11:58
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 (1)
app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx (1)

31-59: Consider adding keyboard navigation support.

The menu implementation looks good, but could benefit from explicit keyboard navigation support for accessibility.

Consider adding:

 <Menu onOpenChange={toggleMenuOpen} open={isMenuOpen}>
+  <MenuTrigger className="t--context-menu" aria-label={tooltipContent}>
-  <MenuTrigger className="t--context-menu">
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7296773 and dd82e81.

📒 Files selected for processing (5)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts (1 hunks)
  • app/client/src/pages/AppIDE/components/JSEntityItem/JSEntityItem.tsx (1 hunks)
  • app/client/src/pages/AppIDE/components/QueryEntityItem/QueryEntityItem.tsx (1 hunks)
  • app/client/src/pages/Editor/JSEditor/AppJSEditorContextMenu.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • app/client/src/pages/Editor/JSEditor/AppJSEditorContextMenu.tsx
  • app/client/src/pages/AppIDE/components/JSEntityItem/JSEntityItem.tsx
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
🔇 Additional comments (4)
app/client/packages/design-system/ads/src/Templates/EntityContextMenu/constants.ts (2)

1-4: LGTM! Well-structured enum for class names.

The enum provides clear, consistent naming for CSS classes.


6-7: Consider making test ID configurable per usage context.

Based on past review comments, the hardcoded test ID caused issues with multiple elements in fullscreen mode.

Consider making this more specific or allowing override per context:

-export const DEFAULT_DATA_TEST_ID = "t--more-action-trigger";
+export const DEFAULT_DATA_TEST_ID = "t--entity-more-action-trigger";
app/client/packages/design-system/ads/src/Templates/EntityContextMenu/EntityContextMenu.tsx (1)

16-20: LGTM! Well-structured props interface.

Props are clearly defined with appropriate types.

app/client/src/pages/AppIDE/components/QueryEntityItem/QueryEntityItem.tsx (1)

51-58: LGTM! Proper memoization of context menu.

The context menu is correctly memoized with appropriate dependencies.

@alex-golovanov alex-golovanov merged commit 0fdac20 into release Feb 20, 2025
50 of 53 checks passed
@alex-golovanov alex-golovanov deleted the feat/39355-ads-entity-context-menu branch February 20, 2025 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design System Product Appsmith design system related issues Enhancement New feature or request Frontend This label marks the issue or pull request to reference client code IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract EntityContextMenu to ADS
2 participants