added export tests feature
This commit is contained in:
@@ -39,6 +39,20 @@ export const api = {
|
||||
return request('GET', `/schedule/week?${params.toString()}`)
|
||||
},
|
||||
getRerunTests: () => request('GET', '/tests/rerun'),
|
||||
|
||||
exportWindow: async (windowId) => {
|
||||
const params = new URLSearchParams({ window_id: windowId })
|
||||
const res = await fetch(`${BASE}/schedule/export?${params}`)
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ detail: res.statusText }))
|
||||
throw new Error(err.detail || `HTTP ${res.status}`)
|
||||
}
|
||||
const blob = await res.blob()
|
||||
const disposition = res.headers.get('Content-Disposition') ?? ''
|
||||
const match = disposition.match(/filename="([^"]+)"/)
|
||||
const filename = match ? match[1] : 'tests.zip'
|
||||
return { blob, filename }
|
||||
},
|
||||
}
|
||||
|
||||
// Transform the flat items array from GET /api/schedule/week into the
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { getDeviceAccentClass } from './TestCard'
|
||||
import { api } from '../api'
|
||||
|
||||
const CONFIG_MAP_IMAGE_MODULES = import.meta.glob('../assets/TC*_map/*.png', {
|
||||
eager: true,
|
||||
@@ -183,6 +184,8 @@ function TestRow({ test }) {
|
||||
|
||||
export default function TestWindowDetailsPanel({ isOpen, windowDetails, onClose }) {
|
||||
const [showConfigMap, setShowConfigMap] = useState(false)
|
||||
const [isExporting, setIsExporting] = useState(false)
|
||||
const [exportError, setExportError] = useState(null)
|
||||
const windowTests = useMemo(
|
||||
() => (Array.isArray(windowDetails?.tests) ? windowDetails.tests : []),
|
||||
[windowDetails],
|
||||
@@ -196,6 +199,10 @@ export default function TestWindowDetailsPanel({ isOpen, windowDetails, onClose
|
||||
const hasConfigMapImages = configMapImages.length > 0
|
||||
const showMapPane = showConfigMap && hasConfigMapImages
|
||||
|
||||
useEffect(() => {
|
||||
setExportError(null)
|
||||
}, [windowDetails])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return undefined
|
||||
|
||||
@@ -209,6 +216,25 @@ export default function TestWindowDetailsPanel({ isOpen, windowDetails, onClose
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [isOpen, onClose])
|
||||
|
||||
async function handleExport() {
|
||||
if (!windowDetails?.window_id) return
|
||||
setIsExporting(true)
|
||||
setExportError(null)
|
||||
try {
|
||||
const { blob, filename } = await api.exportWindow(windowDetails.window_id)
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = filename
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
} catch (err) {
|
||||
setExportError(err.message || 'Export failed')
|
||||
} finally {
|
||||
setIsExporting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`absolute inset-0 z-40 transition-opacity duration-300 ${
|
||||
@@ -238,18 +264,44 @@ export default function TestWindowDetailsPanel({ isOpen, windowDetails, onClose
|
||||
{windowDetails ? formatWindowHeader(windowDetails) : 'Window details'}
|
||||
</h2>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="rounded-full border border-gray-700 p-2 text-gray-400 hover:border-gray-500 hover:text-white transition-colors"
|
||||
aria-label="Close panel"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExport}
|
||||
disabled={isExporting || !windowDetails?.tests?.length}
|
||||
className="inline-flex items-center gap-1.5 rounded-full border border-gray-700 px-3 py-2 text-xs font-semibold text-gray-300 hover:border-gray-500 hover:text-white transition-colors disabled:cursor-not-allowed disabled:opacity-50"
|
||||
aria-label="Export .ini files for this window"
|
||||
>
|
||||
{isExporting ? (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-3.5 w-3.5 animate-spin" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 3v3m0 12v3M4.22 4.22l2.12 2.12m11.32 11.32 2.12 2.12M3 12h3m12 0h3M4.22 19.78l2.12-2.12M17.66 6.34l2.12-2.12" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2M7 10l5 5 5-5M12 15V3" />
|
||||
</svg>
|
||||
)}
|
||||
{isExporting ? 'Exporting…' : 'Export Tests'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="rounded-full border border-gray-700 p-2 text-gray-400 hover:border-gray-500 hover:text-white transition-colors"
|
||||
aria-label="Close panel"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{exportError && (
|
||||
<div className="border-b border-red-900/50 bg-red-950/40 px-5 py-2 text-xs text-red-300">
|
||||
{exportError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{windowDetails && (
|
||||
<div className="flex-1 min-h-0 overflow-y-auto">
|
||||
<div className="flex min-h-full min-w-0">
|
||||
|
||||
Reference in New Issue
Block a user