Migrate navigator.clipboard in link bubble menu to copyToClipboard

What does this MR do and why?

The link bubble menu copy button called navigator.clipboard.writeText directly, which fails in non-secure contexts. This follows the work in !211222 (merged), which blocks direct use of navigator.clipboard. The component now uses the shared helper copyToClipboard from ~/lib/utils/copy_to_clipboard and the matching eslint-disable comment is removed. The spec now mocks copyToClipboard instead of spying on navigator.clipboard.

Closes #579482.

References

Part of epic &19827.

Screenshots or screen recordings

Not applicable — no visual change.

How to set up and validate locally

  1. Run yarn jest spec/frontend/content_editor/components/bubble_menus/link_bubble_menu_spec.js.
  2. In GDK, open a project wiki page (or an issue description) and switch to the rich text editor.
  3. Add a link, for example [GitLab](https://gitlab.com), and select the link text to open the link bubble menu.
  4. Select Copy link URL and paste into another field. The full URL is pasted.
  5. Upload a file (for example a PDF) in the same editor, select its link, and select Copy link URL. The pasted value is the full absolute URL, not the relative /uploads/... path.
  6. Optional, non-secure context: open GDK over plain HTTP on an address other than localhost (for example http://<your-LAN-IP>:3000). There navigator.clipboard is undefined, so before this change the button threw a TypeError and nothing was copied. With this change, copyToClipboard falls back to document.execCommand('copy') and the URL is copied.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

This contribution was prepared with the help of an AI assistant. I reviewed the changes and take responsibility for them.

Edited by Anish Kumar

Merge request reports

Loading
Loading