Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Datatable): Download sandboxes buttons #220

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading