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

Copy to clipboard functionality for concept page #1590

Merged
merged 12 commits into from
Feb 1, 2024

Conversation

osma
Copy link
Member

@osma osma commented Jan 31, 2024

Reasons for creating this PR

Implement copy to clipboard functionality, which is one of the required features for the concept page (#1484).

Link to relevant issue(s), if any

Description of the changes in this PR

  • add a vanilla JS function copyToClipboard
  • use the copyToClipboard method for the prefLabel and URI on the concept page
  • add translations (fi, sv, en) for the "Copy to clipboard" alt text used for the copy buttons
  • remove the copy to clipboard icons from the search results page (this was probably a misunderstanding during layout design)
  • add Cypress tests for copy to clipboard functionality

Known problems or uncertainties in this PR

  • the Cypress tests that access the clipboard may fail when run interactively (npx cypress open) if the Cypress window isn't focused (for example when working in an IDE) due to browser security policy; they always work when run headless (npx cypress run) and under CI

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@osma osma self-assigned this Jan 31, 2024
@osma osma added this to the 3.0 milestone Jan 31, 2024
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (83fd8a1) 70.54% compared to head (f5ee24c) 70.54%.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #1590   +/-   ##
=========================================
  Coverage     70.54%   70.54%           
  Complexity     1644     1644           
=========================================
  Files            32       32           
  Lines          4315     4315           
=========================================
  Hits           3044     3044           
  Misses         1271     1271           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@osma osma force-pushed the issue1484-concept-page-copy-to-clipboard branch from 8f56ee5 to c93eaec Compare January 31, 2024 14:49
@osma
Copy link
Member Author

osma commented Jan 31, 2024

Rebased on current main since PR #1585 was merged.

@osma osma marked this pull request as ready for review January 31, 2024 15:24
@osma
Copy link
Member Author

osma commented Feb 1, 2024

TODO:

  • fix: buttons don't work after partial page load
  • clicking on prefLabel or URI should select it
  • copy button next to a long prefLabel should stay on the same line if possible

@osma osma force-pushed the issue1484-concept-page-copy-to-clipboard branch from 972b16a to 44e1a93 Compare February 1, 2024 12:42
@osma
Copy link
Member Author

osma commented Feb 1, 2024

SonarCloud complains about duplicated code in Cypress tests. Well, duh, tests are repetitive...

// register the copyToClipboard function as event an handler for the copy buttons
registerCopyToClipboardEvents()

// re-register the event handlers after partial page loads
Copy link
Contributor

Choose a reason for hiding this comment

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

This line fills me with dread. We should make sure all event handlers are re-registered collectively. Partial page loading as a specific test case hasn't been used as of yet. Should we have an issue about it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that this is a more general issue, but currently we don't have that many event handlers and AFAICT only the concept-mappings component needs to re-register its event handler after a partial page load, and it already does that.

// check that the clipboard now contains "music research"
// NOTE: This test may fail when running Cypress interactively in a browser.
// The reason is browser security policies for accessing the clipboard.
// If that happens, make sure the browser window has focus and re-run the test.
Copy link
Contributor

Choose a reason for hiding this comment

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

The things you learn..! -__-

Copy link
Member Author

Choose a reason for hiding this comment

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

😁 Ideally the test would just be skipped when this happens. Not sure if that's easy to implement.

@joelit
Copy link
Contributor

joelit commented Feb 1, 2024

I would really want to see a hightlight for the copy button when used by keyboard.

Test case:

  • Go to http://localhost/Skosmos/yso/fi/page/p23406
  • Select "Uudet ja poistetut" form the side bar for ease switchng through interavtive elements
  • Use tab to switch through active elements
  • After the breadcrumb, (and if using shift+tab, before the broader concept link) the point where the preferred label with copy-to-clipboard button is active, there is no visual hint like visible border to indicate this
  • When you press enter while the copy-button is actice, the relevant element is highlighted and the copy works as expected

Copy link
Contributor

@joelit joelit left a comment

Choose a reason for hiding this comment

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

Keyboard navigation needs a highlight hint, otherwise it looks good

@osma osma requested a review from joelit February 1, 2024 13:58
Copy link

sonarqubecloud bot commented Feb 1, 2024

Quality Gate Failed Quality Gate failed

Failed conditions

28.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link
Contributor

@joelit joelit left a comment

Choose a reason for hiding this comment

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

Tested, and it works for me - we can ask for a graphic designer's opinion later.

@osma osma merged commit ed44f6e into main Feb 1, 2024
11 of 12 checks passed
@osma osma deleted the issue1484-concept-page-copy-to-clipboard branch February 1, 2024 14:16
@osma osma modified the milestones: 3.x, 3.0 Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done (verified in test.dev.finto.fi, set Milestone 3.0 for both issue & PR)
Development

Successfully merging this pull request may close these issues.

New copy-to-clipboard component for Skosmos 3.0 Alt text for the copy to clipboard buttons
2 participants