-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dashboard API key button
- Loading branch information
Showing
4 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SHOW_COPIED_TEXT_MS = 4000; |
54 changes: 54 additions & 0 deletions
54
dashboard/src/modules/components/ProfileComponent/ClipboardCopy.jsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Button, Tooltip } from "@patternfly/react-core"; | ||
import React, { useState } from "react"; | ||
|
||
import { CopyIcon } from "@patternfly/react-icons"; | ||
import { SHOW_COPIED_TEXT_MS } from "assets/constants/copyTextConstants"; | ||
|
||
const ClipboardCopy = ({ copyText }) => { | ||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
const copyTextToClipboard = async (text) => { | ||
if ("clipboard" in navigator) { | ||
return await navigator.clipboard.writeText(text); | ||
} else { | ||
return document.execCommand("copy", true, text); | ||
} | ||
}; | ||
|
||
// onClick handler function for the copy button | ||
const handleCopyClick = () => { | ||
// Asynchronously call copyTextToClipboard | ||
copyTextToClipboard(copyText) | ||
.then(() => { | ||
// If successful, update the isCopied state value | ||
setIsCopied(true); | ||
setTimeout(() => { | ||
setIsCopied(false); | ||
}, SHOW_COPIED_TEXT_MS); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="key-cell-wrapper"> | ||
<div className="key-cell">{copyText}</div> | ||
<Tooltip | ||
aria="none" | ||
aria-live="polite" | ||
content={isCopied ? "Copied" : "Copy to clipboard"} | ||
> | ||
<Button | ||
variant="plain" | ||
className="copy-icon" | ||
onClick={() => handleCopyClick(copyText)} | ||
> | ||
<CopyIcon /> | ||
</Button> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClipboardCopy; |
This file contains 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 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