@@ -388,48 +388,72 @@ export default function ResultsView({
388388 [ updateColumnVisibility ] ,
389389 ) ;
390390
391- const handleSaveEvalName = async ( newName : string ) => {
392- invariant ( config , 'Config must be loaded before updating its description' ) ;
393- const newConfig = { ...config , description : newName } ;
394-
395- const response = await callApi ( `/eval/${ evalId } ` , {
396- method : 'PATCH' ,
397- headers : {
398- 'Content-Type' : 'application/json' ,
399- } ,
400- body : JSON . stringify ( { config : newConfig } ) ,
401- } ) ;
391+ const handleSaveEvalName = React . useCallback (
392+ async ( newName : string ) => {
393+ try {
394+ invariant ( config , 'Config must be loaded before updating its description' ) ;
395+ const newConfig = { ...config , description : newName } ;
402396
403- if ( ! response . ok ) {
404- throw new Error ( 'Failed to update eval name' ) ;
405- }
397+ const response = await callApi ( `/eval/${ evalId } ` , {
398+ method : 'PATCH' ,
399+ headers : {
400+ 'Content-Type' : 'application/json' ,
401+ } ,
402+ body : JSON . stringify ( { config : newConfig } ) ,
403+ } ) ;
406404
407- setConfig ( newConfig ) ;
408- } ;
405+ if ( ! response . ok ) {
406+ throw new Error ( 'Failed to update eval name' ) ;
407+ }
408+
409+ setConfig ( newConfig ) ;
410+ } catch ( error ) {
411+ console . error ( 'Failed to update eval name:' , error ) ;
412+ showToast (
413+ `Failed to update eval name: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
414+ 'error' ,
415+ ) ;
416+ throw error ;
417+ }
418+ } ,
419+ [ config , evalId , setConfig , showToast ] ,
420+ ) ;
409421
410- const handleCopyEval = async ( description : string ) => {
411- invariant ( evalId , 'Eval ID must be set before copying' ) ;
422+ const handleCopyEval = React . useCallback (
423+ async ( description : string ) => {
424+ try {
425+ invariant ( evalId , 'Eval ID must be set before copying' ) ;
412426
413- const response = await callApi ( `/eval/${ evalId } /copy` , {
414- method : 'POST' ,
415- headers : {
416- 'Content-Type' : 'application/json' ,
417- } ,
418- body : JSON . stringify ( { description } ) ,
419- } ) ;
427+ const response = await callApi ( `/eval/${ evalId } /copy` , {
428+ method : 'POST' ,
429+ headers : {
430+ 'Content-Type' : 'application/json' ,
431+ } ,
432+ body : JSON . stringify ( { description } ) ,
433+ } ) ;
420434
421- if ( ! response . ok ) {
422- throw new Error ( 'Failed to copy evaluation' ) ;
423- }
435+ if ( ! response . ok ) {
436+ throw new Error ( 'Failed to copy evaluation' ) ;
437+ }
424438
425- const { id : newEvalId , distinctTestCount } = await response . json ( ) ;
439+ const { id : newEvalId , distinctTestCount } = await response . json ( ) ;
426440
427- // Open in new tab (Google Docs pattern)
428- window . open ( `/eval/${ newEvalId } ` , '_blank' ) ;
441+ // Open in new tab (Google Docs pattern)
442+ window . open ( `/eval/${ newEvalId } ` , '_blank' ) ;
429443
430- // Show success toast
431- showToast ( `Copied ${ distinctTestCount . toLocaleString ( ) } results successfully` , 'success' ) ;
432- } ;
444+ // Show success toast
445+ showToast ( `Copied ${ distinctTestCount . toLocaleString ( ) } results successfully` , 'success' ) ;
446+ } catch ( error ) {
447+ console . error ( 'Failed to copy evaluation:' , error ) ;
448+ showToast (
449+ `Failed to copy evaluation: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
450+ 'error' ,
451+ ) ;
452+ throw error ;
453+ }
454+ } ,
455+ [ evalId , showToast ] ,
456+ ) ;
433457
434458 const handleDeleteEvalClick = async ( ) => {
435459 if ( window . confirm ( 'Are you sure you want to delete this evaluation?' ) ) {
0 commit comments