Skip to content

Commit

Permalink
feat(Datatable): Download sandboxes buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Loxeris committed Aug 29, 2024
1 parent aea2f06 commit 95c0065
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { JobHistoryDialog } from "./JobHistoryDialog";
import {
deleteJobs,
getJobHistory,
getSandbox,
getSandboxUrl,
killJobs,
refreshJobs,
rescheduleJobs,
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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"),
},
];

/**
Expand Down

0 comments on commit 95c0065

Please sign in to comment.