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

chore: Housekeeping items in List and Entity Item ADS #38537

Merged
merged 2 commits into from
Jan 8, 2025

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Jan 8, 2025

Description

General housekeeping items to ADS ListItem, Editable and Entity Item. In prep for usage of EntityListTree we found these items missing. PR #38493

Automation

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

🔍 Cypress test results

Tip

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


Wed, 08 Jan 2025 11:23:10 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced event handling for list components
    • Improved tooltip visibility management
    • Added unique identifiers for entity items
  • Improvements

    • Streamlined mouse and keyboard event interactions
    • Updated component testing capabilities
    • Refined class name and test ID management
  • Bug Fixes

    • Prevented unintended event propagation in keyboard interactions

The updates focus on improving component interactions, event handling, and testing infrastructure across various design system components.

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Walkthrough

This pull request introduces refinements to the design system's List and EntityItem components, focusing on event handling, type definitions, and component identification. The changes primarily involve updating event callbacks, adding test IDs, and introducing new properties like id for better component management and testability.

Changes

File Change Summary
design-system/ads/src/List/List.tsx Replaced useEffect with useEventCallback for tooltip and event handling
design-system/ads/src/List/List.types.tsx Updated onClick type to include MouseEvent parameter
design-system/ads/src/Templates/EntityExplorer/Editable/useEditableText.ts Added e.stopPropagation() to prevent event bubbling
design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx Added className and data-testid to ListItem
design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.types.ts Introduced id property to EntityItemProps

Sequence Diagram

sequenceDiagram
    participant User
    participant EntityItem
    participant ListItem
    participant EventHandler

    User->>EntityItem: Interact
    EntityItem->>ListItem: Trigger Event
    ListItem->>EventHandler: Process Event
    EventHandler-->>ListItem: Handle Callback
    ListItem-->>EntityItem: Update State
Loading

Possibly related PRs

Suggested Labels

IDE Product, Task, skip-changelog, IDE Pod, ok-to-test

Suggested Reviewers

  • ankitakinger
  • albinAppsmith

Poem

🧩 Code evolves, events dance light,
Components sing with newfound might,
Callbacks refined, IDs take flight,
In design's elegant, structured height!
🚀 Refactoring's pure delight! 🌟


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 the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jan 8, 2025
@hetunandu hetunandu requested a review from ankitakinger January 8, 2025 10:15
@hetunandu hetunandu added the ok-to-test Required label for CI label Jan 8, 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/EntityExplorer/EntityItem/EntityItem.tsx (2)

7-7: Consider renaming import to standard convention.

The clx import alias is less common. Consider using the standard name classnames.

-import clx from "classnames";
+import classnames from "classnames";

81-84: Consider deriving data-testid from id for consistency.

Currently, data-testid uses title while id uses a different value. Consider using id for both to maintain consistency.

-      className={clx("t--entity-item", props.className)}
+      className={classnames("t--entity-item", props.className)}
       customTitleComponent={customTitle}
-      data-testid={`t--entity-item-${props.title}`}
+      data-testid={`t--entity-item-${props.id}`}
       id={"entity-" + props.id}
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.stories.tsx (1)

39-39: Consider adding id to all story variants.

While the id is set in the Template, consider adding different ids in the story variants (InEditingMode, NoPermissionToEdit, etc.) to demonstrate different id values.

Example for story variants:

InEditingMode.args = {
  id: "editing-mode-item",
  title: "EntityName",
  // ... rest of the props
};
app/client/packages/design-system/ads/src/List/List.tsx (1)

103-105: Consider adding a comment explaining the stopPropagation.

While the implementation is correct, it would be helpful to document why event propagation needs to be stopped here.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/Editable/useEditableText.test.tsx (1)

85-85: Add assertions for stopPropagation calls

While the mock for stopPropagation is correctly added, we should verify that it's being called. Add expectations like:

expect(stopPropagationMock).toHaveBeenCalled();

Example implementation:

 const stopPropagationMock = jest.fn();
 handleKeyUp({
   key: "Enter",
-  stopPropagation: jest.fn(),
+  stopPropagation: stopPropagationMock,
 } as unknown as React.KeyboardEvent<HTMLInputElement>);
+expect(stopPropagationMock).toHaveBeenCalled();

Also applies to: 117-117, 139-142, 163-166

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e0e76d6 and 0fac0e7.

📒 Files selected for processing (7)
  • app/client/packages/design-system/ads/src/List/List.tsx (4 hunks)
  • app/client/packages/design-system/ads/src/List/List.types.tsx (2 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/Editable/useEditableText.test.tsx (4 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/Editable/useEditableText.ts (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.stories.tsx (1 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (2 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.types.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • 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 (8)
app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.types.ts (1)

8-9: LGTM! Well-documented type addition.

The new id property is properly typed and documented.

app/client/packages/design-system/ads/src/List/List.types.tsx (1)

2-2: LGTM! Improved type safety for event handling.

The addition of MouseEvent type and updated onClick signature properly type the event parameter, aligning with React's event system.

Also applies to: 14-14

app/client/packages/design-system/ads/src/List/List.tsx (4)

40-57: Improved tooltip performance with event-driven approach.

Good refactor from ref-based DOM queries to direct event handling. The useEventCallback ensures stable event handlers across renders.


87-93: LGTM! Proper event handling implementation.

Good addition of stopPropagation() and proper event typing. The handler correctly checks for disabled state before invoking the callback.


95-101: LGTM! Consistent event handling pattern.

The double click handler follows the same pattern as onClick, maintaining code consistency.


113-113: LGTM! Proper id propagation.

The id prop is correctly passed to the DOM element for accessibility and testing purposes.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/Editable/useEditableText.ts (1)

77-78: Verify the necessity of stopping event propagation

Adding stopPropagation() will prevent Enter/Escape key events from reaching parent components. Ensure this doesn't break any parent component's keyboard event handling that might be relying on these events.

✅ Verification successful

Event propagation change is safe to implement

The stopPropagation() addition is safe as the parent component (EntityItem) only forwards the hook's keyboard handler without adding its own event handling logic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for parent components that might be listening for Enter/Escape key events
rg -B 2 -A 2 "onKeyUp|onKeyDown|onKeyPress" app/client/packages/design-system/ads/src/Templates/EntityExplorer/

Length of output: 692


Script:

#!/bin/bash
# Get the implementation of handleKeyUp in EntityItem
ast-grep --pattern 'const handleKeyUp = $_' app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx

Length of output: 138


Script:

#!/bin/bash
# Search for handleKeyUp with more context
rg -B 5 -A 5 "handleKeyUp" app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx

Length of output: 672

app/client/packages/design-system/ads/src/Templates/EntityExplorer/Editable/useEditableText.test.tsx (1)

85-85: LGTM! Test coverage is complete

The stopPropagation mock has been consistently added to all keyboard event test cases.

Also applies to: 117-117, 139-142, 163-166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants