-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(explore): add copy to clipboard to cell actions #93907
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #93907 +/- ##
==========================================
- Coverage 88.03% 88.03% -0.01%
==========================================
Files 10338 10338
Lines 597029 597028 -1
Branches 23203 23203
==========================================
- Hits 525594 525593 -1
Misses 70971 70971
Partials 464 464 |
export function stringifyValue(value: string | number | string[] | undefined) { | ||
if (!value) return ''; | ||
if (typeof value === 'string') return value; | ||
return value.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toString
for an array will return the contents of the array, so [1,2,3].toString()
-> "1,2,3"
. This might not be what the user expects.
Instead I'd have a check that basically does if primitive call value.toString()
, otherwise call JSON.stringify
(falling back to toString
if JSON.stringify
fails).
We don't want to always call JSON.stringify
because it will add quotes unnecessarily.
@@ -83,6 +90,9 @@ export function updateQuery( | |||
} | |||
// these actions do not modify the query in any way, | |||
// instead they have side effects | |||
case Actions.COPY_TO_CLIPBOARD: | |||
navigator.clipboard.writeText(stringifyValue(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can throw, I would expect we extract this out to a function similar to the react hook for copying and emit error messages accordingly.
export default function useCopyToClipboard({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AbhiPrasad Should I also add a success message? And for the error, do we want to try to parse out the error message, or just display something generic like "Error copying to clipboard"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a success message would be nice, but I'd give it a try and see how the UX feels, I don't have strong feelings.
"Error copying to clipboard"
seems fine as a starting point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to leave it out to keep clutter down. imo just displaying the message when something went wrong is better. But if anyone wants it, we can add easily anytime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ambivalent toward the success message, so approving to unblock.
Changes
Add a copy to clipboard option to the tables that use the cell action dropdown. Option does not render if the value is empty/undefined. Currently only enabled for tables in explore.
Video
Screen.Recording.2025-06-19.at.12.46.53.PM.mov