diff --git a/packages/trace-viewer/src/ui/copyToClipboard.tsx b/packages/trace-viewer/src/ui/copyToClipboard.tsx index 1eb989d08e..8f3f8cb448 100644 --- a/packages/trace-viewer/src/ui/copyToClipboard.tsx +++ b/packages/trace-viewer/src/ui/copyToClipboard.tsx @@ -46,11 +46,16 @@ export const CopyToClipboard: React.FunctionComponent<{ export const CopyToClipboardTextButton: React.FunctionComponent<{ value: string | (() => Promise), description: string, -}> = ({ value, description }) => { + copiedDescription?: React.ReactNode, + style?: React.CSSProperties, +}> = ({ value, description, copiedDescription = description, style }) => { + const [copied, setCopied] = React.useState(false); const handleCopy = React.useCallback(async () => { const valueToCopy = typeof value === 'function' ? await value() : value; await navigator.clipboard.writeText(valueToCopy); + setCopied(true); + setTimeout(() => setCopied(false), 3000); }, [value]); - return {description}; + return {copied ? copiedDescription : description}; }; diff --git a/packages/trace-viewer/src/ui/errorsTab.tsx b/packages/trace-viewer/src/ui/errorsTab.tsx index 5adca212ca..f0c52742c1 100644 --- a/packages/trace-viewer/src/ui/errorsTab.tsx +++ b/packages/trace-viewer/src/ui/errorsTab.tsx @@ -21,7 +21,7 @@ import { PlaceholderPanel } from './placeholderPanel'; import { renderAction } from './actionList'; import type { Language } from '@isomorphic/locatorGenerators'; import type { StackFrame } from '@protocol/channels'; -import { CopyToClipboard } from './copyToClipboard'; +import { CopyToClipboardTextButton } from './copyToClipboard'; import { attachmentURL } from './attachmentsTab'; import { fixTestPrompt } from '@web/components/prompts'; @@ -46,7 +46,7 @@ const PromptButton: React.FC<{ const prompt = React.useMemo(() => fixTestPrompt(error, undefined, pageSnapshot), [error, pageSnapshot]); - return ; + return Copied } style={{ width: '90px', justifyContent: 'center' }} />; }; export type ErrorDescription = { @@ -100,7 +100,7 @@ export const ErrorsTab: React.FunctionComponent<{ {location &&
@ revealInSource(error)}>{location}
} - +