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: Add useActiveDoubleClick hook for improved double-click handling #39474

Merged
merged 3 commits into from
Feb 28, 2025

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Feb 27, 2025

Description

Introduces a new useActiveDoubleClick hook to manage double-click interactions for editable components. The hook provides a more controlled double-click experience by:

  • Enabling double-click only when an item is active
  • Preventing rapid or unintended double-clicks
  • Simplifying double-click logic across different components

Fixes #39477

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/13565291252
Commit: 2b591c2
Cypress dashboard.
Tags: @tag.IDE
Spec:


Thu, 27 Feb 2025 11:57:50 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Introduced a new hook for improved double-click interactions, enhancing responsiveness on tabs and list items.
  • Refactor
    • Streamlined event handling logic and removed legacy focus management workarounds for improved component efficiency.

Introduces a new useActiveDoubleClick hook to manage double-click interactions for editable components. The hook provides a more controlled double-click experience by:
- Enabling double-click only when an item is active
- Preventing rapid or unintended double-clicks
- Simplifying double-click logic across different components
@hetunandu hetunandu requested a review from a team as a code owner February 27, 2025 09:51
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

Walkthrough

This pull request introduces a new custom hook, useActiveDoubleClick, and integrates it into two UI components to enhance double-click handling. The hook is exported and used in both the EditableDismissibleTab and EntityItem components to conditionally trigger specified callbacks based on the active state. Additionally, a workaround for refocusing an input in an editing component has been removed, simplifying the logic.

Changes

File(s) Change Summary
app/client/.../EditableDismissibleTab.tsx, app/client/.../EntityItem.tsx Updated double-click event handling to use the new useActiveDoubleClick hook and adjusted prop destructuring in EntityItem.
app/client/.../__hooks__/useActiveDoubleClick.ts, app/client/.../__hooks__/index.ts Introduced and exported the useActiveDoubleClick hook, which manages double-click activation using state and effects.
app/client/.../useEditableText/useEditableText.ts Removed the useEffect hook that managed input refocusing in editing mode.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Component
    participant H as useActiveDoubleClick Hook
    participant CB as Callback

    U->>C: Double-click event
    C->>H: Call hook with active state & callback
    H-->>H: Evaluate canDoubleClick (via state/effect)
    alt Double-click enabled
        H->>CB: Execute callback (e.g., enter edit mode)
    else
        H->>C: Return noop function
    end
Loading

Possibly related PRs

Suggested reviewers

  • ankitakinger
  • albinAppsmith

Poem

In the realm of code, a hook takes flight,
Guiding each double-click to do what’s right.
No more hacks lurking in the night,
Clean logic shines with newfound might.
Celebrate the merge with joy and light!
Happy coding! 🎉


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9bacf69 and 2b591c2.

📒 Files selected for processing (1)
  • app/client/packages/design-system/ads/src/__hooks__/useActiveDoubleClick.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/design-system/ads/src/hooks/useActiveDoubleClick.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: perform-test / client-build / client-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: chromatic-deployment
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests

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.
  • @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.

@hetunandu
Copy link
Member Author

/build-deploy-preview

@github-actions github-actions bot added the Enhancement New feature or request label Feb 27, 2025
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13563563851.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 39474.
recreate: .

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

🧹 Nitpick comments (1)
app/client/packages/design-system/ads/src/__hooks__/useActiveDoubleClick.ts (1)

18-20: Consider making the timeout delay configurable or extracting it to a constant.

The hardcoded 200ms value would be more maintainable as a named constant or configurable parameter.

+ const DOUBLE_CLICK_DELAY = 200; // ms
+
export function useActiveDoubleClick(
  isActive: boolean,
  onDoubleClick?: () => void,
+ delayMs: number = DOUBLE_CLICK_DELAY,
) {
  // ...
  
  useEffect(
    function handleDoubleClickEnableBasedOnSelection() {
      if (isActive) {
        setTimeout(() => {
          setCanDoubleClick();
-       }, 200);
+       }, delayMs);
      } else {
        setCannotDoubleClick();
      }
    },
-   [isActive, setCanDoubleClick, setCannotDoubleClick],
+   [isActive, setCanDoubleClick, setCannotDoubleClick, delayMs],
  );
  
  // ...
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3df028d and 9bacf69.

