Skip to content

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

Merged
merged 4 commits into from
Jun 19, 2025

Conversation

lzhao-sentry
Copy link
Contributor

@lzhao-sentry lzhao-sentry commented Jun 19, 2025

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

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jun 19, 2025
Copy link

codecov bot commented Jun 19, 2025

Codecov Report

All 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              

@lzhao-sentry lzhao-sentry marked this pull request as ready for review June 19, 2025 19:21
@lzhao-sentry lzhao-sentry requested a review from a team as a code owner June 19, 2025 19:21
export function stringifyValue(value: string | number | string[] | undefined) {
if (!value) return '';
if (typeof value === 'string') return value;
return value.toString();
Copy link
Member

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));
Copy link
Member

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({

Copy link
Contributor Author

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"?

Copy link
Member

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!

Copy link
Contributor Author

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

Copy link
Member

@AbhiPrasad AbhiPrasad left a 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.

@lzhao-sentry lzhao-sentry merged commit c471f0b into master Jun 19, 2025
46 checks passed
@lzhao-sentry lzhao-sentry deleted the lzhao/add-copy-to-clipboard-cell-action branch June 19, 2025 21:03
@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants