Skip to content

Commit dbd3a51

Browse files
authored
Merge pull request #1281 from topcoder-platform/feat/v6
Fix for winner tab display
2 parents 8e53f50 + b33e1d5 commit dbd3a51

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import {
2323
import { fetchChallengeReviews } from '../services'
2424
import { ChallengeDetailContext } from '../contexts'
2525
import { PAST_CHALLENGE_STATUSES } from '../utils/challengeStatus'
26+
import {
27+
SUBMISSION_TYPE_CONTEST,
28+
} from '../constants'
2629

2730
type ResourceMemberMapping = ChallengeDetailContextModel['resourceMemberIdMapping']
2831

@@ -135,8 +138,16 @@ const buildProjectResult = ({
135138

136139
// Find all submissions for this member
137140
const memberSubmissions = submissions.filter(s => s.memberId === memberId)
141+
const contestSubmissions = memberSubmissions.filter(
142+
submission => (submission.type ?? SUBMISSION_TYPE_CONTEST) === SUBMISSION_TYPE_CONTEST,
143+
)
144+
145+
// Prefer contest submissions; fall back to everything so we still display something if data is inconsistent
146+
const submissionsToEvaluate = contestSubmissions.length
147+
? contestSubmissions
148+
: memberSubmissions
138149

139-
if (!memberSubmissions.length) {
150+
if (!submissionsToEvaluate.length) {
140151
return undefined
141152
}
142153

@@ -148,7 +159,7 @@ const buildProjectResult = ({
148159
computedInitialScore: number
149160
}
150161

151-
const evaluated: EvaluatedSubmission[] = memberSubmissions.map(submission => {
162+
const evaluated: EvaluatedSubmission[] = submissionsToEvaluate.map(submission => {
152163
const fallbackReviews = submission?.reviews ?? []
153164
const mappedReviews = reviewsBySubmissionId.get(submission.id) ?? fallbackReviews
154165
const orderedReviews = orderReviewsByCreatedDate(mappedReviews)

src/apps/review/src/lib/models/BackendChallengeInfo.model.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import moment from 'moment'
22

33
import { formatDurationDate } from '../utils'
4+
import { SUBMISSION_TYPE_CONTEST } from '../constants'
45
import { TABLE_DATE_FORMAT } from '../../config/index.config'
56

67
import { BackendMetadata } from './BackendMetadata.model'
@@ -108,15 +109,22 @@ function normalizeTrack(
108109
function mapWinners(
109110
winners: BackendChallengeInfo['winners'],
110111
): ChallengeWinner[] | undefined {
111-
return winners
112-
? winners.map(winner => ({
113-
handle: winner.handle,
114-
maxRating: winner.maxRating ?? undefined,
115-
placement: winner.placement,
116-
type: winner.type,
117-
userId: winner.userId,
118-
}))
119-
: undefined
112+
if (!winners) {
113+
return undefined
114+
}
115+
116+
// Only expose contest submissions in the winners list
117+
const contestWinners = winners.filter(winner => (
118+
(winner.type ?? SUBMISSION_TYPE_CONTEST) === SUBMISSION_TYPE_CONTEST
119+
))
120+
121+
return contestWinners.map(winner => ({
122+
handle: winner.handle,
123+
maxRating: winner.maxRating ?? undefined,
124+
placement: winner.placement,
125+
type: winner.type,
126+
userId: winner.userId,
127+
}))
120128
}
121129

122130
/**

0 commit comments

Comments
 (0)