Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add VLink component for external links #871

Closed
wants to merge 5 commits into from
Closed

Add VLink component for external links #871

wants to merge 5 commits into from

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Feb 15, 2022

Fixes

Fixes #468 by @obulat

Description

This PR adds a simple VLink component that is a wrapper over an a anchor with the target="_blank" rel="noopener noreferrer" added to it, and replaces all external a links in the components with VLink.

This ensures that the links can be opened from the iframe, and reduces the cognitive load of having to remember to add the link properties every time.

An interesting thing I learned: target="_blank" is not the same as target="blank", with the latter opening all the links in a single new tab, and the former opening each new link in a new tab. I think we want the former behavior, but this is open for a discussion.
Also, in the modern browsers, rel="noopenver" is automatically added to all the links with target="_blank", but it's nice to have it for older browsers.

I did not initially replace the DownloadButton's <a>. Trying out the DownloadButton on the production site, wordpress.org/openverse, with a sound from Freesound, I got a similar error screen as in the linked issue, so I used the VLink component for DownloadButton as well. But then I realized that the problem is caused by me not being signed in to Freesound, Jamendo audios can be downloaded from the deployed site. But I reverted the change anyway because the tests fail. If we decide to change it, we can do it in a new PR.

Unrelated bug-fix: removes the bug-report state that was removed in a recent PR from the feedback page.

Testing Instructions

Running the app, you should see all the external links working properly and opening in a new tab.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat added 🟧 priority: high Stalls work on the project or its dependents 💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users labels Feb 15, 2022
@obulat obulat requested a review from a team as a code owner February 15, 2022 14:19
@obulat obulat self-assigned this Feb 15, 2022
@obulat obulat requested review from zackkrida and stacimc February 15, 2022 14:19
@obulat obulat added the 🟥 priority: critical Must be addressed ASAP label Feb 15, 2022
@obulat obulat removed the 🟧 priority: high Stalls work on the project or its dependents label Feb 15, 2022
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

Looks awesome! Love this kind of thing 🎉

Left a couple of non-blocking suggestions of things we can fix up if you want.

Additionally: in VButton we log a warning for a's that are missing href attribute. It'd be nice to transport that assurance to this component as well, just to catch accidental places where we bind it to a value and it turns up undefined, null, or as an empty string or something.

It might also be nice to throw a warning if we catch a non-external link being passed as those should all use NuxtLink anyway, right?

Finally: some simple unit tests would be nice as well 🙂

None of that are blockers though 👍

@@ -9,9 +9,9 @@

<i18n path="meta-search-page.intro" tag="p" class="mb-4">
<template #link>
<a aria-label="sources" href="/sources">{{
<NuxtLink aria-label="sources" :to="localePath('/sources')">{{
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're already here, can we go ahead and translate the sources string in the aria-label if you don't mind?

src/pages/meta-search.vue Outdated Show resolved Hide resolved
Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

Nice, looking at this we save several lines using a component. I wonder if it would be a good idea to make it more general and let it use an anchor or NuxtLink when it's an internal or external link, as it is already done elsewhere, but I don't remember exactly where.

If not, don't you think we should rename it to ExternalLink or something like that?

@sarayourfriend
Copy link
Contributor

@krysal do you think we should have it auto-detect when a relative path vs external path is passed in? It could automatically call to localePath and stuff like we're doing on all the NuxtLinks anyway without having to write that everywhere as well.

@obulat
Copy link
Contributor Author

obulat commented Feb 16, 2022

Thank you for your great suggestions, @sarayourfriend and @krysal ! I decided to open a new PR #879 for a larger VLink component for both external and internal links, as Krystle suggested.
I've moved the warning about missing href attribute from VButton to VLink, and added some unit tests (and shamelessly copied some from VButton)

It might also be nice to throw a warning if we catch a non-external link being passed as those should all use NuxtLink anyway, right?
No need for a warning in a component that wraps both :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟥 priority: critical Must be addressed ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

External links NOT opening in the Openverse iframe
4 participants