Skip to content

Commit b7801b6

Browse files
authored
Merge pull request #1345 from topcoder-platform/auto-refresh-ui
Auto-refresh the AI reviews ui if run is in progress
2 parents 2b72d9a + 614b230 commit b7801b6

File tree

6 files changed

+19
-25
lines changed

6 files changed

+19
-25
lines changed

src/apps/review/src/lib/components/AiReviewsTable/AiReviewsTable.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ import styles from './AiReviewsTable.module.scss'
2020

2121
interface AiReviewsTableProps {
2222
submission: Pick<BackendSubmission, 'id'|'virusScan'>
23-
reviewers: { aiWorkflowId: string }[]
2423
}
2524

2625
const stopPropagation = (ev: ReactMouseEvent<HTMLDivElement, MouseEvent>): void => {
2726
ev.stopPropagation()
2827
}
2928

3029
const AiReviewsTable: FC<AiReviewsTableProps> = props => {
31-
const aiWorkflowIds = useMemo(() => props.reviewers.map(r => r.aiWorkflowId), [props.reviewers])
32-
const { runs, isLoading }: AiWorkflowRunsResponse = useFetchAiWorkflowsRuns(props.submission.id, aiWorkflowIds)
30+
const { runs, isLoading }: AiWorkflowRunsResponse = useFetchAiWorkflowsRuns(props.submission.id)
3331

3432
const windowSize: WindowSize = useWindowSize()
3533
const isTablet = useMemo(

src/apps/review/src/lib/components/CollapsibleAiReviewsRow/CollapsibleAiReviewsRow.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ const CollapsibleAiReviewsRow: FC<CollapsibleAiReviewsRowProps> = props => {
3535
</span>
3636
{isOpen && (
3737
<div className={classNames(styles.table, 'reviews-table')}>
38-
<AiReviewsTable
39-
reviewers={props.aiReviewers}
40-
submission={props.submission}
41-
/>
38+
<AiReviewsTable submission={props.submission} />
4239
</div>
4340
)}
4441
</div>

src/apps/review/src/lib/components/SubmissionHistoryModal/SubmissionHistoryModal.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,7 @@ export const SubmissionHistoryModal: FC<SubmissionHistoryModalProps> = (props: S
279279
<tr>
280280
<td className={styles.aiReviewersTableRow} colSpan={4}>
281281
<div className={styles.aiReviewersTable}>
282-
<AiReviewsTable
283-
reviewers={aiReviewers}
284-
submission={submission}
285-
/>
282+
<AiReviewsTable submission={submission} />
286283
</div>
287284
</td>
288285
</tr>

src/apps/review/src/lib/hooks/useFetchAiWorkflowRuns.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useState } from 'react'
1+
import { useCallback, useEffect, useRef, useState } from 'react'
22
import useSWR, { SWRResponse } from 'swr'
33

44
import { EnvironmentConfig } from '~/config'
@@ -111,8 +111,8 @@ export const aiRunFailed = (aiRun: Pick<AiWorkflowRun, 'status'>): boolean => [
111111

112112
export function useFetchAiWorkflowsRuns(
113113
submissionId: string,
114-
workflowIds: string[],
115114
): AiWorkflowRunsResponse {
115+
const hasInProgress = useRef(true)
116116
// Use swr hooks for challenge info fetching
117117
const {
118118
data: runs = [],
@@ -121,10 +121,19 @@ export function useFetchAiWorkflowsRuns(
121121
}: SWRResponse<AiWorkflowRun[], Error> = useSWR<AiWorkflowRun[], Error>(
122122
`${TC_API_BASE_URL}/workflows/runs?submissionId=${submissionId}`,
123123
{
124-
isPaused: () => !workflowIds?.length || !submissionId,
124+
isPaused: () => !submissionId,
125+
refreshInterval: hasInProgress.current ? 10 * 1000 : 0,
125126
},
126127
)
127128

129+
hasInProgress.current = !!runs.find(r => (
130+
![
131+
AiWorkflowRunStatusEnum.SUCCESS,
132+
AiWorkflowRunStatusEnum.CANCELLED,
133+
AiWorkflowRunStatusEnum.COMPLETED,
134+
].includes(r.status)
135+
))
136+
128137
// Show backend error when fetching challenge info
129138
useEffect(() => {
130139
if (fetchError) {

src/apps/review/src/pages/reviews/ReviewsContext/ReviewsContextProvider.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Context, createContext, FC, PropsWithChildren, ReactNode, useContext, u
55
import { useParams, useSearchParams } from 'react-router-dom'
66

77
import { ChallengeDetailContext } from '../../../lib'
8-
import { ChallengeDetailContextModel, ReviewCtxStatus, ReviewsContextModel } from '../../../lib/models'
8+
import { ReviewCtxStatus, ReviewsContextModel } from '../../../lib/models'
99
import { AiWorkflowRunsResponse, useFetchAiWorkflowsRuns, useFetchSubmissionInfo } from '../../../lib/hooks'
1010

1111
export const ReviewsContext: Context<ReviewsContextModel>
@@ -25,17 +25,10 @@ export const ReviewsContextProvider: FC<PropsWithChildren> = props => {
2525
const [actionButtons, setActionButtons] = useState<ReactNode>()
2626

2727
const challengeDetailsCtx = useContext(ChallengeDetailContext)
28-
const { challengeInfo }: ChallengeDetailContextModel = challengeDetailsCtx
29-
3028
const [submissionInfo] = useFetchSubmissionInfo(submissionId)
3129

32-
const aiReviewers = useMemo(() => (
33-
(challengeInfo?.reviewers ?? []).filter(r => !!r.aiWorkflowId)
34-
), [challengeInfo?.reviewers])
35-
const aiWorkflowIds = useMemo(() => aiReviewers?.map(r => r.aiWorkflowId as string), [aiReviewers])
36-
3730
const { runs: workflowRuns, isLoading: aiWorkflowRunsLoading }: AiWorkflowRunsResponse
38-
= useFetchAiWorkflowsRuns(submissionId, aiWorkflowIds)
31+
= useFetchAiWorkflowsRuns(submissionId)
3932

4033
const isLoadingCtxData
4134
= challengeDetailsCtx.isLoadingChallengeInfo

src/libs/ui/lib/components/tooltip/Tooltip.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ const Tooltip: FC<TooltipProps> = (props: TooltipProps) => {
5252

5353
function renderTrigger(): ReactElement[] {
5454
return Children.toArray(props.children)
55-
.map(child => cloneElement((wrapComponents(child, props.disableWrap) as ReactElement), {
55+
.map((child, i) => cloneElement((wrapComponents(child, props.disableWrap) as ReactElement), {
5656
'data-tooltip-delay-show': triggerOnClick ? '0' : '300',
5757
'data-tooltip-id': tooltipId.current as string,
5858
'data-tooltip-place': props.place ?? 'bottom',
5959
'data-tooltip-strategy': props.strategy ?? 'absolute',
60-
key: tooltipId.current as string,
60+
key: `${tooltipId.current as string}-${i}`,
6161
} as any))
6262
}
6363

0 commit comments

Comments
 (0)