@@ -31,6 +31,8 @@ import { JobHistoryDialog } from "./JobHistoryDialog";
3131import {
3232 deleteJobs ,
3333 getJobHistory ,
34+ getJobSandbox ,
35+ getJobSandboxUrl ,
3436 killJobs ,
3537 rescheduleJobs ,
3638 useJobs ,
@@ -182,7 +184,6 @@ export function JobDataTable({
182184 diracxUrl ,
183185 rowSelection ,
184186 clearSelected ,
185- setSearchBody ,
186187 mutateJobs ,
187188 ] ) ;
188189
@@ -251,7 +252,6 @@ export function JobDataTable({
251252 diracxUrl ,
252253 rowSelection ,
253254 clearSelected ,
254- setSearchBody ,
255255 mutateJobs ,
256256 ] ) ;
257257
@@ -311,29 +311,19 @@ export function JobDataTable({
311311 } finally {
312312 setBackdropOpen ( false ) ;
313313 }
314- } , [
315- accessToken ,
316- diracxUrl ,
317- rowSelection ,
318- clearSelected ,
319- setSearchBody ,
320- mutateJobs ,
321- ] ) ;
314+ } , [ accessToken , diracxUrl , rowSelection , clearSelected , mutateJobs ] ) ;
322315
323316 /**
324317 * Handle the history of the selected job
325318 */
326319 const handleHistory = useCallback (
327- async ( selectedId : number | null ) => {
320+ async ( selectedId : string | null ) => {
328321 if ( ! selectedId ) return ;
322+ const jobId = Number ( selectedId ) ;
329323 setBackdropOpen ( true ) ;
330- setSelectedJobId ( selectedId ) ;
324+ setSelectedJobId ( jobId ) ;
331325 try {
332- const { data } = await getJobHistory (
333- diracxUrl ,
334- selectedId ,
335- accessToken ,
336- ) ;
326+ const { data } = await getJobHistory ( diracxUrl , jobId , accessToken ) ;
337327 setBackdropOpen ( false ) ;
338328 // Show the history
339329 setJobHistoryData ( data ) ;
@@ -360,6 +350,61 @@ export function JobDataTable({
360350 setIsHistoryDialogOpen ( false ) ;
361351 } ;
362352
353+ const handleSandboxDownload = useCallback (
354+ async ( selectedId : string | null , sbType : "input" | "output" ) => {
355+ if ( ! selectedId ) return ;
356+ const jobId = Number ( selectedId ) ;
357+ setBackdropOpen ( true ) ;
358+ try {
359+ const { data : sandboxData } = await getJobSandbox (
360+ diracxUrl ,
361+ jobId ,
362+ sbType ,
363+ accessToken ,
364+ ) ;
365+ if ( sandboxData . length === 0 )
366+ throw new Error ( `No ${ sbType } sandbox found` ) ;
367+ const pfn = sandboxData [ 0 ] ;
368+ if ( pfn ) {
369+ const { data : urlData } = await getJobSandboxUrl (
370+ diracxUrl ,
371+ pfn ,
372+ accessToken ,
373+ ) ;
374+ if ( urlData ?. url ) {
375+ const link = document . createElement ( "a" ) ;
376+ link . href = urlData . url ;
377+ link . download = `${ sbType } -sandbox-${ jobId } .tar.gz` ;
378+ document . body . appendChild ( link ) ;
379+ link . click ( ) ;
380+ document . body . removeChild ( link ) ;
381+ setSnackbarInfo ( {
382+ open : true ,
383+ message : `Downloading ${ sbType } sandbox of ${ jobId } ...` ,
384+ severity : "info" ,
385+ } ) ;
386+ } else
387+ throw new Error (
388+ "Could not retrieve a download URL for the sandbox" ,
389+ ) ;
390+ } else throw new Error ( `No ${ sbType } sandbox found` ) ;
391+ } catch ( error : unknown ) {
392+ let errorMessage = "An unknown error occurred" ;
393+ if ( error instanceof Error ) {
394+ errorMessage = error . message ;
395+ }
396+ setSnackbarInfo ( {
397+ open : true ,
398+ message : `Fetching sandbox of ${ jobId } failed: ` + errorMessage ,
399+ severity : "error" ,
400+ } ) ;
401+ } finally {
402+ setBackdropOpen ( false ) ;
403+ }
404+ } ,
405+ [ accessToken , diracxUrl ] ,
406+ ) ;
407+
363408 /**
364409 * The toolbar components for the data grid
365410 */
@@ -405,10 +450,21 @@ export function JobDataTable({
405450 ( ) => [
406451 {
407452 label : "Get history" ,
408- onClick : ( id : string | null ) => handleHistory ( Number ( id ) ) ,
453+ onClick : ( id : string | null ) => handleHistory ( id ) ,
454+ dataTestId : "get-history-button" ,
455+ } ,
456+ {
457+ label : "Download input sandbox" ,
458+ onClick : ( id : string | null ) => handleSandboxDownload ( id , "input" ) ,
459+ dataTestId : "download-input-sandbox-button" ,
460+ } ,
461+ {
462+ label : "Download output sandbox" ,
463+ onClick : ( id : string | null ) => handleSandboxDownload ( id , "output" ) ,
464+ dataTestId : "download-output-sandbox-button" ,
409465 } ,
410466 ] ,
411- [ handleHistory ] ,
467+ [ handleHistory , handleSandboxDownload ] ,
412468 ) ;
413469
414470 /**
0 commit comments