📒 Files selected for processing (5)
  • app/client/packages/design-system/ads/src/Templates/EditableDismissibleTab/EditableDismissibleTab.tsx (2 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (2 hunks)
  • app/client/packages/design-system/ads/src/__hooks__/index.ts (1 hunks)
  • app/client/packages/design-system/ads/src/__hooks__/useActiveDoubleClick.ts (1 hunks)
  • app/client/packages/design-system/ads/src/__hooks__/useEditableText/useEditableText.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • app/client/packages/design-system/ads/src/hooks/useEditableText/useEditableText.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
🔇 Additional comments (8)
app/client/packages/design-system/ads/src/__hooks__/index.ts (1)

3-3: Added export for the new hook looks good.

This export makes the useActiveDoubleClick hook available for import across the application.

app/client/packages/design-system/ads/src/Templates/EditableDismissibleTab/EditableDismissibleTab.tsx (3)

9-9: Import of the new hook looks good.

Correctly imports the useActiveDoubleClick hook from the hooks directory.


38-43: Good implementation of the useActiveDoubleClick hook.

The hook is correctly configured with the component's active state and edit mode handler.


43-43: Clean refactoring of the double-click handler.

This simplifies the conditional logic by leveraging the hook's functionality.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (3)

6-6: Import of the new hook looks good.

Correctly imports the useActiveDoubleClick hook from the hooks directory.


9-14: Good implementation of the useActiveDoubleClick hook.

The hook is correctly configured with the component's selected state and double-click handler. The null check with || false is a good safety measure.


70-70: Correctly applies the double-click override.

The ListItem now uses the enhanced double-click handler from the hook.

app/client/packages/design-system/ads/src/__hooks__/useActiveDoubleClick.ts (1)

1-14: Well-structured hook with appropriate dependencies.

The hook correctly manages state using useBoolean and has a clear function signature.

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/__hooks__/useActiveDoubleClick.ts (1)

1-39: Simplify the handleDoubleClick function logic.

The hook implementation is generally good, but the conditional logic in the handleDoubleClick function can be simplified.

  const handleDoubleClick = useMemo(() => {
    if (!canDoubleClick || !onDoubleClick) {
      return noop;
    }

-   if (canDoubleClick) {
-     return onDoubleClick;
-   }
+   return onDoubleClick;
  }, [canDoubleClick, onDoubleClick]);

The second check for canDoubleClick is redundant since we already confirmed it's true in the first condition.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3df028d and 9bacf69.

📒 Files selected for processing (5)
  • app/client/packages/design-system/ads/src/Templates/EditableDismissibleTab/EditableDismissibleTab.tsx (2 hunks)
  • app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (2 hunks)
  • app/client/packages/design-system/ads/src/__hooks__/index.ts (1 hunks)
  • app/client/packages/design-system/ads/src/__hooks__/useActiveDoubleClick.ts (1 hunks)
  • app/client/packages/design-system/ads/src/__hooks__/useEditableText/useEditableText.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • app/client/packages/design-system/ads/src/hooks/useEditableText/useEditableText.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
  • GitHub Check: chromatic-deployment
  • GitHub Check: storybook-tests
  • GitHub Check: chromatic-deployment
🔇 Additional comments (7)
app/client/packages/design-system/ads/src/__hooks__/index.ts (1)

3-3: Export addition looks good.

Clean addition of the new hook export that follows the established pattern.

app/client/packages/design-system/ads/src/Templates/EntityExplorer/EntityItem/EntityItem.tsx (3)

6-6: Appropriate import added.

The hook import is correctly added from the hooks directory.


9-14: Good implementation of destructuring and hook usage.

Clean implementation that destructures the necessary props early and correctly uses the hook.


70-70: Correct usage of the doubleClickOverride function.

The hook-generated function is properly assigned to the onDoubleClick prop.

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

9-9: Appropriate import added.

The hook import is correctly added from the hooks directory.


38-43: Good implementation of the hook.

The hook is correctly used with the active state and enter edit mode function.

app/client/packages/design-system/ads/src/__hooks__/useActiveDoubleClick.ts (1)

15-26: Consider the timing implications of the timeout.

The 200ms delay before enabling double-clicks after an item becomes active creates a small window where double-clicks won't work immediately after selection. This is likely intentional to prevent accidental double-clicks, but worth verifying this behavior is expected.

Copy link

Deploy-Preview-URL: https://ce-39474.dp.appsmith.com

@hetunandu hetunandu added the ok-to-test Required label for CI label Feb 27, 2025
@github-actions github-actions bot added ADS Components All issues related ADS components Design System Product Appsmith design system related issues IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Feb 27, 2025
ankitakinger
ankitakinger previously approved these changes Feb 27, 2025
[isActive, setCanDoubleClick, setCannotDoubleClick],
);

const handleDoubleClick = useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like you need useMemo here. Callback onDoubleClick and noop are already stable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Merging in for now. It does not harm to keep this in.

@hetunandu hetunandu merged commit efa90ea into release Feb 28, 2025
52 checks passed
@hetunandu hetunandu deleted the chore/entity-item-double-click branch February 28, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADS Components All issues related ADS components Design System Product Appsmith design system related issues Enhancement New feature or request 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.

[Task]: ADS Editable items should only allow double click when selected
4 participants