-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
Allow copying label-value pair to buffer on click #11229
Conversation
Thanks for your PR. For legal reasons, we require that all commits are signed with a DCO before we can merge them. See this blog post for considerations around this. This means that the last line of your commit message should read like:
If you are using GitHub through the web interface, it's quickest to close this PR and open a new one with the appropriate line. If you are using Git on the command line, it is probably quickest to amend and force push. You can do that with
As always, be careful when force-pushing. |
navigator.clipboard | ||
.writeText(copyText) | ||
.then(() => { | ||
toast.success('label selector copied 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.
Some extra spaces here, and "label matcher" would be the specific technical term for a single label:
toast.success('label selector copied to clipboard', { | |
toast.success('Label matcher copied to clipboard.', { |
Kept similar DOM structure to keep test compatibility. Using `navigator.clipboard` API since it is used by the current standard browsers. React hot toast is used to notify that the text was successfully copied into clipboard. Signed-off-by: lpessoa <luisalmeida@yape.com.pe>
c681a6d
to
cf3d3e1
Compare
Using the bootstrap toast notification provided by reactstrap. Clipboard handling is managed using React.Context via a shared callback. Updated css according to CR suggestions. Signed-off-by: lpessoa <luisalmeida@yape.com.pe>
c1d13f3
to
cc01c11
Compare
@juliusv added the suggested changes to the code. Maybe i will change the We can also think of if the user hovers over the |
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.
Yeah, how to copy the rest of the series components is still an open question IMO, but we don't need to solve it in this PR. The curly braces are too small to comfortably hover over. Maybe hovering over the metric name should select the entire series 🤷♂️
@@ -16,7 +34,7 @@ const SeriesName: FC<SeriesNameProps> = ({ labels, format }) => { | |||
} | |||
|
|||
labelNodes.push( | |||
<span key={label}> | |||
<span className="legend-label-container" onClick={toClipboard} key={label} title="Click to copy label matcher"> |
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 noticed that the hovering now includes the comma between labels as well.
How about changing the HTML here so that the legend-label-container
only wraps the k=v part without the comma, like:
<span key={label}>
{!first && ', '}
<span className="legend-label-container" onClick={toClipboard} title="Click to copy label matcher">
<span className="legend-label-name">{label}</span>=<span className="legend-label-value">"{labels[label]}"</span>
</span>
</span>
Then you can also drop the logic around the comma in toClipboard
.
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.
Thought of that too. I have to confess that i did not go with that approach since it would require to change the existing tests a little bit 😄... but it is the proper way to go.
@@ -0,0 +1,11 @@ | |||
import React from 'react'; | |||
|
|||
const ClipboardContext = React.createContext((msg: string) => { |
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 would tend to not call this ClipboardContext
, but just ToastContext
, to both clarify what it's actually about and make it more general in use. When I first read the name, I assumed this was for storing the clipboard message (but I think keeping the clipboard message just in the actual clipboard as you do it now is good).
@juliusv applied suggested changes and reworked the tests 😃 |
Thanks, looks good now, just the DCO CI check is failing now with this message for one of the commits: Commit sha: dd254c8, Author: Luis Pessoa, Committer: Luis Pessoa; Expected "Luis Pessoa luisalmeida@yape.com.pe", but got "lpessoa luisalmeida@yape.com.pe". I guess it expects you to sign off with your full name that you also use as the author in Git. |
Cleaning up renderFormatted method. Renamed Clipboard to ToastContext. Updated tests. Signed-off-by: Luis Pessoa <luisalmeida@yape.com.pe>
dd254c8
to
4a9c2b5
Compare
Done... no idea how it got lpessoa instead of Luis Pessoa 🤷🏼♂️ @juliusv |
Ah, belated thanks, gonna merge 👍 |
Addresses #7995
Kept similar DOM structure to keep test compatibility.
Using
navigator.clipboard
API since it is used by the current standard browsers.React hot toast is used to notify that the text was successfully copied into clipboard.