diff --git a/dashboard/src/assets/constants/copyTextConstants.js b/dashboard/src/assets/constants/copyTextConstants.js new file mode 100644 index 0000000000..7d6dd97419 --- /dev/null +++ b/dashboard/src/assets/constants/copyTextConstants.js @@ -0,0 +1 @@ +export const SHOW_COPIED_TEXT_MS = 4000; diff --git a/dashboard/src/modules/components/ProfileComponent/ClipboardCopy.jsx b/dashboard/src/modules/components/ProfileComponent/ClipboardCopy.jsx new file mode 100644 index 0000000000..6db6d68a7e --- /dev/null +++ b/dashboard/src/modules/components/ProfileComponent/ClipboardCopy.jsx @@ -0,0 +1,52 @@ +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); + + /* Funcion has to be rewritten by removing document.execCommand() on upgrading to HTTPS */ + const copyTextToClipboard = async (text) => + "clipboard" in navigator + ? await navigator.clipboard.writeText(text) + : 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 ( +
+
{copyText}
+ + + +
+ ); +}; + +export default ClipboardCopy; diff --git a/dashboard/src/modules/components/ProfileComponent/KeyListTable.jsx b/dashboard/src/modules/components/ProfileComponent/KeyListTable.jsx index 587ed5fcfa..b592e94d8a 100644 --- a/dashboard/src/modules/components/ProfileComponent/KeyListTable.jsx +++ b/dashboard/src/modules/components/ProfileComponent/KeyListTable.jsx @@ -1,4 +1,3 @@ -import { Button, ClipboardCopy } from "@patternfly/react-core"; import { TableComposable, Tbody, @@ -9,6 +8,8 @@ import { } from "@patternfly/react-table"; import { useDispatch, useSelector } from "react-redux"; +import { Button } from "@patternfly/react-core"; +import ClipboardCopy from "./ClipboardCopy"; import React from "react"; import { TrashIcon } from "@patternfly/react-icons"; import { deleteAPIKey } from "actions/keyManagementActions"; @@ -22,7 +23,6 @@ const KeyListTable = () => { created: "Created Date & Time", key: "API key", }; - return ( @@ -40,14 +40,8 @@ const KeyListTable = () => { {formatDateTime(item.created)} - - - {item.key} - + + diff --git a/dashboard/src/modules/components/ProfileComponent/index.less b/dashboard/src/modules/components/ProfileComponent/index.less index 3d6121eace..8de9cd371a 100644 --- a/dashboard/src/modules/components/ProfileComponent/index.less +++ b/dashboard/src/modules/components/ProfileComponent/index.less @@ -82,6 +82,13 @@ display: block; text-overflow: ellipsis; } + .key-cell-wrapper { + display: flex; + .copy-icon { + padding-top: 0; + } + } + .pf-c-clipboard-copy__group { input { background-color: transparent;