-
-
Notifications
You must be signed in to change notification settings - Fork 391
[2.x] Disable the copy button in insecure contexts #1271
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
base: 2.x
Are you sure you want to change the base?
[2.x] Disable the copy button in insecure contexts #1271
Conversation
8242e1a
to
c1ffb8e
Compare
c1ffb8e
to
42398d4
Compare
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.
@keerthi-swarna Thanks for working on this! Left a few suggestions on how to improve this PR below.
/** | ||
* Boolean flag that indicates whether the copy functionality is disabled or not. | ||
* This helps to disable the copy action button. The value is based on the presence | ||
* of `navigator.clipboard`. If `navigator.clipboard` is unavailable, the copy | ||
* functionality is considered disabled, and the `copyStatus` will be set to | ||
* either `CopyStatus.None` or `CopyStatus.Disabled`. | ||
*/ | ||
isCopyDisabled: boolean; |
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 don't think adding isCopyDisabled
is necessary here, since consumers can already check if the status is disabled by using this condition:
disabled={copyStatus === CopyStatus.Disabled}
Generally, we should avoid having 2 sources of truth for the same thing, since a future change might accidentally cause the two to differ.
@@ -38,15 +47,19 @@ export type UseCopyReturn = { | |||
const DEFAULT_LABELS_BY_COPY_STATUS: Record<CopyStatus, string> = { | |||
[CopyStatus.None]: 'Copy to clipboard', | |||
[CopyStatus.Copying]: 'Copying…', | |||
[CopyStatus.Copied]: 'Copied!' | |||
[CopyStatus.Copied]: 'Copied!', | |||
[CopyStatus.Disabled]: 'Copy to clipboard disabled in insecure context' |
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.
We should provide more helpful information to users in the tooltip, since many users will not know what an insecure context is.
[CopyStatus.Disabled]: 'Copy to clipboard disabled in insecure context' | |
[CopyStatus.Disabled]: 'The clipboard is disabled by your browser because you are accessing this page outside of a secure context. To enable the clipboard, you must access this page through a HTTPS connection.' |
You may have to adjust the CSS set by the sx
prop in MUI React Elements to get this to render in a readable way.
SHA256 hashes: jupyter-ai-core-2.30.0.tgz: 4c675fe9bdf903977b4a24f5732f89299ed9413e7cb777c46b450594b51abb4b jupyter_ai-2.30.0-py3-none-any.whl: 1a0ef2b45b3c9419675e2107bf627b897ba2932e4450424f37d05760cf6b3473 jupyter_ai-2.30.0.tar.gz: 2aff02d999d607add850624bfb46b1a1f2701ddf8614bb58f20e8c6847361ac7 jupyter_ai_magics-2.30.0-py3-none-any.whl: a2bab2b12c926ec726b832e1ddc6fddda72924e5e65c5e348731d231f3f9578a jupyter_ai_magics-2.30.0.tar.gz: e4e4d59a57450ca5e2d29760f42872d2103be3132f6744760f39651bced5e895
…ds, fix coupled model fields, add custom OpenAI provider) (jupyterlab#1282) * Backport PR jupyterlab#1264: Allow embedding model fields, fix coupled model fields, add custom OpenAI provider * Fix CI --------- Co-authored-by: Sanjiv Das <[email protected]>
…ent in future releases (jupyterlab#1284) Co-authored-by: David L. Qiu <[email protected]>
SHA256 hashes: jupyter-ai-core-2.31.0.tgz: 5df1a9db40af5847610fa3292c049a3ce533d10ac5b2a1a813f9dd06b31b4fc1 jupyter_ai-2.31.0-py3-none-any.whl: 9e71984a29ff35a515c883eb510a5f9789b3aec375b8584695b1797f536c7bee jupyter_ai-2.31.0.tar.gz: 938aff4db8d5524cea7fadbf6e2e3ad85141bf76ed19d8456586beacaba23fba jupyter_ai_magics-2.31.0-py3-none-any.whl: 38ac34ab4f50ecb0312a38adb04b98d02c0d22c0f7dcbdacf95446de5b6271e3 jupyter_ai_magics-2.31.0.tar.gz: 213479558738e81d107fec8ad587949f29e998318777429f203c0c15d8023045
… is absent (jupyterlab#1289) Co-authored-by: Sanjiv Das <[email protected]>
…viders in the AI Setting page (jupyterlab#1292) Co-authored-by: Sanjiv Das <[email protected]>
…regression (jupyterlab#1295) Co-authored-by: David L. Qiu <[email protected]>
SHA256 hashes: jupyter-ai-core-2.31.1.tgz: c3013cb668d9db6de0e12f27b43eb93fbecb38eccd2f954e7fc11093a7e450c5 jupyter_ai-2.31.1-py3-none-any.whl: 0a4ec61007f2d5473405aba50acd4134fc1df4d17e71a0a76bcb7f6123925f7d jupyter_ai-2.31.1.tar.gz: b0794139a161d872aff538acfc8931fc8f0a48f433ff52da66988f60d3aebfbc jupyter_ai_magics-2.31.1-py3-none-any.whl: d117f149c84b436d5d7990dca17105e93fa734359c981bc81a2822f01827edf1 jupyter_ai_magics-2.31.1.tar.gz: 721bc28010ad09262036f67f70b6967dd37b3cffcc651ee25a56122dc5e0c586
…respecified custom config file (jupyterlab#1302) Co-authored-by: Sanjiv Das <[email protected]>
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.
@keerthi-swarna It looks like the Git history of this branch is weird. I recommend that in the future, you should avoid merging 2.x
back into your feature branch, and instead prefer rebasing to update your feature branch.
Rebasing essentially means taking your PR branch and moving it to the head of a base branch, which updates your PR branch to include changes in the base branch. You will want to rebase this branch onto 2.x
& fix any merge conflicts that arose in the last 3 weeks.
You can do so by running the following:
# update your copy of 2.x branch
git switch 2.x
git pull
git switch disable-copy-button-v1
# rebase your branch onto the latest 2.x branch
# this is saying "take all the commits that differ b/w 2.x and this branch,"
# "then, put them back *onto* the latest 2.x branch"
#
# you will likely have to address merge conflicts here.
git rebase 2.x disable-copy-button-v1 --onto 2.x
# verify your branch state
git status
# then, push and override the remote branch used in this PR
git push -f
Hi @dlqqq and @keerthi-swarna, My name is Jiya Gupta. I would like to work on this issue as well, but I'm unable to see the copy button inside the cell, even in a secure context (HTTPS or localhost). Additionally, when the server runs on HTTP, I still don't see the button. |
@Jiya873 The screenshot you're looking at is the JupyterLab cell toolbar, which is different from the toolbar we offer underneath code blocks in the Jupyter AI chat panel. If you're interested in contributing, you can look through our issues to find one you want to work on, then ping me to assign yourself to it. If you have questions, feel free to ping me or join our community calls every week on Wednesdays at 0830 Pacific Time. 🤗 |
@dlqqq thanks for clearing. I’ll go through the issues and let you know which one I’d like to take on. Excited to contribute!! |
Problem Statement
The "Copy to Clipboard" button fails to function when the JupyterLab server is accessed over HTTP (insecure context). Clipboard functionality requires a secure context (HTTPS or localhost), and when the server runs on HTTP, the copy action is disabled. This can cause confusion for users who may expect the button to work even in insecure contexts. To improve the user experience and minimize confusion, the copy button should be disabled when the server is served over HTTP, with a tooltip explaining that copying requires a secure context.
Changes Made
useCopy
hook to include an additional boolean parameter that controls the button's enabled/disabled state.Disabled
, to indicate the copy status along with an appropriate label.Expected Behavior
Testing