({ endpoint, filename, label = "Export" }: ExportButtonProps)
| 30 | } |
| 31 | |
| 32 | export function ExportButton({ endpoint, filename, label = "Export" }: ExportButtonProps) { |
| 33 | const [isExporting, setIsExporting] = useState(false); |
| 34 | |
| 35 | async function handleExport(format: "csv" | "json") { |
| 36 | setIsExporting(true); |
| 37 | try { |
| 38 | await triggerDownload(endpoint, format, filename); |
| 39 | } catch (err) { |
| 40 | console.error("Export failed:", err); |
| 41 | } finally { |
| 42 | setIsExporting(false); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return ( |
| 47 | <DropdownMenu> |
| 48 | <DropdownMenuTrigger asChild> |
| 49 | <Button variant="outline" size="sm" className="gap-1.5" disabled={isExporting}> |
| 50 | {isExporting ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : <Download className="w-3.5 h-3.5" />} |
| 51 | {label} |
| 52 | </Button> |
| 53 | </DropdownMenuTrigger> |
| 54 | <DropdownMenuContent align="end"> |
| 55 | <DropdownMenuItem |
| 56 | className="cursor-pointer gap-2" |
| 57 | onClick={() => handleExport("csv")} |
| 58 | > |
| 59 | <FileSpreadsheet className="w-4 h-4" /> |
| 60 | Export CSV |
| 61 | </DropdownMenuItem> |
| 62 | <DropdownMenuItem |
| 63 | className="cursor-pointer gap-2" |
| 64 | onClick={() => handleExport("json")} |
| 65 | > |
| 66 | <FileJson className="w-4 h-4" /> |
| 67 | Export JSON |
| 68 | </DropdownMenuItem> |
| 69 | </DropdownMenuContent> |
| 70 | </DropdownMenu> |
| 71 | ); |
| 72 | } |
nothing calls this directly
no test coverage detected