Skip to content

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Jan 30, 2025

Description

This PR includes-

  1. Ability to add a link without the protocol. In case the protocol is absent, we prepend it manually,
  2. Better error handling for invalid links.

Type of Change

  • Improvement (change that would cause existing functionality to not work as expected)

Summary by CodeRabbit

  • New Features

    • Enhanced link selector with improved URL validation
    • Added error handling for invalid URL inputs
    • Implemented user feedback for link submission errors
  • Bug Fixes

    • Improved URL input handling by automatically prepending "http://" when needed

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

The pull request introduces modifications to the BubbleMenuLinkSelector component in the editor's link selector. The changes focus on improving URL validation and error handling. A new error state has been added to manage URL input validation, with enhanced logic to check and format URLs. The component now provides more robust feedback when users enter invalid links, including visual indicators and error messaging.

Changes

File Change Summary
packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx - Updated Trash icon import to Trash2
- Added error state for URL validation
- Renamed onLinkSubmit to handleLinkSubmit
- Enhanced URL validation logic
- Added error handling and conditional error message rendering

Possibly related PRs

Suggested labels

🐛bug

Suggested reviewers

  • Palanikannan1437
  • sriramveeraghanta

Poem

🔗 A link selector's tale, oh so bright
With errors caught and validation tight
From empty strings to URLs askew
Our rabbit coder makes the input true
A bubble menu that's sharp and clean
Ensuring links are just what they seem! 🐰✨


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.

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

🧹 Nitpick comments (2)
packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (2)

23-35: Enhance URL validation and protocol handling.

While the current implementation works, consider these improvements:

  1. Support for HTTPS protocol by default instead of HTTP
  2. Handle more URL formats (e.g., FTP, custom protocols)
  3. Provide more specific error messages based on validation failure reason

Consider this enhanced implementation:

 const handleLinkSubmit = useCallback(() => {
   const input = inputRef.current;
   if (!input) return;
   let url = input.value;
   if (!url) return;
-  if (!url.startsWith("http")) url = `http://${url}`;
+  // Support common protocols or default to HTTPS
+  const commonProtocols = ['http:', 'https:', 'ftp:', 'mailto:'];
+  const hasProtocol = commonProtocols.some(protocol => url.startsWith(protocol));
+  if (!hasProtocol) url = `https://${url}`;
+
   if (isValidHttpUrl(url)) {
     setLinkEditor(editor, url);
     setIsOpen(false);
     setError(false);
   } else {
     setError(true);
+    // Set more specific error message based on validation failure
+    const errorMessage = url.includes('://') 
+      ? 'Invalid URL format'
+      : 'Please enter a valid URL';
+    setErrorMessage(errorMessage);
   }
 }, [editor, inputRef, setIsOpen]);

58-109: Enhance accessibility for the link selector.

While the UI implementation looks good, consider these accessibility improvements:

  1. Add ARIA labels for error messages
  2. Include role attributes for interactive elements
  3. Add keyboard navigation between buttons

Apply these accessibility enhancements:

 <div
   className={cn("flex rounded border border-custom-border-300 transition-colors", {
     "border-red-500": error,
   })}
+  role="group"
+  aria-label="Link editor"
 >
   <input
     ref={inputRef}
     type="url"
     placeholder="Enter or paste a link"
     onClick={(e) => e.stopPropagation()}
     className="flex-1 border-r border-custom-border-300 bg-custom-background-100 py-2 px-1.5 text-xs outline-none placeholder:text-custom-text-400 rounded"
     defaultValue={editor.getAttributes("link").href || ""}
+    aria-invalid={error}
+    aria-describedby={error ? "link-error-message" : undefined}
     onKeyDown={(e) => {
       setError(false);
       if (e.key === "Enter") {
         e.preventDefault();
         handleLinkSubmit();
+      } else if (e.key === "Tab") {
+        // Prevent focus trap
+        e.stopPropagation();
       }
     }}
     onFocus={() => setError(false)}
     autoFocus
   />
   {/* ... buttons ... */}
 </div>
 {error && (
   <p 
     className="text-xs text-red-500 my-1 px-2 pointer-events-none animate-in fade-in slide-in-from-top-0"
+    id="link-error-message"
+    role="alert"
   >
     Please enter a valid URL
   </p>
 )}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9268180 and feb9a4e.

📒 Files selected for processing (1)
  • packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (2)

2-2: LGTM! Icon import updated consistently.

The Trash2 icon import aligns with its usage in the component.


19-19: LGTM! Error state added for validation feedback.

The error state addition improves user feedback for invalid URLs.

@sriramveeraghanta sriramveeraghanta merged commit 6a37a2c into preview Jan 30, 2025
10 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix/editor-link branch January 30, 2025 14:55
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.

4 participants