Skip to content
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

Merged
merged 3 commits into from
Sep 20, 2022

Conversation

lpessoa
Copy link
Contributor

@lpessoa lpessoa commented Aug 30, 2022

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.

@lpessoa lpessoa requested a review from juliusv as a code owner August 30, 2022 03:03
@roidelapluie
Copy link
Member

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:

Signed-Off-By: Your Name <your@email.address>

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

git commit --amend --signoff
git push -f $remote $remote_branch_for_pr

As always, be careful when force-pushing.

@juliusv
Copy link
Member

juliusv commented Aug 31, 2022

Heya, nice, thanks! A couple of comments:

  • The Toasted toasts look nice, but since we're already using Bootstrap (via Reactstrap), could we use the Toasts from that to not pull in a new dependency for such a small feature?
  • A user currently wouldn't know what clicking on a label does, could we add a title="Click to copy label matcher" attribute to the span?
  • Even with the title, it would be good to visually clarify whether the entire set of matchers is being copied or only one. We could do that by introducing a :hover class for the legen-label-container and setting something like background-color: #add6ff; border-radius: 3px; padding-bottom: 1px; on it:
    copy-label

I'm also thinking it would be good to eventually have a way to copy the entire series identifier, or the metric name. Just being able to copy specifically a single label matcher seems a bit arbitrary to me at least. But I'm not sure how to add that UI-wise for the entire series identifier. I guess we'd have to put a little copy icon next to each series, but that adds a lot of clutter, so let's better sleep on that.

navigator.clipboard
.writeText(copyText)
.then(() => {
toast.success('label selector copied 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.

Some extra spaces here, and "label matcher" would be the specific technical term for a single label:

Suggested change
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>
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>
@lpessoa
Copy link
Contributor Author

lpessoa commented Sep 3, 2022

@juliusv added the suggested changes to the code. Maybe i will change the ClipboardContext signature to not only pass the content copied to the clipboard but also the message to be displayed (just to make it a bit more flexible) WDYT?

We can also think of if the user hovers over the { or } we can highlight the whole block in a different color and allow him to copy all labels in one step.

Copy link
Member

@juliusv juliusv left a 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">
Copy link
Member

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.

Copy link
Contributor Author

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

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).

@lpessoa
Copy link
Contributor Author

lpessoa commented Sep 12, 2022

@juliusv applied suggested changes and reworked the tests 😃

@juliusv
Copy link
Member

juliusv commented Sep 12, 2022

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>
@lpessoa
Copy link
Contributor Author

lpessoa commented Sep 12, 2022

Done... no idea how it got lpessoa instead of Luis Pessoa 🤷🏼‍♂️ @juliusv

@juliusv
Copy link
Member

juliusv commented Sep 20, 2022

Ah, belated thanks, gonna merge 👍

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.

None yet

3 participants