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

Add hyperlink creation feature #332

Merged
merged 6 commits into from
Sep 5, 2024

Conversation

choidabom
Copy link
Member

@choidabom choidabom commented Sep 3, 2024

What this PR does / why we need it?

This PR introduces a feature that enhances text selection by enabling the automatic creation of hyperlinks when dragging and selecting text prior to pasting a link. Currently, users experience the inconvenience of having URLs pasted directly into the text instead of being applied as hyperlinks to the selected text.

With this enhancement, the system will automatically detect if the copied content is a link and generate a Markdown link format that connects the selected text with the URL, thus improving the overall user experience.

Any background context you want to provide?

Streamlining the hyperlink creation process will not only save time for users but also ensure that linking text is more intuitive. This is particularly useful for users who frequently need to reference external sources, as they can now create clickable links with a simple drag-and-select action, enhancing productivity and usability.

What are the relevant tickets?

Fixes #322

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Introduced a new toolbar management system for improved formatting options in the editor.
    • Added functionality for seamless hyperlink insertion from the clipboard, enhancing user experience.
  • Bug Fixes

    • Streamlined the toolbar's visibility and selected formats, improving responsiveness to user interactions.
  • Chores

    • Removed unused imports to enhance code clarity and maintainability.
    • Updated dependencies for enhanced type support and validation functionalities.

@choidabom choidabom requested a review from devleejb September 3, 2024 13:13
@choidabom choidabom self-assigned this Sep 3, 2024
Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes involve the introduction of a new useToolBar hook for managing the state of a formatting toolbar in a text editor, refactoring the Editor component to utilize this hook. Additionally, a new utility for hyperlink insertion has been created, allowing users to easily link selected text to URLs. These modifications enhance the overall functionality and structure of the codebase.

Changes

Files Change Summary
frontend/src/components/editor/Editor.tsx Refactored to use useToolBar for toolbar state management; removed unused imports.
frontend/src/hooks/useToolBar.ts Introduced a new hook for managing toolbar visibility and selected formats.
frontend/src/hooks/useFormatUtils.ts Added checkAndAddFormat function to conditionally modify format sets based on text selection.
frontend/src/utils/urlHyperlinkInserter.ts Added functionality for inserting hyperlinks into the editor based on pasted URLs.
frontend/package.json Added dependencies for validator and @types/validator to support hyperlink functionality.

Assessment against linked issues

