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

web: Improve UX for copyCode animation #48958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apoorvapendse
Copy link

@apoorvapendse apoorvapendse commented Dec 6, 2024

Description

This PR introduces a new toast animation instead
of the previous modal that would have to be manually closed.
The new toast is less intrusive to the user's workflow
and closes by itself.

preview

copy_to_clipboard_updated_animation.mp4

Issue

#48950.

Closes: #48950.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Dec 6, 2024
Copy link

linux-foundation-easycla bot commented Dec 6, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: apoorvapendse / name: Apoorva Pendse (134e4b4)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Dec 6, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sftim for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes sig/docs Categorizes an issue or PR as relevant to SIG Docs. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Dec 6, 2024
@sftim
Copy link
Contributor

sftim commented Dec 6, 2024

The failed build looks like an internal error (nil pointer error) within hugo.

Build log excerpt
4:50:46 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
4:50:46 AM: ERROR render of "page" failed: "/opt/build/repo/layouts/docs/baseof.html:59:7": execute of template failed: template: docs/single.html:59:7: executing "docs/single.html" at <partial "scripts.html" .>: error calling partial: "/opt/build/repo/layouts/partials/scripts.html:55:3": execute of template failed: template: partials/scripts.html:55:3: executing "partials/scripts.html" at <partial "hooks/body-end.html" .>: error calling partial: "/opt/build/repo/layouts/partials/hooks/body-end.html:11:29": execute of template failed: template: partials/hooks/body-end.html:11:29: executing "partials/hooks/body-end.html" at <$toastrCss.RelPermalink>: nil pointer evaluating resource.Resource.RelPermalink
4:50:46 AM: Total in 39071 ms

@apoorvapendse
Copy link
Author

The failed build looks like an internal error (nil pointer error) within hugo.

Build log excerpt
4:50:46 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
4:50:46 AM: ERROR render of "page" failed: "/opt/build/repo/layouts/docs/baseof.html:59:7": execute of template failed: template: docs/single.html:59:7: executing "docs/single.html" at <partial "scripts.html" .>: error calling partial: "/opt/build/repo/layouts/partials/scripts.html:55:3": execute of template failed: template: partials/scripts.html:55:3: executing "partials/scripts.html" at <partial "hooks/body-end.html" .>: error calling partial: "/opt/build/repo/layouts/partials/hooks/body-end.html:11:29": execute of template failed: template: partials/hooks/body-end.html:11:29: executing "partials/hooks/body-end.html" at <$toastrCss.RelPermalink>: nil pointer evaluating resource.Resource.RelPermalink
4:50:46 AM: Total in 39071 ms

Oh, I see...
Thanks for pointing that out, I'll make sure to read the logs carefullly next time.

@apoorvapendse apoorvapendse force-pushed the main branch 2 times, most recently from 3dc1438 to 8fbfee2 Compare December 6, 2024 13:32
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Dec 6, 2024
Copy link

netlify bot commented Dec 6, 2024

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 3dc1438
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/6752fcacc41cc500080e76ff
😎 Deploy Preview https://deploy-preview-48958--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 6, 2024

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 134e4b4
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/6753a38dd24ae00008661d7a
😎 Deploy Preview https://deploy-preview-48958--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@apoorvapendse apoorvapendse force-pushed the main branch 2 times, most recently from e29c87a to c51f0c7 Compare December 6, 2024 17:45
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

Ideally, localize the strings (ie, make them localizable). However we can merge without doing that because the existing string is also not localized.

layouts/partials/hooks/head-end.html Outdated Show resolved Hide resolved
layouts/partials/hooks/body-end.html Outdated Show resolved Hide resolved
layouts/partials/hooks/body-end.html Outdated Show resolved Hide resolved
layouts/partials/hooks/body-end.html Outdated Show resolved Hide resolved
@sftim
Copy link
Contributor

sftim commented Dec 6, 2024

