1
1
/**
2
2
* Table Winners.
3
3
*/
4
- import { FC , MouseEvent , useContext , useMemo } from 'react'
4
+ import {
5
+ FC ,
6
+ MouseEvent ,
7
+ useCallback ,
8
+ useContext ,
9
+ useMemo ,
10
+ } from 'react'
5
11
import { Link } from 'react-router-dom'
6
12
import { toast } from 'react-toastify'
7
13
import { includes , noop } from 'lodash'
@@ -20,8 +26,15 @@ import {
20
26
AggregatedReviewDetail ,
21
27
AggregatedSubmissionReviews ,
22
28
aggregateSubmissionReviews ,
29
+ isAppealsPhase ,
30
+ isAppealsResponsePhase ,
23
31
} from '../../utils'
24
- import { NO_RESOURCE_ID , WITHOUT_APPEAL } from '../../../config/index.config'
32
+ import {
33
+ FIRST2FINISH ,
34
+ NO_RESOURCE_ID ,
35
+ TRACK_CHALLENGE ,
36
+ WITHOUT_APPEAL ,
37
+ } from '../../../config/index.config'
25
38
import { ChallengeDetailContext } from '../../contexts'
26
39
import { useSubmissionDownloadAccess } from '../../hooks'
27
40
import type { UseSubmissionDownloadAccessResult } from '../../hooks/useSubmissionDownloadAccess'
@@ -73,6 +86,29 @@ export const TableReviewAppealsForSubmitter: FC<Props> = (props: Props) => {
73
86
[ challengeTrack , challengeType ] ,
74
87
)
75
88
89
+ const isFirst2FinishChallenge = useMemo (
90
+ ( ) => [ challengeType , challengeTrack ]
91
+ . some ( type => type === FIRST2FINISH ) ,
92
+ [ challengeTrack , challengeType ] ,
93
+ )
94
+
95
+ const isStandardChallenge = useMemo (
96
+ ( ) => [ challengeType , challengeTrack ]
97
+ . some ( type => type === TRACK_CHALLENGE ) ,
98
+ [ challengeTrack , challengeType ] ,
99
+ )
100
+
101
+ const isAppealsWindowOpen = useMemo (
102
+ ( ) => isAppealsPhase ( challengeInfo )
103
+ || isAppealsResponsePhase ( challengeInfo ) ,
104
+ [ challengeInfo ] ,
105
+ )
106
+
107
+ const shouldShowAppealsColumn = useMemo (
108
+ ( ) => allowsAppeals && ( isAppealsWindowOpen || isChallengeCompleted ) ,
109
+ [ allowsAppeals , isAppealsWindowOpen , isChallengeCompleted ] ,
110
+ )
111
+
76
112
const aggregatedRows = useMemo ( ( ) => aggregateSubmissionReviews ( {
77
113
mappingReviewAppeal,
78
114
reviewers,
@@ -95,6 +131,43 @@ export const TableReviewAppealsForSubmitter: FC<Props> = (props: Props) => {
95
131
[ aggregatedRows ] ,
96
132
)
97
133
134
+ const canDisplayScores = useCallback (
135
+ ( submission : SubmissionRow ) : boolean => {
136
+ if ( isChallengeCompleted ) {
137
+ return true
138
+ }
139
+
140
+ if ( isFirst2FinishChallenge ) {
141
+ const reviews = submission . aggregated ?. reviews ?? [ ]
142
+ if ( ! reviews . length ) {
143
+ return false
144
+ }
145
+
146
+ const allReviewsCompleted = reviews . every ( review => {
147
+ const status = ( review . reviewInfo ?. status ?? '' ) . toUpperCase ( )
148
+ const committed = review . reviewInfo ?. committed ?? false
149
+
150
+ return committed
151
+ || includes ( [ 'COMPLETED' , 'SUBMITTED' ] , status )
152
+ } )
153
+
154
+ return allReviewsCompleted
155
+ }
156
+
157
+ if ( isStandardChallenge ) {
158
+ return isAppealsWindowOpen
159
+ }
160
+
161
+ return true
162
+ } ,
163
+ [
164
+ isAppealsWindowOpen ,
165
+ isChallengeCompleted ,
166
+ isFirst2FinishChallenge ,
167
+ isStandardChallenge ,
168
+ ] ,
169
+ )
170
+
98
171
const columns = useMemo < TableColumn < SubmissionRow > [ ] > ( ( ) => {
99
172
const submissionColumn : TableColumn < SubmissionRow > = {
100
173
className : styles . submissionColumn ,
@@ -222,6 +295,14 @@ export const TableReviewAppealsForSubmitter: FC<Props> = (props: Props) => {
222
295
columnId : 'review-score' ,
223
296
label : 'Review Score' ,
224
297
renderer : ( data : SubmissionRow ) => {
298
+ if ( ! canDisplayScores ( data ) ) {
299
+ return (
300
+ < span className = { styles . notReviewed } >
301
+ --
302
+ </ span >
303
+ )
304
+ }
305
+
225
306
const scoreDisplay = data . aggregated ?. averageFinalScoreDisplay
226
307
if ( ! scoreDisplay ) {
227
308
return (
@@ -294,6 +375,14 @@ export const TableReviewAppealsForSubmitter: FC<Props> = (props: Props) => {
294
375
)
295
376
}
296
377
378
+ if ( ! canDisplayScores ( data ) ) {
379
+ return (
380
+ < span className = { styles . notReviewed } >
381
+ --
382
+ </ span >
383
+ )
384
+ }
385
+
297
386
const finalScore = reviewDetail ?. finalScore
298
387
const formattedScore = typeof finalScore === 'number' && Number . isFinite ( finalScore )
299
388
? finalScore . toFixed ( 2 )
@@ -386,7 +475,7 @@ export const TableReviewAppealsForSubmitter: FC<Props> = (props: Props) => {
386
475
type : 'element' ,
387
476
} )
388
477
389
- if ( allowsAppeals ) {
478
+ if ( shouldShowAppealsColumn ) {
390
479
aggregatedColumns . push ( {
391
480
className : styles . tableCellNoWrap ,
392
481
columnId : `appeals-${ index } ` ,
@@ -400,11 +489,13 @@ export const TableReviewAppealsForSubmitter: FC<Props> = (props: Props) => {
400
489
return aggregatedColumns
401
490
} , [
402
491
allowsAppeals ,
492
+ canDisplayScores ,
403
493
downloadSubmission ,
404
494
isSubmissionDownloadRestricted ,
405
495
isDownloading ,
406
496
isChallengeCompleted ,
407
497
maxReviewCount ,
498
+ shouldShowAppealsColumn ,
408
499
restrictionMessage ,
409
500
] )
410
501
0 commit comments