-
-
Notifications
You must be signed in to change notification settings - Fork 417
[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
Open
keerthi-swarna
wants to merge
11
commits into
jupyterlab:2.x
Choose a base branch
from
keerthi-swarna:disable-copy-button-v1
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42398d4
Disable the copy button in insecure contexts
keerthi-swarna c932201
Publish 2.30.0
dlqqq b1691fd
Backport PR #1264 on branch 2.x (Allow embedding model fields, fix co…
meeseeksmachine a942271
Backport PR #1280: Ensure magics package version is consistent in fut…
meeseeksmachine edad98a
Publish 2.31.0
dlqqq 7a59043
Backport PR #1287: Remove error log emitted when FAISS file is absent…
meeseeksmachine bcffd2c
Backport PR #1288: Added help text fields for embedding providers in …
meeseeksmachine f67b895
Backport PR #1294: Migrate old config schemas, fix v2.31.0 regression…
meeseeksmachine 7534167
Publish 2.31.1
dlqqq 8aeb669
Backport PR #1298: Updating embeddings config fields from prespecifie…
meeseeksmachine b5dbb13
Refactored code to utilise copyStatusparameter
keerthi-swarna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,8 @@ import { useState, useRef, useCallback } from 'react'; | |||||
export enum CopyStatus { | ||||||
None, | ||||||
Copying, | ||||||
Copied | ||||||
Copied, | ||||||
Disabled | ||||||
} | ||||||
|
||||||
export type UseCopyProps = { | ||||||
|
@@ -29,6 +30,14 @@ export type UseCopyReturn = { | |||||
* the `useCopy()` hook. | ||||||
*/ | ||||||
copyLabel: string; | ||||||
/** | ||||||
* 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; | ||||||
/** | ||||||
* Function that takes a string and copies it to the clipboard. | ||||||
*/ | ||||||
|
@@ -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 commentThe 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.
Suggested change
You may have to adjust the CSS set by the |
||||||
}; | ||||||
|
||||||
/** | ||||||
* Hook that provides a function to copy a string to a clipboard and manages | ||||||
* related UI state. Should be used by any button that intends to copy text. | ||||||
*/ | ||||||
export function useCopy(props?: UseCopyProps): UseCopyReturn { | ||||||
const [copyStatus, setCopyStatus] = useState<CopyStatus>(CopyStatus.None); | ||||||
const isCopyDisabled = navigator.clipboard === undefined; | ||||||
dlqqq marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const [copyStatus, setCopyStatus] = useState<CopyStatus>( | ||||||
isCopyDisabled ? CopyStatus.Disabled : CopyStatus.None | ||||||
); | ||||||
const timeoutId = useRef<number | null>(null); | ||||||
|
||||||
const copy = useCallback( | ||||||
dlqqq marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -84,6 +97,7 @@ export function useCopy(props?: UseCopyProps): UseCopyReturn { | |||||
return { | ||||||
copyStatus, | ||||||
copyLabel, | ||||||
isCopyDisabled, | ||||||
copy | ||||||
}; | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:Generally, we should avoid having 2 sources of truth for the same thing, since a future change might accidentally cause the two to differ.