From 91d3ed632ae7cacd4b9e046e67fbc2484e0e331c Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Thu, 18 Sep 2025 12:17:50 -0700 Subject: [PATCH] improvement: reduce code duplication for copy value --- .../SecretListView/SecretVersionItem.tsx | 61 ++++++++----------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretVersionItem.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretVersionItem.tsx index 2d3e123a0..1e24c83aa 100644 --- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretVersionItem.tsx +++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretVersionItem.tsx @@ -112,6 +112,29 @@ export const SecretVersionItem = ({ } }; + const handleCopyValue = async ( + e: React.MouseEvent | React.KeyboardEvent + ) => { + const value = await handleGetSecretValue(); + navigator.clipboard.writeText(value || ""); + const target = e.currentTarget; + target.style.borderBottom = "1px dashed"; + target.style.paddingBottom = "-1px"; + + // Create and insert popup + const popup = document.createElement("div"); + popup.className = + "w-16 flex justify-center absolute top-6 left-0 text-xs text-primary-100 bg-mineshaft-800 px-1 py-0.5 rounded-md border border-primary-500/50"; + popup.textContent = "Copied!"; + target.parentElement?.appendChild(popup); + + // Remove popup and border after delay + setTimeout(() => { + popup.remove(); + target.style.borderBottom = "none"; + }, 3000); + }; + return (
@@ -158,47 +181,13 @@ export const SecretVersionItem = ({ onClick={async (e) => { if (secretValueHidden) return; - const value = await handleGetSecretValue(); - navigator.clipboard.writeText(value || ""); - const target = e.currentTarget; - target.style.borderBottom = "1px dashed"; - target.style.paddingBottom = "-1px"; - - // Create and insert popup - const popup = document.createElement("div"); - popup.className = - "w-16 flex justify-center absolute top-6 left-0 text-xs text-primary-100 bg-mineshaft-800 px-1 py-0.5 rounded-md border border-primary-500/50"; - popup.textContent = "Copied!"; - target.parentElement?.appendChild(popup); - - // Remove popup and border after delay - setTimeout(() => { - popup.remove(); - target.style.borderBottom = "none"; - }, 3000); + await handleCopyValue(e); }} onKeyDown={async (e) => { if (secretValueHidden) return; if (e.key === "Enter" || e.key === " ") { - const value = await handleGetSecretValue(); - navigator.clipboard.writeText(value || ""); - const target = e.currentTarget; - target.style.borderBottom = "1px dashed"; - target.style.paddingBottom = "-1px"; - - // Create and insert popup - const popup = document.createElement("div"); - popup.className = - "w-16 flex justify-center absolute top-6 left-0 text-xs text-primary-100 bg-mineshaft-800 px-1 py-0.5 rounded-md border border-primary-500/50"; - popup.textContent = "Copied!"; - target.parentElement?.appendChild(popup); - - // Remove popup and border after delay - setTimeout(() => { - popup.remove(); - target.style.borderBottom = "none"; - }, 3000); + await handleCopyValue(e); } }} >