Skip to content

[WEB-2047] refactor: editor side menu#5329

Merged
SatishGandham merged 2 commits intopreviewfrom
refactor/editor-side-menu
Aug 8, 2024
Merged

[WEB-2047] refactor: editor side menu#5329
SatishGandham merged 2 commits intopreviewfrom
refactor/editor-side-menu

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Aug 8, 2024

Improvements:

Created a new extension to render the editor side menu to support addition of new handles based on the requirement.

Summary by CodeRabbit

  • New Features

    • Introduced a side menu extension for enhanced user interaction with drag-and-drop capabilities and AI features.
    • AI-related functionalities are now accessible through a centralized module, improving organization and ease of use.
  • Bug Fixes

    • Removed unused functionality related to drag handles, streamlining the user experience.
  • Refactor

    • Simplified various components by eliminating unnecessary props and state management, focusing on the new side menu integration.
  • Style

    • Updated styles to reflect the transition from drag handle elements to a responsive side menu layout.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The recent updates enhance the editor by integrating AI features through a contextual side menu, replacing the previous drag-and-drop interface. This shift simplifies component structures, improves modularity, and clarifies event handling. The changes span several files, ensuring a cohesive implementation that supports new functionalities while maintaining performance and usability.

Changes

File Path Change Summary
packages/editor/src/ce/extensions/ai-features/*.ts Introduced handle.ts for AIHandlePlugin, a re-export module in index.ts, and a new side-menu.tsx for enhanced AI feature integration via a side menu interface.
packages/editor/src/core/components/editors/*.tsx Refactored DocumentEditor, PageRenderer, EditorContainer, and EditorWrapper components by removing drag handle state management and associated props, shifting towards a simpler UI without drag-and-drop visibility control.
packages/editor/src/core/hooks/use-document-editor.ts Updated DocumentEditorProps and the useDocumentEditor to replace drag-and-drop with SideMenuExtension, reflecting a shift in how functionalities are implemented.
packages/editor/src/core/plugins/drag-handle.ts Refactored DragHandle function into DragHandlePlugin, adjusting its parameter handling and simplifying event management.
packages/editor/src/core/types/extensions.ts Expanded TExtensions type to include "ai", enhancing the system's capability to recognize AI-related features.
packages/editor/src/styles/drag-drop.css Refactored CSS from drag handle styles to side menu styles, removing unnecessary states and improving layout responsiveness.
packages/editor/src/ee/extensions/ai-features/index.ts New file re-exports all entities from the AI features module for improved modularity.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor
    participant SideMenu

    User->>Editor: Interacts with editor
    Editor->>SideMenu: Trigger side menu visibility
    SideMenu->>Editor: Update context based on user interaction
    Editor->>User: Display updated options
Loading

Poem

🐰 In a garden bright with change so new,
The side menu hops in, with features to view!
No more drag handles, just a sleek design,
Helping all editors feel quite divine.
With AI in bloom, our tasks are so light,
Let's hop and rejoice, everything feels right! 🌼✨


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

Outside diff range, codebase verification and nitpick comments (1)
packages/editor/src/ce/extensions/ai-features/handle.ts (1)

5-12: Consider implementing or documenting placeholders in AIHandlePlugin.

The AIHandlePlugin function currently contains placeholders for view and domEvents. Consider implementing these or adding comments/documentation to clarify future intentions.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 943dd59 and 1cf8a6a.

Files selected for processing (16)
  • packages/editor/src/ce/extensions/ai-features/handle.ts (1 hunks)
  • packages/editor/src/ce/extensions/ai-features/index.ts (1 hunks)
  • packages/editor/src/ce/extensions/index.ts (1 hunks)
  • packages/editor/src/core/components/editors/document/editor.tsx (4 hunks)
  • packages/editor/src/core/components/editors/document/page-renderer.tsx (2 hunks)
  • packages/editor/src/core/components/editors/editor-container.tsx (2 hunks)
  • packages/editor/src/core/components/editors/editor-wrapper.tsx (3 hunks)
  • packages/editor/src/core/components/editors/lite-text/editor.tsx (1 hunks)
  • packages/editor/src/core/components/editors/rich-text/editor.tsx (1 hunks)
  • packages/editor/src/core/extensions/index.ts (1 hunks)
  • packages/editor/src/core/extensions/side-menu.tsx (1 hunks)
  • packages/editor/src/core/hooks/use-document-editor.ts (4 hunks)
  • packages/editor/src/core/plugins/drag-handle.ts (6 hunks)
  • packages/editor/src/core/types/extensions.ts (1 hunks)
  • packages/editor/src/ee/extensions/ai-features/index.ts (1 hunks)
  • packages/editor/src/styles/drag-drop.css (1 hunks)
Files skipped from review due to trivial changes (4)
  • packages/editor/src/ce/extensions/ai-features/index.ts
  • packages/editor/src/core/components/editors/document/editor.tsx
  • packages/editor/src/core/components/editors/lite-text/editor.tsx
  • packages/editor/src/ee/extensions/ai-features/index.ts
Additional comments not posted (23)
packages/editor/src/core/types/extensions.ts (1)

1-1: Change approved for TExtensions type.

The addition of "ai" to the TExtensions type is a straightforward enhancement that allows for AI-related extensions, aligning with the PR objectives.

packages/editor/src/ce/extensions/index.ts (1)

1-1: Export of ai-features approved.

The addition of export * from "./ai-features"; is a necessary step to integrate AI functionalities, supporting the PR's goal of enhancing the editor's capabilities.

packages/editor/src/core/extensions/index.ts (1)

20-20: Verify the impact of export changes.

The export change from drag-drop to side-menu might affect other parts of the codebase. Ensure that any dependencies on drag-drop are updated accordingly.

Verification successful

Export change verification complete: No issues found.

The export change from drag-drop to side-menu does not affect other TypeScript dependencies in the codebase. The only reference to drag-drop is related to a CSS file, which is unrelated to this export change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of export changes from `drag-drop` to `side-menu`.

# Test: Search for occurrences of `drag-drop` and `side-menu` to ensure dependencies are updated.
rg --type typescript 'drag-drop|side-menu'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify the impact of export changes from `drag-drop` to `side-menu`.

# Test: Search for occurrences of `drag-drop` and `side-menu` in TypeScript files to ensure dependencies are updated.
rg --glob '*.ts' 'drag-drop|side-menu'

Length of output: 178

packages/editor/src/core/components/editors/rich-text/editor.tsx (1)

6-6: Verify the integration of SideMenuExtension.

Ensure that the SideMenuExtension is correctly integrated and that its functionality aligns with the requirements. Verify that any previous functionality provided by DragAndDrop is adequately replaced or re-implemented.

packages/editor/src/core/components/editors/editor-wrapper.tsx (1)

57-57: Verify the impact of removing hideDragHandleOnMouseLeave.

Ensure that the removal of hideDragHandleOnMouseLeave does not negatively impact user interactions with the editor. Verify that any necessary adjustments have been made to maintain intuitive functionality.

packages/editor/src/styles/drag-drop.css (2)

1-12: Good use of Flexbox for layout.

The .editor-side-menu class uses Flexbox for layout, which is a good choice for responsive design. The transition properties are well-defined for smooth visibility changes.


12-15: Effective use of .side-menu-hidden class for visibility control.

The .side-menu-hidden class effectively manages the visibility and interaction of the side menu by setting opacity to 0 and disabling pointer events.

packages/editor/src/core/components/editors/editor-container.tsx (2)

14-14: Simplified props destructuring.

The removal of hideDragHandle from the props simplifies the component interface, reducing complexity.


55-58: Direct DOM manipulation for hiding the side menu.

The handleContainerMouseLeave function effectively hides the side menu by adding the side-menu-hidden class. Ensure this approach aligns with your application's architecture, as direct DOM manipulation can sometimes bypass React's state management.

Verification successful

Direct DOM manipulation in handleContainerMouseLeave is used in a React component. The function is directly tied to the component's lifecycle via the onMouseLeave event. Ensure this approach aligns with your application's architecture, particularly if React's state management is heavily utilized elsewhere.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `handleContainerMouseLeave` to ensure consistency with React's state management.

# Test: Search for the function usage. Expect: Consistent usage across the codebase.
rg --type tsx -A 5 $'handleContainerMouseLeave'

Length of output: 74


Script:

#!/bin/bash
# Description: Search for the usage of `handleContainerMouseLeave` across the codebase without specifying the file type.

rg -A 5 'handleContainerMouseLeave'

Length of output: 1201

packages/editor/src/core/hooks/use-document-editor.ts (2)

6-6: Updated imports for new extension.

The import of SideMenuExtension replaces DragAndDrop, reflecting the shift to a side menu interface. This change enhances modularity and aligns with the new design.


96-99: Configurable SideMenuExtension.

The SideMenuExtension is configured with properties for AI and drag-and-drop functionality. This approach enhances flexibility and allows for easy feature toggling.

packages/editor/src/core/components/editors/document/page-renderer.tsx (2)

28-28: Destructuring change approved.

The removal of hideDragHandle from the props destructuring simplifies the component's interface.


133-133: Simplified conditional rendering approved.

The change to render BlockMenu only if editor.isEditable is true simplifies the logic.

packages/editor/src/core/extensions/side-menu.tsx (5)

32-50: SideMenuExtension function approved.

The SideMenuExtension function is well-structured, providing flexibility for AI and drag-drop configurations.


52-60: absoluteRect utility function approved.

The function effectively encapsulates the logic for retrieving element dimensions.


62-95: nodeDOMAtCoords utility function approved.

The function comprehensively covers various selectors to identify relevant nodes at specific coordinates.


97-198: SideMenu function approved.

The function is well-organized, with clear separation of concerns for menu visibility and handle interactions.


128-198: handleDOMEvents approved.

The event handlers are well-defined, effectively managing interactions for drag-and-drop and visibility.

packages/editor/src/core/plugins/drag-handle.ts (5)

13-33: createDragHandleElement function approved.

The function encapsulates the creation logic well, improving readability and maintainability.


Line range hint 35-73: nodeDOMAtCoords utility function approved.

The function is well-implemented, providing a reliable way to identify elements at specific coordinates.


Line range hint 108-320: DragHandlePlugin function approved.

The function comprehensively covers initialization, event handling, and cleanup for drag handle interactions.


Line range hint 110-162: handleDragStart function approved.

The function is well-structured, ensuring proper setup for drag-and-drop operations.


Line range hint 164-227: handleClick function approved.

The function is effectively implemented, allowing for accurate selection updates.

for (let i = 0; i < 6; i++) {
const spanElement = document.createElement("span");
spanElement.classList.add("drag-handle-dot");
spanElement.classList.value = dragHandleDotClassName;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably use a unicode symbol here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants