Skip to content

ui: Copy error message from toast to clipboard#4624

Merged
Etsija merged 2 commits intomainfrom
copy-toast-error
Mar 6, 2026
Merged

ui: Copy error message from toast to clipboard#4624
Etsija merged 2 commits intomainfrom
copy-toast-error

Conversation

@Etsija
Copy link
Contributor

@Etsija Etsija commented Mar 6, 2026

Screenshot from 2026-03-06 10-55-09 Screenshot from 2026-03-06 10-55-20

How it looks in a text editor

Screenshot from 2026-03-06 10-55-46

Please see the commits for details.

@Etsija Etsija requested review from lamppu and sschuberth as code owners March 6, 2026 09:13
@Etsija Etsija linked an issue Mar 6, 2026 that may be closed by this pull request
@Etsija Etsija force-pushed the copy-toast-error branch from 0cf2142 to 69bb13c Compare March 6, 2026 09:14
@Etsija Etsija enabled auto-merge March 6, 2026 09:15
@sschuberth
Copy link
Contributor

Just looking at the screenshots, I like it a lot! Leaving the code review to @lamppu and others.

type='button'
onClick={handleCopyClick}
>
<Button variant='ghost' size='sm' onClick={handleCopyClick}>
Copy link
Contributor

@lamppu lamppu Mar 6, 2026

Choose a reason for hiding this comment

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

Can you test copying the JSON payload from the create run form, IIRC the type='button' was added here to prevent the form from submitting when clicking the copy button.

Copy link
Contributor Author

@Etsija Etsija Mar 6, 2026

Choose a reason for hiding this comment

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

So that's what it was for! I couldn't understand why we would be forced to tell a Button that it is a Button, but indeed, without it, it does create a new run in that view, so thanks for catching this! Need to remember in case we use CopyToClipboard in some other forms in the future.

Etsija added 2 commits March 6, 2026 12:13
Sonner's swipe-to-dismiss and touch action implementation prevents manual
text selection from all toasts. There is no Sonner API to disable this
selectively for the content area, so making the text manually selectable is
not feasible without patching the library.

Instead, add copy-to-clipboard button to each error toast, by passing a
`ReactNode` to Sonner's cancel option containing a stacked column of
"Dismiss" button + `CopyToClipboard`. 

By centralizing the toast error creation into a `toastError()` helper, also
remove ~800 lines of boilerplate UI code from 75 call sites.

Signed-off-by: Jyrki Keisala <jyrki.keisala@doubleopen.org>
As the `title`, `message` and `cause` of the error are readily available,
separate them in the text which is copied to clipboard. 

To help readability of the message/cause, also word-wrap the lines on
column 75.

Resolves #4507.

Signed-off-by: Jyrki Keisala <jyrki.keisala@doubleopen.io>
@Etsija Etsija force-pushed the copy-toast-error branch from 69bb13c to d62ad8b Compare March 6, 2026 10:14
@Etsija Etsija requested a review from lamppu March 6, 2026 10:16
@Etsija Etsija added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit 42a2861 Mar 6, 2026
34 checks passed
@Etsija Etsija deleted the copy-toast-error branch March 6, 2026 11:04
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.

Allow to copy the text of error toasts

3 participants