Objective Addressed Explanation
Add hyperlink creation feature (#322)

🐰 Hopping through the code so bright,
A toolbar that dances, oh what a sight!
Links now can flourish with just a quick paste,
Formatting made easy, no time to waste!
In the editor's garden, we play and we cheer,
With each little change, the magic draws near! 🌟


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

@choidabom choidabom changed the title Enhance text selection with automatic hyperlink creation for pasted links Add hyperlink creation feature Sep 3, 2024
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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3682417 and a3e2f94.

Files selected for processing (3)
  • frontend/src/components/editor/Editor.tsx (3 hunks)
  • frontend/src/hooks/useToolBar.ts (1 hunks)
  • frontend/src/utils/urlHyperlinkInserter.ts (1 hunks)
Additional comments not posted (9)
frontend/src/utils/urlHyperlinkInserter.ts (1)

4-8: LGTM!

The code changes are approved.

frontend/src/hooks/useToolBar.ts (3)

1-4: LGTM!

The code segment is approved.


5-68: LGTM!

The code segment is approved.


6-10: LGTM!

The code segment is approved.

frontend/src/components/editor/Editor.tsx (5)

3-3: LGTM!

The import changes align with the refactoring of the toolbar state management and the addition of the hyperlink insertion utility.

Also applies to: 11-12, 18-18


86-86: LGTM!

The EditorView instantiation with the configured state and element as the parent looks good.


Line range hint 94-106: LGTM!

The updated useEffect dependencies ensure that the hook re-runs when any of the relevant dependencies change, keeping the component in sync with the latest state and props.


31-32: Verify the usage of the new hooks.

The changes improve the component's structure by leveraging hooks for managing the toolbar state and format utilities, reducing complexity within the component.

Run the following script to verify the usage of the new hooks:

Verification successful

Hooks are correctly utilized in the component.

The useFormatUtils and useToolBar hooks are effectively used to manage formatting actions and toolbar state, respectively. The implementation aligns with their intended purposes, enhancing the component's structure and functionality.

  • applyFormat and setKeymapConfig are used for formatting actions.
  • toolBarState, setToolBarState, and updateFormatBar are used for toolbar state management.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new `useFormatUtils` and `useToolBar` hooks.

# Test 1: Search for the usage of `applyFormat` and `setKeymapConfig` from `useFormatUtils`. Expect: Usage in the component.
rg --type typescript -A 5 $'applyFormat|setKeymapConfig'

# Test 2: Search for the usage of `toolBarState`, `setToolBarState`, and `updateFormatBar` from `useToolBar`. Expect: Usage in the component.
rg --type typescript -A 5 $'toolBarState|setToolBarState|updateFormatBar'

Length of output: 202


Script:

#!/bin/bash
# Description: Verify the usage of the new `useFormatUtils` and `useToolBar` hooks.

# Find all .ts and .tsx files and search for the usage of the hooks within them.

# Test 1: Search for the usage of `applyFormat` and `setKeymapConfig` from `useFormatUtils`.
fd --extension ts --extension tsx --exec rg 'applyFormat|setKeymapConfig' {}

# Test 2: Search for the usage of `toolBarState`, `setToolBarState`, and `updateFormatBar` from `useToolBar`.
fd --extension ts --extension tsx --exec rg 'toolBarState|setToolBarState|updateFormatBar' {}

Length of output: 1315


70-83: Verify the functionality of the new extensions.

The changes enhance the editor's functionality by adding support for intelligence pivot, hyperlink insertion, and conditional image uploading based on settings.

Run the following script to verify the functionality of the new extensions:

Verification successful

Extensions Verified Successfully

The intelligencePivot, urlHyperlinkInserter, and imageUploader extensions are correctly implemented and integrated into the editor component. The conditional logic for including imageUploader based on settings is also correctly applied. These changes enhance the editor's functionality as intended.

  • intelligencePivot is implemented in frontend/src/utils/intelligence/intelligencePivot.ts.
  • urlHyperlinkInserter is implemented in frontend/src/utils/urlHyperlinkInserter.ts.
  • imageUploader is implemented in frontend/src/utils/imageUploader.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the functionality of the new `intelligencePivot`, `urlHyperlinkInserter`, and `imageUploader` extensions.

# Test 1: Search for the implementation of the `intelligencePivot` extension. Expect: Implementation details.
rg --type typescript -A 10 $'intelligencePivot'

# Test 2: Search for the implementation of the `urlHyperlinkInserter` extension. Expect: Implementation details.
rg --type typescript -A 10 $'urlHyperlinkInserter'

# Test 3: Search for the implementation of the `imageUploader` extension. Expect: Implementation details and conditional usage based on `settingStore.fileUpload.enable`.
rg --type typescript -A 10 $'imageUploader'

Length of output: 244


Script:

#!/bin/bash
# Description: Verify the functionality of the new `intelligencePivot`, `urlHyperlinkInserter`, and `imageUploader` extensions.

# Test 1: Search for the implementation of the `intelligencePivot` extension. Expect: Implementation details.
rg --type ts -A 10 $'intelligencePivot'

# Test 2: Search for the implementation of the `urlHyperlinkInserter` extension. Expect: Implementation details.
rg --type ts -A 10 $'urlHyperlinkInserter'

# Test 3: Search for the implementation of the `imageUploader` extension. Expect: Implementation details and conditional usage based on `settingStore.fileUpload.enable`.
rg --type ts -A 10 $'imageUploader'

Length of output: 7036

frontend/src/utils/urlHyperlinkInserter.ts Outdated Show resolved Hide resolved
frontend/src/utils/urlHyperlinkInserter.ts Show resolved Hide resolved
frontend/src/hooks/useToolBar.ts Outdated Show resolved Hide resolved
frontend/src/hooks/useToolBar.ts Outdated Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3e2f94 and c2db04e.

Files selected for processing (3)
  • frontend/src/hooks/useFormatUtils.ts (1 hunks)
  • frontend/src/hooks/useToolBar.ts (1 hunks)
  • frontend/src/utils/urlHyperlinkInserter.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • frontend/src/hooks/useToolBar.ts
  • frontend/src/utils/urlHyperlinkInserter.ts
Additional comments not posted (1)
frontend/src/hooks/useFormatUtils.ts (1)

146-159: LGTM!

The code changes are approved.

@choidabom choidabom force-pushed the add-hyperlink-creation branch from c2db04e to 4d3b2e4 Compare September 5, 2024 03:17
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c2db04e and 4d3b2e4.

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (5)
  • frontend/package.json (1 hunks)
  • frontend/src/components/editor/Editor.tsx (3 hunks)
  • frontend/src/hooks/useFormatUtils.ts (1 hunks)
  • frontend/src/hooks/useToolBar.ts (1 hunks)
  • frontend/src/utils/urlHyperlinkInserter.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • frontend/package.json
Files skipped from review as they are similar to previous changes (2)
  • frontend/src/hooks/useFormatUtils.ts
  • frontend/src/utils/urlHyperlinkInserter.ts
Additional comments not posted (6)
frontend/src/hooks/useToolBar.ts (3)

1-3: Setup and imports are appropriate.

The initial setup and imports are correctly aligned with the functionality of the useToolBar hook.


6-10: State setup is well-defined.

The useState setup for toolBarState is clear and supports the toolbar's functionality effectively.


59-60: Return statement is appropriate.

The hook correctly exposes toolBarState, setToolBarState, and updateFormatBar, allowing for effective external control and integration.

frontend/src/components/editor/Editor.tsx (3)

3-18: Approved import changes.

The import changes reflect the refactoring and introduction of new functionalities, aligning with the PR's objectives to enhance hyperlink functionality.


70-82: Verify hyperlink functionality integration.

The integration of urlHyperlinkInserter at line 82 is crucial for the new hyperlink feature. Ensure this utility is correctly implemented and interacts seamlessly with the editor's state and other utilities.

Verification successful

Hyperlink functionality integration verified.

The urlHyperlinkInserter utility is correctly implemented and integrated into the editor. It handles paste events to detect valid URLs, enhancing the editor's functionality by potentially hyperlinking URLs. The integration appears seamless with the editor's state and other utilities. No issues were found with its implementation or integration.

  • File: frontend/src/utils/urlHyperlinkInserter.ts
  • Usage: frontend/src/components/editor/Editor.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `urlHyperlinkInserter` utility.

# Test: Search for the utility usage and implementation details.
rg --type typescript -A 5 $'urlHyperlinkInserter'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify the implementation of `urlHyperlinkInserter` utility.

# Test: Search for the utility usage and implementation details with corrected file type.
rg --type ts -A 5 $'urlHyperlinkInserter'

Length of output: 1365


86-86: Check cleanup logic and dependencies.

The cleanup logic in the return function of useEffect at line 86 ensures the editor view is properly destroyed. Verify that all dependencies in the useEffect hook are necessary and correctly trigger updates without causing excessive re-renders.

Also applies to: 94-100

Verification successful

Review of useEffect Dependencies and Cleanup Logic in Editor.tsx

The useEffect hook in Editor.tsx is correctly implemented with a cleanup function that destroys the EditorView instance. The dependencies listed in the hook appear necessary for ensuring that the editor updates correctly when any of these values change. The dependencies include:

  • element
  • editorStore.client
  • editorStore.doc
  • themeMode
  • workspaceStore.data
  • settingStore.fileUpload?.enable
  • dispatch
  • createUploadUrl
  • uploadFile
  • applyFormat
  • updateFormatBar
  • setKeymapConfig

Each of these dependencies is relevant to the setup and functioning of the editor, and changes to any of them would necessitate a re-render to maintain the correct state and behavior of the editor. The cleanup logic is also correctly implemented to prevent memory leaks by destroying the EditorView when the component unmounts or dependencies change.

  • No excessive re-renders: The dependencies are necessary and should not cause excessive re-renders as they are tied to significant changes in the editor's state or configuration.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the necessity of all dependencies in the `useEffect` hook.

# Test: Check for potential excessive re-renders due to dependencies.
rg --type typescript -A 5 $'useEffect'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the necessity of all dependencies in the `useEffect` hook.

# Test: Check for potential excessive re-renders due to dependencies.
rg --type ts -A 5 $'useEffect'

Length of output: 20217


Script:

#!/bin/bash
# Extract the complete implementation of the useEffect hook from Editor.tsx to analyze dependencies and cleanup logic.
ast-grep --lang tsx --pattern $'useEffect(() => {
  $$$
}, [$$$]);' frontend/src/components/editor/Editor.tsx

Length of output: 4787

frontend/src/hooks/useToolBar.ts Show resolved Hide resolved
frontend/src/components/editor/Editor.tsx Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4d3b2e4 and fbd9236.

Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (1)
  • frontend/package.json (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/package.json

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

@devleejb devleejb merged commit ba3d54d into yorkie-team:main Sep 5, 2024
2 checks passed
minai621 pushed a commit that referenced this pull request Nov 5, 2024
* Add useToolBar hook

* Add hyperlink creation feature

* Add text selection check before inserting hyperlink

* Refactor `useToolBar` & extract `checkAndAddFormat` functon to a separate utility file

* Change valid URL check regular expression to `validator` library

* Fix missing validator package installation
@coderabbitai coderabbitai bot mentioned this pull request Nov 14, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Add hyperlink creation feature
2 participants