feat: improve machines inventory exports

This commit is contained in:
codex-bot 2025-10-30 16:09:06 -03:00
parent d92c817e7b
commit 38b46f32ce
5 changed files with 858 additions and 222 deletions

View file

@ -2004,7 +2004,7 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
}
return JSON.stringify(payload, null, 2)
}, [machine, metrics, metadata])
const handleDownloadInventory = useCallback(() => {
const handleDownloadInventoryJson = useCallback(() => {
if (!machine) return
const safeHostname = machine.hostname.replace(/[^a-z0-9_-]/gi, "-").replace(/-{2,}/g, "-").toLowerCase()
const fileName = `${safeHostname || "machine"}_${machine.id}.json`
@ -3915,7 +3915,14 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
) : null}
<Dialog open={openDialog} onOpenChange={setOpenDialog}>
<div className="flex justify-end">
<div className="flex flex-wrap items-center justify-end gap-2">
{machine ? (
<Button size="sm" variant="outline" asChild className="inline-flex items-center gap-2">
<a href={`/api/admin/machines/${machine.id}/inventory.xlsx`} download>
<Download className="size-4" /> Exportar planilha
</a>
</Button>
) : null}
<DialogTrigger asChild>
<Button size="sm" variant="outline" onClick={() => setOpenDialog(true)}>Inventário completo</Button>
</DialogTrigger>
@ -3932,15 +3939,24 @@ export function MachineDetails({ machine }: MachineDetailsProps) {
onChange={(e) => setDialogQuery(e.target.value)}
className="sm:flex-1"
/>
<Button
type="button"
variant="outline"
size="sm"
onClick={handleDownloadInventory}
className="inline-flex items-center gap-2"
>
<Download className="size-4" /> Baixar JSON
</Button>
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3">
<Button
type="button"
variant="outline"
size="sm"
onClick={handleDownloadInventoryJson}
className="inline-flex items-center gap-2"
>
<Download className="size-4" /> Baixar JSON
</Button>
{machine ? (
<Button type="button" variant="outline" size="sm" asChild className="inline-flex items-center gap-2">
<a href={`/api/admin/machines/${machine.id}/inventory.xlsx`} download>
<Download className="size-4" /> Baixar planilha
</a>
</Button>
) : null}
</div>
</div>
<div className="max-h-[60vh] overflow-auto rounded-md border border-slate-200 bg-slate-50/60 p-3 text-xs">
<pre className="whitespace-pre-wrap break-words text-muted-foreground" dangerouslySetInnerHTML={{ __html: filteredJsonHtml