Skip to content

added copy to clipboard feature on trace id #2815

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

Closed
wants to merge 2 commits into from

Conversation

Darshit42
Copy link

@Darshit42 Darshit42 commented May 24, 2025

Which problem is this PR solving?

Description of the changes

  • added a useState hook to keep track of copying the traceid and used Tooltip

How was this change tested?

  • on UI user can see copy to clipboard when hovered over trace id and when clicked it copies the trace id to clipboard

Checklist

@Darshit42 Darshit42 requested a review from a team as a code owner May 24, 2025 17:55
@Darshit42 Darshit42 requested review from jkowall and removed request for a team May 24, 2025 17:55
@Parship999
Copy link
Contributor

@Darshit42 As per the contributing guidelines, all commits need to be signed, this ensures compliance with the DCO. Also, please review the checklist and ensure that all relevant items are properly checked off.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

  • the proposal as to create a dedicated "click to copy" component so that we can reuse it in more than one place
  • include the screenshots in the PR description

setHasCopied(true);
setTimeout(() => {
setHasCopied(false);
}, 2000);
Copy link
Member

Choose a reason for hiding this comment

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

this works but it's an unstable way to implement this. If I click the link again 1.9s after the first time, then "copied" text will disappear in 0.1s instead of 2s. A more robust way to do it is

  • whenClick stores a deadline timestamp in a state (such that later click will override it to later timestamp): deadline=time.Now + 1.8sec
  • whenClick kicks of a timeout function
  • timeout function checks if the current time >= deadline, then it sets copied=false, otherwise it doesn't do that

Another solution is to cancel old timeout when new one is created, but I think it's even harder to implement

Copy link
Author

@Darshit42 Darshit42 May 25, 2025

Choose a reason for hiding this comment

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

I didn't consider this while implementing previous code, I have created a separate ClickToCopy function below if everything seems correct i'll push the code

image

@abhayporwals
Copy link
Contributor

before pushing new commit, sign the old commit please.
then you can push the changes as per the review and make sure you sign.

@Darshit42
Copy link
Author

@Parship999 @yurishkuro I have made the changes, I also changed test cases to fit the new component, to be honest I wrote/changed test cases for first time if you can tell me how to improve them please let me know :)

@Darshit42 Darshit42 requested a review from yurishkuro May 27, 2025 05:28
@Darshit42
Copy link
Author

Darshit42 commented May 27, 2025

before pushing new commit, sign the old commit please. then you can push the changes as per the review and make sure you sign.

thanks for the advice I will do it :)

Edit--

by sign them do you mean tick the checklist? I did run the tests before pushing

@yurishkuro
Copy link
Member

by sign them do you mean tick the checklist? I did run the tests before pushing

https://github.com/jaegertracing/jaeger/blob/a7c26c55b0691c891842d89ddc3999d9f667bb67/CONTRIBUTING_GUIDELINES.md?plain=1#L138

@Darshit42
Copy link
Author

@yurishkuro @Parship999 I think they are now signed I ran this command git commit --amend -s

@yurishkuro
Copy link
Member

You can see the DCO check failing in CI checks. git amend only affects the latest commits, but the check expects all of them signed. Usually the easiest way is to manually squash all commits and sign the latest, but it gets complicated if you did multiple merge-main in between.

@Darshit42 Darshit42 force-pushed the main branch 2 times, most recently from faf0cb7 to af3be5e Compare May 29, 2025 14:19

