@@ -3,6 +3,7 @@ import moment from 'moment'
33
44import { CheckIcon , MinusCircleIcon } from '@heroicons/react/outline'
55import { useWindowSize , WindowSize } from '~/libs/shared'
6+ import { IconOutline , Tooltip } from '~/libs/ui'
67
78import {
89 AiWorkflowRun ,
@@ -17,27 +18,23 @@ import { TABLE_DATE_FORMAT } from '../../../config/index.config'
1718import { BackendSubmission } from '../../models'
1819
1920import styles from './AiReviewsTable.module.scss'
20- import { IconOutline , Tooltip } from '~/libs/ui'
21- import { run } from 'node:test'
2221
2322interface AiReviewsTableProps {
2423 submission : Pick < BackendSubmission , 'id' | 'virusScan' >
2524 reviewers : { aiWorkflowId : string } [ ]
2625}
2726
28- const aiRunInProgress = ( aiRun : Pick < AiWorkflowRun , 'status' > ) =>
29- [
30- AiWorkflowRunStatus . INIT ,
31- AiWorkflowRunStatus . QUEUED ,
32- AiWorkflowRunStatus . DISPATCHED ,
33- AiWorkflowRunStatus . IN_PROGRESS ,
34- ] . includes ( aiRun . status )
27+ const aiRunInProgress = ( aiRun : Pick < AiWorkflowRun , 'status' > ) : boolean => [
28+ AiWorkflowRunStatus . INIT ,
29+ AiWorkflowRunStatus . QUEUED ,
30+ AiWorkflowRunStatus . DISPATCHED ,
31+ AiWorkflowRunStatus . IN_PROGRESS ,
32+ ] . includes ( aiRun . status )
3533
36- const aiRunFailed = ( aiRun : Pick < AiWorkflowRun , 'status' > ) =>
37- [
38- AiWorkflowRunStatus . FAILURE ,
39- AiWorkflowRunStatus . CANCELLED ,
40- ] . includes ( aiRun . status )
34+ const aiRunFailed = ( aiRun : Pick < AiWorkflowRun , 'status' > ) : boolean => [
35+ AiWorkflowRunStatus . FAILURE ,
36+ AiWorkflowRunStatus . CANCELLED ,
37+ ] . includes ( aiRun . status )
4138
4239const AiReviewsTable : FC < AiReviewsTableProps > = props => {
4340 const aiWorkflowIds = useMemo ( ( ) => props . reviewers . map ( r => r . aiWorkflowId ) , [ props . reviewers ] )
@@ -53,15 +50,15 @@ const AiReviewsTable: FC<AiReviewsTableProps> = props => {
5350 const aiRuns = useMemo ( ( ) => [
5451 ...runs ,
5552 {
56- id : '-1' ,
5753 completedAt : ( props . submission as BackendSubmission ) . submittedDate ,
58- status : AiWorkflowRunStatus . SUCCESS ,
54+ id : '-1' ,
5955 score : props . submission . virusScan === true ? 100 : 0 ,
56+ status : AiWorkflowRunStatus . SUCCESS ,
6057 workflow : {
61- name : 'Virus Scan' ,
6258 description : '' ,
63- }
64- } as AiWorkflowRun
59+ name : 'Virus Scan' ,
60+ } ,
61+ } as AiWorkflowRun ,
6562 ] . filter ( r => isAdmin || ! aiRunFailed ( r ) ) , [ runs , props . submission ] )
6663
6764 if ( isTablet ) {
@@ -154,86 +151,90 @@ const AiReviewsTable: FC<AiReviewsTableProps> = props => {
154151 return (
155152 < div className = { styles . wrap } >
156153 < table className = { styles . reviewsTable } >
157- < tr >
158- < th > AI Reviewer</ th >
159- < th > Review Date</ th >
160- < th > Score</ th >
161- < th > Result</ th >
162- </ tr >
163-
164- { ! runs . length && isLoading && (
154+ < thead >
165155 < tr >
166- < td colSpan = { 4 } > Loading...</ td >
156+ < th > AI Reviewer</ th >
157+ < th > Review Date</ th >
158+ < th > Score</ th >
159+ < th > Result</ th >
167160 </ tr >
168- ) }
169-
170- { aiRuns . map ( run => (
171- < tr key = { run . id } >
172- < td >
173- < div className = { styles . aiReviewer } >
174- < span className = { styles . icon } >
175- < IconAiReview />
176- </ span >
177- < span className = { styles . workflowName } title = { run . workflow . name } >
178- < Tooltip content = { run . workflow . name } triggerOn = 'hover' >
179- { run . workflow . name }
180- </ Tooltip >
181- </ span >
182- </ div >
183- </ td >
184- < td >
185- { run . status === 'SUCCESS' && (
186- moment ( run . completedAt )
187- . local ( )
188- . format ( TABLE_DATE_FORMAT )
189- ) }
190- </ td >
191- < td className = { styles . scoreCol } >
192- { run . status === 'SUCCESS' ? (
193- run . workflow . scorecard ? (
194- < a href = { `/scorecard/${ run . workflow . scorecard . id } ` } > { run . score } </ a >
195- ) : run . score
196- ) : '-' }
197- </ td >
198- < td className = { styles . resultCol } >
199- { run . status === 'SUCCESS' && (
200- < div className = { styles . result } >
201- { run . score >= ( run . workflow . scorecard ?. minimumPassingScore ?? 0 )
202- ? (
203- < >
204- < CheckIcon className = 'icon icon-xl passed' />
205- { ' ' }
206- Passed
207- </ >
208- )
209- : (
210- < >
211- < MinusCircleIcon className = 'icon icon-xl' />
212- { ' ' }
213- Passed
214- </ >
215- ) }
216- </ div >
217- ) }
218- { aiRunInProgress ( run ) && (
219- < div className = { styles . result } >
220- < span className = 'icon pending' >
221- < IconOutline . MinusIcon className = 'icon-sm' />
161+ </ thead >
162+
163+ < tbody >
164+ { ! runs . length && isLoading && (
165+ < tr >
166+ < td colSpan = { 4 } > Loading...</ td >
167+ </ tr >
168+ ) }
169+
170+ { aiRuns . map ( run => (
171+ < tr key = { run . id } >
172+ < td >
173+ < div className = { styles . aiReviewer } >
174+ < span className = { styles . icon } >
175+ < IconAiReview />
222176 </ span >
223- { ' ' }
224- To be filled
225- </ div >
226- ) }
227- { aiRunFailed ( run ) && (
228- < div className = { styles . result } >
229- < span className = 'icon' >
230- < IconOutline . XCircleIcon className = 'icon-xl' />
177+ < span className = { styles . workflowName } title = { run . workflow . name } >
178+ < Tooltip content = { run . workflow . name } triggerOn = 'hover' >
179+ { run . workflow . name }
180+ </ Tooltip >
231181 </ span >
232182 </ div >
233- ) }
234- </ td >
235- </ tr >
236- ) ) }
183+ </ td >
184+ < td >
185+ { run . status === 'SUCCESS' && (
186+ moment ( run . completedAt )
187+ . local ( )
188+ . format ( TABLE_DATE_FORMAT )
189+ ) }
190+ </ td >
191+ < td className = { styles . scoreCol } >
192+ { run . status === 'SUCCESS' ? (
193+ run . workflow . scorecard ? (
194+ < a href = { `/scorecard/${ run . workflow . scorecard . id } ` } > { run . score } </ a >
195+ ) : run . score
196+ ) : '-' }
197+ </ td >
198+ < td className = { styles . resultCol } >
199+ { run . status === 'SUCCESS' && (
200+ < div className = { styles . result } >
201+ { run . score >= ( run . workflow . scorecard ?. minimumPassingScore ?? 0 )
202+ ? (
203+ < >
204+ < CheckIcon className = 'icon icon-xl passed' />
205+ { ' ' }
206+ Passed
207+ </ >
208+ )
209+ : (
210+ < >
211+ < MinusCircleIcon className = 'icon icon-xl' />
212+ { ' ' }
213+ Passed
214+ </ >
215+ ) }
216+ </ div >
217+ ) }
218+ { aiRunInProgress ( run ) && (
219+ < div className = { styles . result } >
220+ < span className = 'icon pending' >
221+ < IconOutline . MinusIcon className = 'icon-sm' />
222+ </ span >
223+ { ' ' }
224+ To be filled
225+ </ div >
226+ ) }
227+ { aiRunFailed ( run ) && (
228+ < div className = { styles . result } >
229+ < span className = 'icon' >
230+ < IconOutline . XCircleIcon className = 'icon-xl' />
231+ </ span >
232+ </ div >
233+ ) }
234+ </ td >
235+ </ tr >
236+ ) ) }
237+ </ tbody >
237238 </ table >
238239 </ div >
239240 )
0 commit comments