11import { FC , useMemo } from 'react'
22import moment from 'moment'
33
4- import { CheckIcon , MinusCircleIcon } from '@heroicons/react/outline'
54import { useWindowSize , WindowSize } from '~/libs/shared'
6- import { IconOutline , Tooltip } from '~/libs/ui'
5+ import { Tooltip } from '~/libs/ui'
76
87import {
98 AiWorkflowRun ,
109 AiWorkflowRunsResponse ,
11- AiWorkflowRunStatus ,
10+ AiWorkflowRunStatusEnum ,
1211 useFetchAiWorkflowsRuns ,
13- useRolePermissions ,
14- UseRolePermissionsResult ,
1512} from '../../hooks'
1613import { IconAiReview } from '../../assets/icons'
1714import { TABLE_DATE_FORMAT } from '../../../config/index.config'
1815import { BackendSubmission } from '../../models'
1916
17+ import { AiWorkflowRunStatus } from './AiWorkflowRunStatus'
2018import styles from './AiReviewsTable.module.scss'
2119
2220interface AiReviewsTableProps {
2321 submission : Pick < BackendSubmission , 'id' | 'virusScan' >
2422 reviewers : { aiWorkflowId : string } [ ]
2523}
2624
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 )
33-
34- const aiRunFailed = ( aiRun : Pick < AiWorkflowRun , 'status' > ) : boolean => [
35- AiWorkflowRunStatus . FAILURE ,
36- AiWorkflowRunStatus . CANCELLED ,
37- ] . includes ( aiRun . status )
38-
3925const AiReviewsTable : FC < AiReviewsTableProps > = props => {
4026 const aiWorkflowIds = useMemo ( ( ) => props . reviewers . map ( r => r . aiWorkflowId ) , [ props . reviewers ] )
4127 const { runs, isLoading } : AiWorkflowRunsResponse = useFetchAiWorkflowsRuns ( props . submission . id , aiWorkflowIds )
@@ -45,21 +31,20 @@ const AiReviewsTable: FC<AiReviewsTableProps> = props => {
4531 ( ) => ( windowSize . width ?? 0 ) <= 984 ,
4632 [ windowSize . width ] ,
4733 )
48- const { isAdmin } : UseRolePermissionsResult = useRolePermissions ( )
4934
5035 const aiRuns = useMemo ( ( ) => [
5136 ...runs ,
5237 {
5338 completedAt : ( props . submission as BackendSubmission ) . submittedDate ,
5439 id : '-1' ,
5540 score : props . submission . virusScan === true ? 100 : 0 ,
56- status : AiWorkflowRunStatus . SUCCESS ,
41+ status : AiWorkflowRunStatusEnum . SUCCESS ,
5742 workflow : {
5843 description : '' ,
5944 name : 'Virus Scan' ,
6045 } ,
6146 } as AiWorkflowRun ,
62- ] . filter ( r => isAdmin || ! aiRunFailed ( r ) ) , [ runs , props . submission ] )
47+ ] , [ runs , props . submission ] )
6348
6449 if ( isTablet ) {
6550 return (
@@ -107,39 +92,7 @@ const AiReviewsTable: FC<AiReviewsTableProps> = props => {
10792 < div className = { styles . mobileRow } >
10893 < div className = { styles . label } > Result</ div >
10994 < div className = { `${ styles . value } ${ styles . resultCol } ` } >
110- { run . status === 'SUCCESS' && (
111- < div className = { styles . result } >
112- { run . score >= ( run . workflow . scorecard ?. minimumPassingScore ?? 0 ) ? (
113- < >
114- < CheckIcon className = 'icon icon-xl passed' />
115- { ' ' }
116- Passed
117- </ >
118- ) : (
119- < >
120- < MinusCircleIcon className = 'icon icon-xl' />
121- { ' ' }
122- Failed
123- </ >
124- ) }
125- </ div >
126- ) }
127- { aiRunInProgress ( run ) && (
128- < div className = { styles . result } >
129- < span className = 'icon pending' >
130- < IconOutline . MinusIcon className = 'icon-sm' />
131- </ span >
132- { ' ' }
133- To be filled
134- </ div >
135- ) }
136- { aiRunFailed ( run ) && (
137- < div className = { styles . result } >
138- < span className = 'icon' >
139- < IconOutline . XCircleIcon className = 'icon-xl' />
140- </ span >
141- </ div >
142- ) }
95+ < AiWorkflowRunStatus run = { run } />
14396 </ div >
14497 </ div >
14598 </ div >
@@ -196,41 +149,7 @@ const AiReviewsTable: FC<AiReviewsTableProps> = props => {
196149 ) : '-' }
197150 </ td >
198151 < 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- Failed
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- ) }
152+ < AiWorkflowRunStatus run = { run } />
234153 </ td >
235154 </ tr >
236155 ) ) }
0 commit comments