diff --git a/packages/playwright-core/src/web/traceViewer/ui/workbench.css b/packages/playwright-core/src/web/traceViewer/ui/workbench.css index d5bf2713fa..ba898de856 100644 --- a/packages/playwright-core/src/web/traceViewer/ui/workbench.css +++ b/packages/playwright-core/src/web/traceViewer/ui/workbench.css @@ -20,9 +20,21 @@ justify-content: center; box-shadow: var(--box-shadow); flex: auto; + flex-direction: column; font-size: 24px; color: #666; font-weight: bold; + background-color: #fffb; + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 100; +} + +.drop-target input { + margin-top: 50px; } .progress { @@ -78,7 +90,7 @@ flex: auto; } -tab-strip { +.tab-strip { background-color: var(--light-background); } diff --git a/packages/playwright-core/src/web/traceViewer/ui/workbench.tsx b/packages/playwright-core/src/web/traceViewer/ui/workbench.tsx index e15c732bb1..552cf8ace3 100644 --- a/packages/playwright-core/src/web/traceViewer/ui/workbench.tsx +++ b/packages/playwright-core/src/web/traceViewer/ui/workbench.tsx @@ -37,10 +37,10 @@ export const Workbench: React.FunctionComponent<{ const [highlightedAction, setHighlightedAction] = React.useState(); const [selectedTab, setSelectedTab] = React.useState('logs'); const [progress, setProgress] = React.useState<{ done: number, total: number }>({ done: 0, total: 0 }); + const [dragOver, setDragOver] = React.useState(false); - const handleDropEvent = (event: any) => { - event.preventDefault(); - const blobTraceURL = URL.createObjectURL(event.dataTransfer.files[0]); + const processTraceFile = (file: File) => { + const blobTraceURL = URL.createObjectURL(file); const url = new URL(window.location.href); url.searchParams.set('trace', blobTraceURL); const href = url.toString(); @@ -48,6 +48,19 @@ export const Workbench: React.FunctionComponent<{ // so set it here. window.history.pushState({}, '', href); setTraceURL(blobTraceURL); + setDragOver(false); + }; + + const handleDropEvent = (event: React.DragEvent) => { + event.preventDefault(); + processTraceFile(event.dataTransfer.files[0]); + }; + + const handleFileInputChange = (event: React.ChangeEvent) => { + event.preventDefault(); + if (!event.target.files) + return; + processTraceFile(event.target.files[0]); }; React.useEffect(() => { @@ -73,23 +86,6 @@ export const Workbench: React.FunctionComponent<{ const defaultSnapshotSize = contextEntry.options.viewport || { width: 1280, height: 720 }; const boundaries = { minimum: contextEntry.startTime, maximum: contextEntry.endTime }; - if (!traceURL || progress.total) { - return
-
-
🎭
-
Playwright
-
-
- {!!progress.total &&
-
-
} - {!progress.total &&
{ event.preventDefault(); }} - onDrop={event => handleDropEvent(event)}> - Drop Playwright Trace here -
} -
; - } // Leave some nice free space on the right hand side. boundaries.maximum += (boundaries.maximum - boundaries.minimum) / 20; @@ -106,9 +102,7 @@ export const Workbench: React.FunctionComponent<{ if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') tabs.push({ id: 'source', title: 'Source', count: 0, render: () => }); - return
{ event.preventDefault(); }} - onDrop={event => handleDropEvent(event)}> + return
{ event.preventDefault(); setDragOver(true); }}>
🎭
Playwright
@@ -140,6 +134,18 @@ export const Workbench: React.FunctionComponent<{ setSelectedTab={setSelectedTab} /> + {!!progress.total &&
+
+
} + {!dragOver && !traceURL &&
+
Drop to upload a Playwright Trace
+ +
} + {dragOver &&
{ setDragOver(false); }} + onDrop={event => handleDropEvent(event)}> + Release to analyse the Playwright Trace +
}
; };