Skip to content

Commit ae47522

Browse files
committed
Fix approval not shwoing up
1 parent 372df44 commit ae47522

File tree

1 file changed

+7
-84
lines changed

1 file changed

+7
-84
lines changed

src/apps/review/src/lib/components/ChallengeDetailsContent/TabContentApproval.tsx

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,6 @@ import {
1616
} from '../../../config/index.config'
1717
import { ChallengeDetailContext } from '../../contexts'
1818

19-
const normalizeAlphaLowerCase = (value?: string): string | undefined => {
20-
if (typeof value !== 'string') {
21-
return undefined
22-
}
23-
24-
const trimmed = value.trim()
25-
return trimmed
26-
? trimmed
27-
.toLowerCase()
28-
.replace(/[^a-z]/g, '')
29-
: undefined
30-
}
31-
32-
const getSubmissionScore = (submission: SubmissionInfo): number => {
33-
const scores: number[] = []
34-
35-
if (typeof submission.aggregateScore === 'number' && Number.isFinite(submission.aggregateScore)) {
36-
scores.push(submission.aggregateScore)
37-
}
38-
39-
if (typeof submission.review?.finalScore === 'number' && Number.isFinite(submission.review.finalScore)) {
40-
scores.push(submission.review.finalScore)
41-
}
42-
43-
if (Array.isArray(submission.reviews)) {
44-
submission.reviews.forEach(reviewResult => {
45-
const score = reviewResult?.score
46-
if (typeof score === 'number' && Number.isFinite(score)) {
47-
scores.push(score)
48-
}
49-
})
50-
}
51-
52-
return scores.length
53-
? Math.max(...scores)
54-
: Number.NEGATIVE_INFINITY
55-
}
56-
57-
const getSubmissionTimestamp = (submission: SubmissionInfo): number => {
58-
const submittedDate: SubmissionInfo['submittedDate'] = submission.submittedDate
59-
if (submittedDate instanceof Date) {
60-
return submittedDate.getTime()
61-
}
62-
63-
if (typeof submittedDate === 'string') {
64-
const parsed = Date.parse(submittedDate)
65-
return Number.isFinite(parsed) ? parsed : Number.NEGATIVE_INFINITY
66-
}
67-
68-
return Number.NEGATIVE_INFINITY
69-
}
70-
7119
interface Props {
7220
reviews: SubmissionInfo[]
7321
submitterReviews: SubmissionInfo[]
@@ -97,43 +45,18 @@ export const TabContentApproval: FC<Props> = (props: Props) => {
9745
)
9846
const approvalRows: SubmissionInfo[] = useMemo(
9947
() => {
100-
const inPhase = rawRows.filter(r => (r.review?.phaseId ? approvalPhaseIds.has(r.review.phaseId) : false))
101-
if (!inPhase.length) {
102-
return []
103-
}
104-
105-
const reviewTypeRows = inPhase.filter(row => normalizeAlphaLowerCase(row.reviewTypeId) === 'review')
106-
if (!reviewTypeRows.length) {
48+
if (!rawRows.length) {
10749
return []
10850
}
10951

110-
const passingRows = reviewTypeRows.filter(row => row.isPassingReview === true)
111-
if (!passingRows.length) {
112-
return []
52+
if (approvalPhaseIds.size === 0) {
53+
return rawRows
11354
}
11455

115-
const bestRow = passingRows.reduce<SubmissionInfo | undefined>((best, current) => {
116-
if (!best) {
117-
return current
118-
}
119-
120-
const bestScore = getSubmissionScore(best)
121-
const currentScore = getSubmissionScore(current)
122-
123-
if (currentScore > bestScore) {
124-
return current
125-
}
126-
127-
if (currentScore === bestScore) {
128-
const currentTimestamp = getSubmissionTimestamp(current)
129-
const bestTimestamp = getSubmissionTimestamp(best)
130-
return currentTimestamp > bestTimestamp ? current : best
131-
}
132-
133-
return best
134-
}, undefined)
135-
136-
return bestRow ? [bestRow] : []
56+
return rawRows.filter(row => {
57+
const phaseId = row.review?.phaseId
58+
return phaseId ? approvalPhaseIds.has(phaseId) : false
59+
})
13760
},
13861
[rawRows, approvalPhaseIds],
13962
)

0 commit comments

Comments
 (0)