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

LinkControl: refined the display of the link preview title and url when both are same #61819

Merged
merged 16 commits into from
Jun 10, 2024

Conversation

amitraj2203
Copy link
Contributor

@amitraj2203 amitraj2203 commented May 21, 2024

What?

Fixes: #60900

Why?

When the link text contains the protocol, the preview displays both lines (text and link) and they contain the same information, the only difference is the displayed protocol. So instead of displaying it twice its better to show it only once.

How?

This PR adds a check that weather the URL and Text is same after removing the protocol from the text.

Testing Instructions

  1. Add a Paragraph that contains the text https://test.org.
  2. Select the text https://test.org and add a link to it test.org without the protocol part.
  3. Once the link is added, click the link in the Paragraph to open the link control preview.
  4. Observe the link preview displays only one line: test.org.

Screenshots or screencast

Screen.Recording.2024-05-21.at.5.53.40.PM.mov

@amitraj2203 amitraj2203 requested a review from getdave as a code owner May 21, 2024 12:25
Copy link

github-actions bot commented May 21, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: amitraj2203 <amitraj2203@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@afercia afercia added [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. [Package] Url /packages/url [Package] Block editor /packages/block-editor [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) labels May 29, 2024
@afercia afercia requested a review from tyxla May 29, 2024 12:28
Copy link
Contributor

@afercia afercia left a comment

Choose a reason for hiding this comment

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

Only one small question about the regex.

packages/url/src/filter-url-for-display.js Outdated Show resolved Hide resolved
packages/url/src/filter-url-for-display.js Outdated Show resolved Hide resolved
packages/url/src/filter-url-for-display.js Outdated Show resolved Hide resolved
packages/url/src/filter-url-for-display.js Outdated Show resolved Hide resolved
@amitraj2203 amitraj2203 requested a review from tyxla May 30, 2024 07:44
packages/url/src/filter-url-for-display.js Outdated Show resolved Hide resolved
packages/url/src/filter-url-for-display.js Outdated Show resolved Hide resolved
@amitraj2203
Copy link
Contributor Author

Hi @afercia @tyxla 👋
Based on the above discussion, please let me know what changes should be made with this PR from my side.

Thanks!

@tyxla
Copy link
Member

tyxla commented Jun 3, 2024

Hi @afercia @tyxla 👋 Based on the above discussion, please let me know what changes should be made with this PR from my side.

Thanks!

Thanks for your hard work @amitraj2203 🙌

Introducing new public API functions to another package could take more time as we want to make sure to design them well.

In the meantime, I don't think that's a necessity to fix this issue. So I suggested above, feel free to fix this inline in the component (by introducing a local, unexported helper function), and we can consider abstracting this to public API in another PR. That will help fix the issue at hand and not delay it further.

@amitraj2203
Copy link
Contributor Author

Thanks for having a look at it. I have made the changes and considered the regex which only removes the protocol and domain prefix (www.)

@amitraj2203 amitraj2203 requested a review from tyxla June 3, 2024 13:23
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Thanks for your hard work on it @amitraj2203 🙌

I think there's some last-minute cleanup to do before moving forward with this one.

@amitraj2203 amitraj2203 requested a review from tyxla June 4, 2024 12:04
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

I think this is really close, and left a last round of feedback.

Let me know what you think @amitraj2203 and thanks again for working on this one!

packages/url/src/test/index.js Outdated Show resolved Hide resolved
packages/url/src/test/index.js Outdated Show resolved Hide resolved
packages/url/src/test/index.js Outdated Show resolved Hide resolved
@amitraj2203 amitraj2203 requested a review from tyxla June 6, 2024 11:22
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

This looks great, thanks @amitraj2203 🙌

Just one last thing before we can ship this.

packages/url/src/filter-url-for-display.js Show resolved Hide resolved
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Thanks again @amitraj2203 🙌

I'll let @afercia ship this after confirming #60900 is resolved as expected.

@afercia
Copy link
Contributor

afercia commented Jun 10, 2024

@amitraj2203 @tyxla I loved seeing your collaboration and perseverance on this PR ❤️ Thanks both.

I can't speak for the code part and I'm totally confident in your expertise. Thanks for adding a few tests.
Quickly tested and it does solve the issue.

@afercia afercia merged commit bd6e764 into WordPress:trunk Jun 10, 2024
62 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.6 milestone Jun 10, 2024
patil-vipul pushed a commit to patil-vipul/gutenberg that referenced this pull request Jun 17, 2024
…en both are same (WordPress#61819)

* Add removeProtocol function to URL package

* Fix redundant link preview display when link text includes protocol in LinkControl.

* Changed regex for stripDomainPrefixes to handle all protocols

* Add unit tests for stripDomainPrefixes function

* Refactor URL filtering logic

* Change variable name

* Moved filterTitleForDisplay outside of component

* Adds test cases for the updated regex

* Fix typos and remove redundant tests for filterURLForDisplay

* Fix isUrlRedundant check in LinkPreview component

* Add test case for empty or falsy URL in filterURLForDisplay function

Co-authored-by: amitraj2203 <amitraj2203@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) Needs Design Feedback Needs general design feedback. [Package] Block editor /packages/block-editor [Package] Url /packages/url [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LinkControl: refine the display of the link preview title and url
3 participants