Unverified Commit 8d4175c9 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Show clipboard failures in the Request Insights panel

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent cfac8b25
......@@ -287,6 +287,14 @@
background: var(--color-gray-1000);
}
.request-insights-copy-error {
flex-shrink: 0;
padding: 6px 10px;
border-bottom: 1px solid var(--color-gray-400);
color: var(--color-red-900);
font-size: var(--size-12);
}
.request-insights-context-positioner {
z-index: var(--top-z-index);
}
......
import {
createContext,
useContext,
useCallback,
useEffect,
useId,
......@@ -68,6 +70,8 @@ import {
} from './request-insights-history'
import './request-insights-panel.css'
const CopyErrorContext = createContext<(error: string | null) => void>(() => {})
const TRACE_TICK_COUNT = 5
const REQUEST_ROW_HEIGHT = 52
const REQUEST_ROW_OVERSCAN = 8
......@@ -76,6 +80,7 @@ const REQUEST_SCROLLBAR_MIN_THUMB_HEIGHT = 24
export function RequestInsightsPanel() {
const { dispatch, state, shadowRoot } = useDevOverlayContext()
const [copyError, setCopyError] = useState<string | null>(null)
const [activeFilters, setActiveFilters] = useState<
readonly RequestInsightFilter[]
>([])
......@@ -188,7 +193,7 @@ export function RequestInsightsPanel() {
)
}
return (
const content = (
<div className="request-insights-panel">
<div className="request-insights-list">
<div className="request-insights-list-toolbar">
......@@ -297,6 +302,11 @@ export function RequestInsightsPanel() {
</div>
</div>
</div>
{copyError ? (
<div className="request-insights-copy-error" role="alert">
{copyError}
</div>
) : null}
{activeFilters.length > 0 ? (
<div className="request-insights-filter-status">
<span>
......@@ -374,6 +384,8 @@ export function RequestInsightsPanel() {
) : null}
</div>
)
return <CopyErrorContext value={setCopyError}>{content}</CopyErrorContext>
}
function VirtualRequestList({
......@@ -855,10 +867,25 @@ function RequestContextMenuItem({
getValue: () => string
label: string
}) {
const setCopyError = useContext(CopyErrorContext)
return (
<ContextMenu.Item
className="request-insights-context-item"
onClick={() => copyToClipboard(getValue())}
onClick={async () => {
setCopyError(null)
if (!navigator.clipboard) {
setCopyError('Copy is unavailable. Use HTTPS or localhost.')
return
}
try {
await navigator.clipboard.writeText(getValue())
} catch {
setCopyError(
'Could not copy. Check browser permissions and try again.'
)
}
}}
>
{label}
</ContextMenu.Item>
......@@ -878,17 +905,6 @@ function RequestInsightsContextMenuBackdrop({
)
}
function copyToClipboard(value: string) {
if (!navigator.clipboard) {
console.warn('Copy to clipboard is not supported in this browser')
return
}
void navigator.clipboard.writeText(value).catch((error) => {
console.warn(error)
})
}
function NestedArrowIcon() {
return (
<svg
......
......@@ -1430,6 +1430,45 @@ describe('request insights', () => {
expect(copied).toContain(selectedRequestId)
expect(copied).toContain(spanId)
})
for (const failure of ['unavailable', 'rejected']) {
await browser.eval((mode: string) => {
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value:
mode === 'unavailable'
? undefined
: {
writeText: async () => {
throw new DOMException(
'Permission denied',
'NotAllowedError'
)
},
},
})
}, failure)
await firstSpan.click({ button: 'right' })
await browser
.locator('nextjs-portal .request-insights-context-item')
.filter({ hasText: 'Copy span ID' })
.click()
await retry(async () => {
const message = await browser
.elementByCss('.request-insights-copy-error[role="alert"]')
.text()
expect(message).toBe(
failure === 'unavailable'
? 'Copy is unavailable. Use HTTPS or localhost.'
: 'Could not copy. Check browser permissions and try again.'
)
expect(
await browser
.locator('nextjs-portal .request-insights-context-menu')
.count()
).toBe(0)
})
}
})
it('shows trace tooltips on hover and clears the preview outside the trace', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment