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 button action #15689

Merged
merged 3 commits into from
Mar 7, 2025
Merged

Copy to Clipboard button action #15689

merged 3 commits into from
Mar 7, 2025

Conversation

andz-bb
Copy link
Contributor

@andz-bb andz-bb commented Mar 7, 2025

Description

As demoed earlier I have added a simple copy to clipboard action which does what it says on the tin on an on click/on change action. There's the option to show a notification after the value is copied. You can access the copied value in future steps using the binding {{ Action X.Copied text }}

Screenshots

image

Launchcontrol

Add a Copy to Clipboard on click action

Copy link

qa-wolf bot commented Mar 7, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@github-actions github-actions bot added the size/s label Mar 7, 2025
Copy link
Collaborator

@melohagan melohagan left a comment

Choose a reason for hiding this comment

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

LGTM - nice demo!


navigator.clipboard
.writeText(textToCopy)
.then(() => {
Copy link
Collaborator

@mike12345567 mike12345567 Mar 7, 2025

Choose a reason for hiding this comment

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

our preference for things like this would be to make this an async function, e.g. async action => { ... and then use await,

try {
  await navigator.clipboard.writeText(textToCopy)
  if (showNotification) {
    const message = notificationMessage || "Copied to clipboard"
    notificationStore.actions.success(message, true, 3000)
  }
  return { copied: textToCopy }
} catch (err) {
  console.error("Failed to copy text: ", err)
  notificationStore.actions.error("Failed to copy to clipboard")
}

This means that the further button actions in the sequence will wait for the copy to clipboard to complete before moving on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @mike12345567, it is much nicer right enough

Copy link
Collaborator

@mike12345567 mike12345567 left a comment

Choose a reason for hiding this comment

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

LGTM - one comment on handling promises, but otherwise looks good!

@andz-bb andz-bb merged commit 70b793d into master Mar 7, 2025
22 checks passed
@andz-bb andz-bb deleted the clipboard-action branch March 7, 2025 11:52
@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants