Skip to content

Add copy to clipboard as shared service - #2507

Open
rkweehinzmann wants to merge 25 commits into
masterfrom
add-copy-to-clipboard-as-shared-service
Open

Add copy to clipboard as shared service#2507
rkweehinzmann wants to merge 25 commits into
masterfrom
add-copy-to-clipboard-as-shared-service

Conversation

@rkweehinzmann

@rkweehinzmann rkweehinzmann commented Aug 21, 2026

Copy link
Copy Markdown
Member

Description

a new copy service is introduced as shared service and used in published data details.

Motivation

More convenience: Goal was to make the doi copyable just like the pids in dataset details.

Changes:

introduce new service at central place (app/shared/service) to use in published data for doi field.

  • changes made:
  • added files as was suggested by AI: introduce a new service in shared/service, also in index.ts to export the function then where it is used in publisheddata-details.components.ts and its html.

Other

For maintainability reasons one can follow up replacements of other places (see screenshot) where this functionality was used. Main bottleneck is testing that functionality remains in all cases the same.

Screenshot from github bot
Screenshot 2026-08-21 at 09 02 07

Tests included

  • Included for each change/fix?
  • Passing? (Merge will not be approved unless this is checked)

Backend version

  • Does it require a specific version of the backend
  • which version of the backend is required: not needed

Summary by Sourcery

Centralize clipboard functionality and expand configurable actions across published data and application layout.

New Features:

  • Add a shared clipboard service and use it to let users copy published-data DOIs with feedback.

Enhancements:

  • Integrate published-data operations with configurable actions and add support for published-data context, ownership, login state, one-time actions, links, and success navigation.
  • Add configurable footer links for imprint and privacy pages.
  • Allow snackbar messages to provide optional actions that navigate to configured routes.

Documentation:

  • Document login-state and ownership condition keywords for configurable actions.

Tests:

  • Extend configurable-action and published-data tests for new action conditions and configurable published-data actions.

armandobermudezmartinez and others added 25 commits August 11, 2026 13:05
…ce-usein-publisheddata-details' into add-copy-to-clipboard-as-shared-service
@rkweehinzmann
rkweehinzmann requested a review from a team as a code owner August 21, 2026 13:42

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • ClipboardService calls navigator.clipboard.writeText directly without feature detection or a non-HTTPS fallback, which may break in unsupported or insecure browsing contexts; consider guarding with if (navigator.clipboard?.writeText) and providing a graceful fallback or message when unavailable.
  • UsersService is imported into configurable-action.component.ts but never used; it can be removed to avoid unused dependency warnings and keep the component lean.
  • The Cypress tests for published data actions now rely on configurable-action button with visible text instead of data-cy attributes, which is more brittle against UI/content changes; consider keeping stable data-cy hooks on the relevant action buttons in the configurable-actions component or wrapper.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- ClipboardService calls `navigator.clipboard.writeText` directly without feature detection or a non-HTTPS fallback, which may break in unsupported or insecure browsing contexts; consider guarding with `if (navigator.clipboard?.writeText)` and providing a graceful fallback or message when unavailable.
- `UsersService` is imported into `configurable-action.component.ts` but never used; it can be removed to avoid unused dependency warnings and keep the component lean.
- The Cypress tests for published data actions now rely on `configurable-action button` with visible text instead of `data-cy` attributes, which is more brittle against UI/content changes; consider keeping stable `data-cy` hooks on the relevant action buttons in the configurable-actions component or wrapper.

## Individual Comments

### Comment 1
<location path="src/app/_layout/app-footer/app-footer.component.scss" line_range="19" />
<code_context>
+
+    .toplink {
+      padding: 0.5rem 1rem;
+      font: bold;
+      font-size: 11pt;
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Replace invalid `font: bold;` with a proper font-weight declaration.

`font` is a shorthand that expects a full font definition, so `font: bold;` is invalid and may be ignored. If you only need bold text, use `font-weight: bold;` instead for reliable rendering.
</issue_to_address>

### Comment 2
<location path="src/app/shared/services/clipboard.service.ts" line_range="24" />
<code_context>
+    successMessage: string = "Copied to clipboard",
+    duration: number = 5000,
+  ): void {
+    navigator.clipboard.writeText(text).then(
+      () => {
+        const message = new Message(
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against missing `navigator.clipboard` to avoid runtime errors in unsupported environments.

Because `navigator.clipboard.writeText` can throw synchronously when the Clipboard API isn’t available (e.g. some test runners, non-secure origins, older browsers), that error bypasses your Promise handlers and can crash the app. You can feature-detect and show a message instead:

```ts
if (!navigator.clipboard || !navigator.clipboard.writeText) {
  const errorMessage = new Message(
    "Clipboard not supported",
    MessageType.Error,
    duration,
  );
  this.store.dispatch(showMessageAction({ message: errorMessage }));
  return;
}

navigator.clipboard.writeText(text).then(…)
```
</issue_to_address>

### Comment 3
<location path="docs/contributors/configurable_actions_technical.md" line_range="152" />
<code_context>
 | #userIsAdmin | boolean | True if the user is an admin |
+| #userIsLoggedIn | boolean | True if the user is logged in (negate with a leading `!`, e.g. `!#userIsLoggedIn`) |
 | #uuid | string | A v4 uuid generated on the fly |
 | @variable | any | replace the string with the valu eof the variable defined in the action variable |

</code_context>
<issue_to_address>
**issue (typo):** Fix the typo "valu eof" to "value of" in the description.

Consider rephrasing this to: "replace the string with the value of the variable defined in the action variable."
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


.toplink {
padding: 0.5rem 1rem;
font: bold;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Replace invalid font: bold; with a proper font-weight declaration.

font is a shorthand that expects a full font definition, so font: bold; is invalid and may be ignored. If you only need bold text, use font-weight: bold; instead for reliable rendering.

successMessage: string = "Copied to clipboard",
duration: number = 5000,
): void {
navigator.clipboard.writeText(text).then(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Guard against missing navigator.clipboard to avoid runtime errors in unsupported environments.

Because navigator.clipboard.writeText can throw synchronously when the Clipboard API isn’t available (e.g. some test runners, non-secure origins, older browsers), that error bypasses your Promise handlers and can crash the app. You can feature-detect and show a message instead:

if (!navigator.clipboard || !navigator.clipboard.writeText) {
  const errorMessage = new Message(
    "Clipboard not supported",
    MessageType.Error,
    duration,
  );
  this.store.dispatch(showMessageAction({ message: errorMessage }));
  return;
}

navigator.clipboard.writeText(text).then()

| #userIsAdmin | boolean | True if the user is an admin |
| #userIsLoggedIn | boolean | True if the user is logged in (negate with a leading `!`, e.g. `!#userIsLoggedIn`) |
| #uuid | string | A v4 uuid generated on the fly |
| @variable | any | replace the string with the valu eof the variable defined in the action variable |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (typo): Fix the typo "valu eof" to "value of" in the description.

Consider rephrasing this to: "replace the string with the value of the variable defined in the action variable."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants