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(alpha-editor): update tooltip layout and organize modifiers #1196

Merged
merged 2 commits into from
Oct 31, 2024
Merged

feat(alpha-editor): update tooltip layout and organize modifiers #1196

merged 2 commits into from
Oct 31, 2024

Conversation

dineshsutihar
Copy link
Contributor

✨ Codu Pull Request πŸ’»

Fixes #1195

Pull Request details

  • Move block-level modifiers (Heading, Subheading, Text, Quote) to the left in a dropdown
  • Add a dividing line in the center of the tooltip
  • Position inline-level modifiers (Bold, Italic, Hyperlink) on the right

Any Breaking changes

None

Associated Screenshots

Tooltip With Active State
Tooltip With Dropdown

[Optional] What gif best describes this PR or how it makes you feel

None

Copy link

vercel bot commented Oct 30, 2024

@dineshsutihar is attempting to deploy a commit to the CodΓΊ Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes in this pull request involve modifications to three components: EditorBubbleMenu, LinkSelector, and NodeSelector. The EditorBubbleMenu has had the "code" option removed and improved error handling for editor commands. The LinkSelector now uses a single Link icon instead of multiple icons and has disabled URL input functionality. The NodeSelector has streamlined its options by removing several items and refining the active state logic. These updates enhance the overall functionality and user experience of the editor components.

Changes

File Path Change Summary
components/editor/editor/components/bubble-menu.tsx Removed "code" option, improved error handling with optional chaining and nullish coalescing, updated rendering logic for selectors.
components/editor/editor/components/link-selector.tsx Replaced multiple icons with a single Link icon, commented out URL input form, retained core link management functionality.
components/editor/editor/components/node-selector.tsx Removed "Code", "Bullet List", and "Numbered List" options, simplified "Text" active check, adjusted "Quote" command, added aria-expanded for accessibility.

Assessment against linked issues