return (
<Tooltip title={isCopied ? 'Copied to clipboard' : 'Copy to clipboard'}>
<span className={className} onClick={whenClicked} role="textbox" tabIndex={0}>
Copy link

Choose a reason for hiding this comment

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

The role="textbox" attribute is semantically incorrect for this element since it doesn't accept text input. Consider using role="button" instead, which better represents the element's copy action functionality. Additionally, adding an aria-label attribute (e.g., aria-label="Copy trace ID to clipboard") would improve accessibility by clearly communicating the element's purpose to screen reader users.

Suggested change
<span className={className} onClick={whenClicked} role="textbox" tabIndex={0}>
<span className={className} onClick={whenClicked} role="button" aria-label="Copy to clipboard" tabIndex={0}>

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.


return (
<Tooltip title={isCopied ? 'Copied to clipboard' : 'Copy to clipboard'}>
<span className={className} onClick={whenClicked} role="textbox" tabIndex={0}>
Copy link

Choose a reason for hiding this comment

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

The component is keyboard accessible with tabIndex={0} but doesn't handle keyboard interactions. For full accessibility, please add keyboard event handling for Enter and Space keys:

onKeyDown={(e) => {
  if (e.key === 'Enter' || e.key === ' ') {
    e.preventDefault();
    whenClicked();
  }
}}

This ensures users navigating with keyboards can also trigger the copy functionality.

Suggested change
<span className={className} onClick={whenClicked} role="textbox" tabIndex={0}>
<span className={className} onClick={whenClicked} onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
whenClicked();
}
}} role="textbox" tabIndex={0}>

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@@ -66,12 +72,13 @@ describe('TraceIdDisplayLength', () => {
getConfigValue.mockReturnValue(configuredLength);

wrapper = createWrapper({ traceId: shortTraceId });
expect(wrapper.text()).toEqual(shortTraceId);
expect(wrapper.find('ClickToCopy').children().text()).toEqual(shortTraceId);
});

it('renders when traceId is undefiend', () => {
Copy link

Choose a reason for hiding this comment

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

There's a typo in the test description: undefiend should be undefined.

Suggested change
it('renders when traceId is undefiend', () => {
it('renders when traceId is undefined', () => {

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@yurishkuro
Copy link
Member

please sign all commits

@Darshit42 Darshit42 force-pushed the main branch 5 times, most recently from a789032 to 41ef276 Compare June 1, 2025 08:12
Comment on lines +43 to +48
<span
className={`TraceIDLength ${lengthClass} u-tx-muted ${className}`}
onClick={whenClicked}
role="button"
tabIndex={0}
>
Copy link

Choose a reason for hiding this comment

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

The component correctly implements visual accessibility with role="button" and tabIndex={0}, but is missing keyboard event handling. For full accessibility compliance, please add an onKeyDown handler to support activation via keyboard (Enter or Space key):

onKeyDown={(e) => {
  if (e.key === 'Enter' || e.key === ' ') {
    whenClicked();
  }
}}

This ensures the component is fully accessible to keyboard-only users, which is an important WCAG requirement.

Suggested change
<span
className={`TraceIDLength ${lengthClass} u-tx-muted ${className}`}
onClick={whenClicked}
role="button"
tabIndex={0}
>
<span
className={`TraceIDLength ${lengthClass} u-tx-muted ${className}`}
onClick={whenClicked}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
whenClicked();
}
}}
role="button"
tabIndex={0}
>

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@Darshit42
Copy link
Author

please sign all commits

@yurishkuro I tried signing them but i think its hard due to different commits between my commits, can I close this and open a new pr with all commits signed?

@Darshit42
Copy link
Author

Darshit42 commented Jun 1, 2025

@yurishkuro I just saw another pr has been merged regarding this issue I am sorry for delay, I understand as this was a minor issue and was going on for days, should I close this pr?

@abhayporwals
Copy link
Contributor

@yurishkuro I just saw another pr has been merged regarding this issue I am sorry for delay, I understand as this was a minor issue and was going on for days, should I close this pr?

Nope, That was not merged in jaeger-ui.
You can still open a new PR and make the required changes. Make sure you sign all the commits by adding -s flag while adding commit.

This issue open from a week now. So, if you don't like to work on this or having trouble than also let us know.

Thanks.

@yurishkuro
Copy link
Member

@Darshit42 you can open a new PR and reference this one

@Darshit42
Copy link
Author

I am closing this PR as I am opening another PR

@Darshit42 Darshit42 closed this Jun 3, 2025
@Darshit42 Darshit42 mentioned this pull request Jun 4, 2025
4 tasks
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.

4 participants