From 95c0065fd731a4f636a46c3009726c65901a4d35 Mon Sep 17 00:00:00 2001 From: Loxeris <30194187+Loxeris@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:03:27 +0200 Subject: [PATCH] feat(Datatable): Download sandboxes buttons --- .../components/JobMonitor/JobDataService.ts | 25 ++++++++++++ .../components/JobMonitor/JobDataTable.tsx | 38 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/packages/diracx-web-components/components/JobMonitor/JobDataService.ts b/packages/diracx-web-components/components/JobMonitor/JobDataService.ts index 8ba967da..1a3baecb 100644 --- a/packages/diracx-web-components/components/JobMonitor/JobDataService.ts +++ b/packages/diracx-web-components/components/JobMonitor/JobDataService.ts @@ -99,3 +99,28 @@ export function getJobHistory( const historyUrl = `/api/jobs/${jobId}/status/history`; return fetcher([historyUrl, token]); } + +export function getSandboxes( + jobId: number, + token: any, +): Promise<{ headers: Headers; data: any }> { + const url = `/api/jobs/${jobId}/sandbox`; + return fetcher([url, token]); +} + +export function getSandbox( + jobId: number, + sbType: "input" | "output", + token: any, +): Promise<{ headers: Headers; data: any }> { + const url = `/api/jobs/${jobId}/sandbox/${sbType}`; + return fetcher([url, token]); +} + +export function getSandboxUrl( + pfn: string, + token: any, +): Promise<{ headers: Headers; data: any }> { + const url = `/api/jobs/sandbox?pfn=${pfn}`; + return fetcher([url, token]); +} diff --git a/packages/diracx-web-components/components/JobMonitor/JobDataTable.tsx b/packages/diracx-web-components/components/JobMonitor/JobDataTable.tsx index 466a8e81..2173fb6a 100644 --- a/packages/diracx-web-components/components/JobMonitor/JobDataTable.tsx +++ b/packages/diracx-web-components/components/JobMonitor/JobDataTable.tsx @@ -34,6 +34,8 @@ import { JobHistoryDialog } from "./JobHistoryDialog"; import { deleteJobs, getJobHistory, + getSandbox, + getSandboxUrl, killJobs, refreshJobs, rescheduleJobs, @@ -271,6 +273,34 @@ export function JobDataTable() { setIsHistoryDialogOpen(false); }; + const handleSandboxDl = async ( + jobId: number | null, + sbType: "input" | "output", + ) => { + if (!jobId) return; + setBackdropOpen(true); + try { + const { data } = await getSandbox(jobId, sbType, accessToken); + if (!data) throw new Error("No sandbox found"); + const pfn = data[0]; + setBackdropOpen(false); + console.log("SandBox pfn:", pfn); + if (pfn) { + const { data } = await getSandboxUrl(pfn, accessToken); + if (data?.url) window.open(data.url); + else throw new Error("Could not fetch the sandbox url"); + } else throw new Error("No sandbox found"); + } catch (error: any) { + setSnackbarInfo({ + open: true, + message: "Fetching Sandbox failed: " + error.message, + severity: "error", + }); + } finally { + setBackdropOpen(false); + } + }; + /** * The toolbar components for the data grid */ @@ -299,6 +329,14 @@ export function JobDataTable() { */ const menuItems: MenuItem[] = [ { label: "Get history", onClick: (id: number | null) => handleHistory(id) }, + { + label: "Download input Sandbox", + onClick: (id: number | null) => handleSandboxDl(id, "input"), + }, + { + label: "Download output Sandbox", + onClick: (id: number | null) => handleSandboxDl(id, "output"), + }, ]; /**