LGTM if #48958 (comment) is fixed

Comment on lines 14 to 15
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why latest for a preview but the committed code for production?

Better to do one of:

  • use js/toastr-2.1.4.min.js either way
  • load from the CDN either way, pin to a specific release, and hard code the expected value of integrity

Copy link
Author

Choose a reason for hiding this comment

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

Yeah sure 👍
Actually that url isn't maintained anymore
I guess I'll go with the local file for both.

Copy link
Author

Choose a reason for hiding this comment

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

So, do we need an if block for this case at all?
Since we are loading the same files in both the cases?

@k8s-ci-robot k8s-ci-robot added the language/en Issues or PRs related to English language label Dec 6, 2024
Copy link
Member

Choose a reason for hiding this comment

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

Consider moving the newly added entries in this "en.toml" file based on alphabetical order to align with the rest of the entries.

Copy link
Author

Choose a reason for hiding this comment

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

Sure 👍

Copy link
Author

Choose a reason for hiding this comment

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

image
The order for blog and banner seem mismatched, should I fix that too?

This commit introduces a new toast animation instead
of the previous modal that would have to be manually closed.
The new toast is less intrusive to the user's workflow
and closes by itself.

Fixes issue: 48950.

Signed-off-by: Apoorva Pendse <apoorvavpendse@gmail.com>
@apoorvapendse
Copy link
Author

Hey, I've updated the PR as per the feedback.
Looking forward to your suggestions.
Thanks

@apoorvapendse
Copy link
Author

@sftim, any other changes that are required for this PR to be considered?

@sftim
Copy link
Contributor

sftim commented Dec 13, 2024

Cool

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 13, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 5ab87dd5e2d52cf0c12c94b96e9061b6a93f7512

@sftim
Copy link
Contributor

sftim commented Dec 13, 2024

It might be a few weeks before we can get this approved, I'm afraid.

Copy link
Contributor

@chalin chalin left a comment

Choose a reason for hiding this comment

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

Hi all. Docsy supports a click-to-copy button functionality for all code blocks, as @sftim noticed in #48812 (comment).

For example, here's the tooltip on hover:

image

This is after the button is clicked:

image

In the spirit of ongoing Align with upstream Docsy #41171, if we're to spend some effort improving on #48950, would it not be better to alight with Docsy's offering?

Docsy's click-to-copy works out-of-the-box for all code blocks, is compatible with dark mode, etc.

(Btw, official Docsy support for click to copy started in Docsy 0.7, but the feature elements are a part of 0.5.)

/cc @nate-double-u

@sftim
Copy link
Contributor

sftim commented Dec 14, 2024

I'm OK to merge this and then change again once we have newer Docsy. We've had click-to-copy since before Docsy; improving what we have is useful, even if we eventually converge.

@apoorvapendse
Copy link
Author

Hi all. Docsy supports a click-to-copy button functionality for all code blocks, as @sftim noticed in #48812 (comment).

Thanks for the details @chalin.
Should I close the pull request if this doesn't suit your plans?
Thanks for letting me work on it.

@apoorvapendse
Copy link
Author

I'm OK to merge this and then change again once we have newer Docsy. We've had click-to-copy since before Docsy; improving what we have is useful, even if we eventually converge.

Sure 👍

@@ -6,29 +6,54 @@
{{ end }}
{{/* copy-and-paste helper for codenew shortcode */}}
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
{{- $toastrJs := resources.Get "js/toastr-2.1.4.min.js" | minify | fingerprint -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW: we'd typically only minify the code in production builds.

Copy link
Author

Choose a reason for hiding this comment

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

okay I'll remove the pipe.

Copy link
Author

Choose a reason for hiding this comment

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

@sftim, but js file on the server in already minified, so what should be the next step?

Copy link
Author

Choose a reason for hiding this comment

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

Should I add a non minified version just for development?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve UX for code_sample shortcode
5 participants