Objective Addressed Explanation
Modify tooltip on alpha editor (Issue #1195) ❌ The changes do not address tooltip modifications as specified.

Possibly related PRs

Suggested labels

hacktoberfest-accepted, hacktoberfest

Poem

πŸ‡ In the editor's realm, changes take flight,
With icons simplified, everything feels right.
No more "code" to clutter the view,
Just bold and italic, for the writer in you.
So hop along, let creativity flow,
In this bubble of joy, let your ideas grow! 🌟


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

@John-Paul-Larkin
Copy link
Member

Hi @dineshsutihar
This looks good. Thanks.
However, the link feature is giving me an error. Can you confirm you get this error?
We can make a separate issue to fix this.

Screen.Recording.2024-10-30.at.16.16.16.mov

@dineshsutihar
Copy link
Contributor Author

Hi @dineshsutihar This looks good. Thanks. However, the link feature is giving me an error. Can you confirm you get this error? We can make a separate issue to fix this.

Screen.Recording.2024-10-30.at.16.16.16.mov

Yes, there’s a pre-existing issue with the link feature, and I was planning to create a new issue to address it separately. Additionally, I think a new UI for the link feature would be beneficial. Whenever we click on the link button, it could open a pop-up like this and prompt for a link. What do you think of this design? @John-Paul-Larkin

sample image for link

Could you please create a new issue and assign it to me? I’ll submit a separate PR to fix it.

@dineshsutihar dineshsutihar marked this pull request as ready for review October 30, 2024 16:45
@dineshsutihar dineshsutihar requested a review from a team as a code owner October 30, 2024 16:45
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 and nitpick comments (7)
components/editor/editor/components/node-selector.tsx (1)

68-68: Enhance dropdown accessibility

Good addition of aria-expanded! Consider adding complementary ARIA attributes to make the dropdown menu more accessible.

Apply these additional attributes to the dropdown section:

-        <section className="animate-in fade-in slide-in-from-top-1 fixed top-full z-[99999] mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl">
+        <section 
+          role="menu"
+          aria-orientation="vertical"
+          className="animate-in fade-in slide-in-from-top-1 fixed top-full z-[99999] mt-1 flex w-48 flex-col overflow-hidden rounded border border-stone-200 bg-white p-1 shadow-xl">

And to each menu item button:

-              className="flex items-center justify-between rounded-sm px-2 py-1 text-sm text-stone-600 hover:bg-stone-100"
+              role="menuitem"
+              className="flex items-center justify-between rounded-sm px-2 py-1 text-sm text-stone-600 hover:bg-stone-100"
components/editor/editor/components/link-selector.tsx (4)

3-3: Cleanup unused imports

The import statement for Link is correct, but the removed imports for Check and Trash should be cleaned up from the imports at the top of the file as well.

import { cn, getUrlFromString } from "@/utils/utils";
import type { Editor } from "@tiptap/core";
import { Link } from "lucide-react";
-import { Check, Trash } from "lucide-react";
import type { Dispatch, FC, SetStateAction } from "react";

63-67: Consider accessibility improvements for the link button

While the UI has been simplified to just an icon, this might impact accessibility. Consider adding an aria-label to the button.

        <Link
          className={cn("h-4 w-4", {
            "text-blue-500": editor.isActive("link"),
          })}
+         aria-label="Insert or remove link"
        />

Line range hint 26-58: Review the prompt-based link handling

The current implementation using window.prompt is not ideal for several reasons:

  1. Poor user experience compared to modern UI components
  2. Limited styling and validation capabilities
  3. No preview or editing features

This should be replaced with a proper UI component as discussed in the PR comments.

Consider implementing a reusable modal component that:

  • Provides proper URL validation
  • Supports link preview
  • Handles protocol addition more elegantly
  • Offers better error handling and user feedback

Would you like me to help create a new issue to track this enhancement?


Critical: Link input UI has been replaced with a basic browser prompt

The verification confirms that:

  1. The commented-out form UI has been replaced with a basic window.prompt() implementation in the setLink function
  2. No other components in the codebase handle the link input UI functionality
  3. This is the only implementation of the link editor functionality, as evidenced by the search results

While the link functionality still works, it has been downgraded from a rich UI form to a basic browser prompt. This change:

  • Removes the ability to visually validate URLs
  • Eliminates the user-friendly delete button for removing links
  • Reduces accessibility and user experience

Recommendation:

  1. Either revert the commenting out of the form UI until the new implementation is ready
  2. Or add a TODO comment explaining this is temporary, with a reference to the planned improvement ticket
πŸ”— Analysis chain

Line range hint 69-108: Critical: Link input UI has been disabled without replacement

The commented-out form represents the UI for link input/editing, but it's currently disabled without a replacement implementation. This creates a suboptimal user experience where users can only input URLs through a basic browser prompt. This aligns with the issue mentioned in the PR comments about the link feature needing improvement.

Based on the PR comments, there's a plan to implement a new pop-up UI for link input. Until the new UI is implemented, consider:

  1. Either keeping the current form implementation active
  2. Or adding a TODO comment explaining the temporary state and linking to the follow-up issue

Let's check if there are any other components that might be handling the link input UI:


Let's also check for any editor-related components that might handle links:

And let's verify if there are any other UI components using the editor's link functionality:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential link-related UI components
rg -l "link.*input|url.*input" --type tsx

Length of output: 71


Script:

#!/bin/bash
# Search for potential link-related UI components with ripgrep
# Using broader search patterns and without file type restriction
rg -l "setLink|unsetLink|link.*input|url.*input"

# Also search for potential link-related components by filename
fd "link" --extension tsx --extension ts --extension jsx --extension js

Length of output: 340


Script:

#!/bin/bash
# Search for editor commands related to links
rg "editor.*link" -A 5 -B 5

Length of output: 4693


Script:

#!/bin/bash
# Search for usage of editor's link attributes or commands
rg "getAttributes.*link|setLink|unsetLink" -A 5 -B 5

Length of output: 6212

components/editor/editor/components/bubble-menu.tsx (2)

75-84: Consider simplifying the setIsOpen callback

While the implementation is correct, the callback could be more concise.

Consider this simplified version:

-setIsOpen={() => {
-  setIsNodeSelectorOpen(!isNodeSelectorOpen);
-  setIsLinkSelectorOpen(false);
-}}
+setIsOpen={(open) => {
+  setIsNodeSelectorOpen(open);
+  setIsLinkSelectorOpen(false);
+}}

This version:

  • Uses the state parameter provided by the setter
  • Avoids reading the current state unnecessarily
  • Maintains the same functionality

Line range hint 75-108: Architecture aligns with tooltip reorganization objectives

The separation of NodeSelector and LinkSelector components with their conditional rendering and independent state management provides a good foundation for the tooltip layout reorganization. This structure will support:

  • Block-level modifiers on the left (via NodeSelector)
  • Inline-level modifiers on the right (including LinkSelector)
  • Clear separation between modifier types

Consider documenting these architectural decisions in the component's comments to help maintain the design vision during future modifications.

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 2cb44b3 and 8f3c7a6.

πŸ“’ Files selected for processing (3)
  • components/editor/editor/components/bubble-menu.tsx (3 hunks)
  • components/editor/editor/components/link-selector.tsx (2 hunks)
  • components/editor/editor/components/node-selector.tsx (2 hunks)
πŸ”‡ Additional comments (4)
components/editor/editor/components/node-selector.tsx (2)

37-43: Implementation of Text modifier looks good!

The Text item implementation correctly follows tiptap's patterns and aligns with the PR objectives of organizing block-level modifiers.

Let's verify the Text command implementation across the codebase:

βœ… Verification successful

Text modifier implementation is consistent with existing usage

The implementation is verified to be correct and consistent with other usages in the codebase:

  • The toggleNode("paragraph", "paragraph") command is used consistently in both the node selector and slash command implementations
  • TextIcon is properly scoped to the node selector component
  • The implementation follows the same pattern as other block-level modifiers in the editor
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if there are any other Text command implementations that might conflict
# Expected: No other implementations of paragraph toggle command

ast-grep --pattern 'toggleNode("paragraph", "paragraph")'

Length of output: 59


Script:

#!/bin/bash
# Let's try a broader search for paragraph-related commands and Text implementations
# Search for any paragraph node usage in the codebase

# Search for paragraph-related commands
rg -l "paragraph" --type ts --type tsx

# Search for Text-related components and commands
rg -l "TextIcon" --type ts --type tsx

# Search for toggleNode usage
rg "toggleNode" --type ts --type tsx -A 2

Length of output: 202


Script:

#!/bin/bash
# Let's try without specifying file types since tsx is not recognized
# Search for paragraph-related commands and Text implementations

# Search for paragraph node usage
rg "paragraph" -A 2

# Search for TextIcon usage
rg "TextIcon"

# Search for toggleNode usage
rg "toggleNode" -A 2

Length of output: 5785


Line range hint 1-99: Verify alignment with PR objectives

The current implementation includes block-level modifiers but appears to be missing:

  1. The visual separator mentioned in the PR objectives
  2. The inline-level modifiers (Bold, Italic, Hyperlink) that should be positioned on the right

Let's check if these are implemented in other components:

components/editor/editor/components/bubble-menu.tsx (2)

27-28: LGTM: Improved error handling for editor commands

The addition of null-safe checks using optional chaining and nullish coalescing operators enhances the robustness of the editor commands.

Also applies to: 33-34


100-108: Verify link feature implementation

Based on the PR comments, there are known issues with the link feature that will be addressed in a separate PR. Ensure this implementation will be compatible with the planned changes to the link UI (pop-up for link input).

Let's check for any existing link-related components or implementations:

βœ… Verification successful

Link feature implementation is compatible with future changes

The current implementation in link-selector.tsx is well-structured for future updates:

  • It has a commented-out form UI that can be easily enabled for the planned pop-up link input
  • The core link functionality (setting/unsetting links, URL validation) is already implemented
  • The component accepts isOpen and setIsOpen props needed for the pop-up behavior
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for link-related components and implementations
echo "Searching for link-related files and implementations..."
fd -e tsx -e ts link
rg -i "link.*selector|link.*popup" -t typescript -t tsx

Length of output: 400


Script:

#!/bin/bash
# Let's examine the link-selector implementation and its dependencies
echo "=== Link Selector Implementation ==="
cat components/editor/editor/components/link-selector.tsx

echo -e "\n=== Checking for Link-related UI Components ==="
cat components/ui-components/link.tsx

echo -e "\n=== Checking Custom Link Node Implementation ==="
cat markdoc/nodes/customLink.markdoc.ts

echo -e "\n=== Searching for Link-related Props and Types ==="
rg -A 5 "interface.*Link|type.*Link" --type-add "ts:*.{ts,tsx}"

Length of output: 9532

Copy link
Contributor

@NiallJoeMaher NiallJoeMaher left a comment

Choose a reason for hiding this comment

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

Great work!

@NiallJoeMaher NiallJoeMaher merged commit 69625c1 into codu-code:develop Oct 31, 2024
4 of 5 checks passed
@dineshsutihar dineshsutihar deleted the fix-1195 branch November 14, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify tooltip on alpha editor
3 participants