1- import { FC , useMemo , useState } from 'react'
1+ import { FC , useCallback , useMemo , useState } from 'react'
2+ import { mutate } from 'swr'
3+ import classNames from 'classnames'
24
3- import { Tabs } from '~/apps/review/src/lib'
5+ import { Tabs , useChallengeDetailsContext } from '~/apps/review/src/lib'
46import { ScorecardViewer } from '~/apps/review/src/lib/components/Scorecard'
57import { ScorecardAttachments } from '~/apps/review/src/lib/components/Scorecard/ScorecardAttachments'
68import {
79AiWorkflowRunAttachmentsResponse ,
810AiWorkflowRunItemsResponse ,
911AiWorkflowRunStatusEnum ,
12+ useAppNavigate ,
1013useFetchAiWorkflowsRunAttachments ,
1114useFetchAiWorkflowsRunItems ,
1215} from '~/apps/review/src/lib/hooks'
13- import { ReviewsContextModel , SelectOption } from '~/apps/review/src/lib/models'
16+ import { ChallengeDetailContextModel , ReviewsContextModel , SelectOption } from '~/apps/review/src/lib/models'
1417import { AiWorkflowRunStatus } from '~/apps/review/src/lib/components/AiReviewsTable'
18+ import { rootRoute } from '~/apps/review/src/config/routes.config'
1519
1620import { ScorecardHeader } from '../ScorecardHeader'
1721import { useReviewsContext } from '../../ReviewsContext'
@@ -28,12 +32,21 @@ const AiReviewViewer: FC = () => {
2832)
2933const { totalCount} :AiWorkflowRunAttachmentsResponse
3034= useFetchAiWorkflowsRunAttachments ( workflowId , workflowRun ?. id )
35+ const {
36+ challengeInfo,
37+ } :ChallengeDetailContextModel = useChallengeDetailsContext ( )
38+ const navigate = useAppNavigate ( )
3139
3240const tabItems :SelectOption [ ] = [
3341{
3442indicator :workflowRun && (
3543< >
36- < span className = { styles . tabScore } > { workflowRun ?. score ?? '' } </ span >
44+ < span className = { classNames ( styles . tabScore , {
45+ [ styles . selected ] :selectedTab === 'scorecard' ,
46+ } ) }
47+ >
48+ { workflowRun ?. score ?? '' }
49+ </ span >
3750< AiWorkflowRunStatus
3851run = { workflowRun }
3952hideLabel
@@ -52,6 +65,28 @@ const AiReviewViewer: FC = () => {
5265] . includes ( workflowRun . status )
5366) , [ workflowRun ] )
5467
68+ const back = useCallback ( async ( e ?:React . MouseEvent < HTMLAnchorElement > ) => {
69+ e ?. preventDefault ( )
70+ try {
71+ if ( challengeInfo ?. id ) {
72+ // Ensure the challenge details reflect the latest data (e.g., active phase)
73+ await mutate ( `challengeBaseUrl/challenges/${ challengeInfo ?. id } ` )
74+ }
75+ } catch {
76+ // no-op: navigation should still occur even if revalidation fails
77+ }
78+
79+ const pastPrefix = '/past-challenges/'
80+ // eslint-disable-next-line no-restricted-globals
81+ const idx = location . pathname . indexOf ( pastPrefix )
82+ const url = idx > - 1
83+ ?`${ rootRoute } /past-challenges/${ challengeInfo ?. id } /challenge-details`
84+ :`${ rootRoute } /active-challenges/${ challengeInfo ?. id } /challenge-details`
85+ navigate ( url , {
86+ fallback :'./../../../../challenge-details' ,
87+ } )
88+ } , [ challengeInfo ?. id , mutate , navigate ] )
89+
5590return (
5691< div className = { styles . wrap } >
5792
@@ -74,6 +109,7 @@ const AiReviewViewer: FC = () => {
74109scorecard = { scorecard }
75110aiFeedback = { runItems }
76111setActionButtons = { setActionButtons }
112+ navigateBack = { back }
77113/>
78114) }
79115