Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/apps/opportunities/src/components/ChallengeSidebar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const topgearChallengesExplainedUrl
const mockUseSWR = jest.fn()
const mockChallengeAllowsStockArt = jest.fn()
const mockChallengeFileTypes = jest.fn()
const mockChallengeManualReviewScorecardUrl = jest.fn()
const mockChallengeSidebarLinks = jest.fn()
const mockIsTopgearChallenge = jest.fn()

Expand All @@ -64,6 +65,7 @@ jest.mock('../utils', () => ({
challengeAllowsStockArt: (...args: unknown[]) => mockChallengeAllowsStockArt(...args),
challengeFileTypes: (...args: unknown[]) => mockChallengeFileTypes(...args),
challengeForumUrl: (): undefined => undefined,
challengeManualReviewScorecardUrl: (...args: unknown[]) => mockChallengeManualReviewScorecardUrl(...args),
challengeReviewAppUrl: (challengeId: string): string => (
`https://review.topcoder-dev.com/active-challenges/${challengeId}/challenge-details`
),
Expand Down Expand Up @@ -137,6 +139,7 @@ describe('ChallengeSidebar Review Style', () => {
mockUseSWR.mockReturnValue({ data: undefined })
mockChallengeAllowsStockArt.mockReturnValue(false)
mockChallengeFileTypes.mockReturnValue([])
mockChallengeManualReviewScorecardUrl.mockReturnValue(undefined)
mockIsTopgearChallenge.mockReturnValue(false)
mockChallengeSidebarLinks.mockReturnValue({
attachments: [],
Expand Down Expand Up @@ -171,6 +174,43 @@ describe('ChallengeSidebar Review Style', () => {
.toBeInTheDocument()
expect(screen.queryByText(/Instant Review is/))
.not.toBeInTheDocument()
expect(screen.queryByRole('link', { name: 'Scorecard Link' }))
.not.toBeInTheDocument()
})

it('links the manual review scorecard from the challenge review definition', () => {
const scorecardUrl = 'https://review.topcoder-dev.com/scorecard/hFU73Ve2XlYCK-'
mockChallengeManualReviewScorecardUrl.mockReturnValue(scorecardUrl)

renderSidebar(undefined, developmentChallenge)

expect(mockChallengeManualReviewScorecardUrl)
.toHaveBeenCalledWith(developmentChallenge)
const scorecardLink = screen.getByRole('link', { name: 'Scorecard Link' })
expect(scorecardLink)
.toHaveAttribute('href', scorecardUrl)
expect(scorecardLink)
.toHaveAttribute('target', '_blank')
expect(scorecardLink.closest('li')?.textContent)
.toContain('Manual: Scorecard Link')
expect(screen.getByRole('button', { name: 'About Manual' }))
.toBeInTheDocument()
})

it('does not attach the manual scorecard link to AI review modes', () => {
mockChallengeManualReviewScorecardUrl.mockReturnValue('https://review.topcoder-dev.com/scorecard/manual')

renderSidebar({
challengeId: challenge.id,
id: 'ai-gating-config',
instantReview: false,
mode: 'AI_GATING',
}, developmentChallenge)

expect(screen.getByText('AI Gating'))
.toBeInTheDocument()
expect(screen.queryByRole('link', { name: 'Scorecard Link' }))
.not.toBeInTheDocument()
})

it('shows AI-only review and the disabled Instant Review state', () => {
Expand Down
30 changes: 26 additions & 4 deletions src/apps/opportunities/src/components/ChallengeSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
challengeAllowsStockArt,
challengeFileTypes,
challengeForumUrl,
challengeManualReviewScorecardUrl,
challengeReviewAppUrl,
ChallengeSidebarLink,
challengeSidebarLinks,
Expand Down Expand Up @@ -77,26 +78,44 @@ interface SidebarCardProps {

interface ReviewStyleItemProps {
label: string
scorecardUrl?: string
tooltip: string
}

interface ReviewStyleSectionProps {
config?: ChallengeAiReviewConfig
loading?: boolean
manualReviewScorecardUrl?: string
unavailable?: boolean
}

/**
* Renders one review-style bullet with an accessible tooltip.
*
* @param props member-facing label and tooltip copy.
* @param props member-facing label, tooltip copy, and optional scorecard destination
* rendered as "<label>: Scorecard Link".
* @returns one review-style list item.
* @throws Does not throw.
*/
const ReviewStyleItem: FC<ReviewStyleItemProps> = props => (
<li>
<span className={styles.reviewStyleRow}>
<span>{props.label}</span>
<span>
{props.label}
{props.scorecardUrl && (
<>
{': '}
<a
className={styles.inlineAnchor}
href={props.scorecardUrl}
rel='noreferrer'
target='_blank'
>
Scorecard Link
</a>
</>
)}
</span>
<Tooltip
className={styles.reviewStyleTooltip}
content={props.tooltip}
Expand All @@ -117,13 +136,15 @@ const ReviewStyleItem: FC<ReviewStyleItemProps> = props => (

/**
* Renders development-challenge review style above challenge terms.
* Manual review links its scorecard when the challenge review definition provides one.
*
* @param props AI review configuration and request state.
* @param props AI review configuration, manual review scorecard URL, and request state.
* @returns Review mode and instant review details.
* @throws Does not throw.
*/
const ReviewStyleSection: FC<ReviewStyleSectionProps> = props => {
const reviewModeItem = getReviewStyleModeItem(props.config)
const scorecardUrl = hasAiReviewConfig(props.config) ? undefined : props.manualReviewScorecardUrl

return (
<div className={styles.infoSection}>
Expand All @@ -137,7 +158,7 @@ const ReviewStyleSection: FC<ReviewStyleSectionProps> = props => {
? <p className={styles.reviewConfigStatus}>Review configuration is unavailable.</p>
: (
<ul className={styles.reviewStyleList}>
<ReviewStyleItem {...reviewModeItem} />
<ReviewStyleItem {...reviewModeItem} scorecardUrl={scorecardUrl} />
{hasAiReviewConfig(props.config) && (
<ReviewStyleItem
{...getInstantReviewStyleItem(props.config?.instantReview === true)}
Expand Down Expand Up @@ -532,6 +553,7 @@ export const ChallengeSidebar: FC<ChallengeSidebarProps> = props => {
<ReviewStyleSection
config={props.aiReviewConfig}
loading={props.reviewStyleLoading}
manualReviewScorecardUrl={challengeManualReviewScorecardUrl(props.challenge)}
unavailable={props.reviewStyleUnavailable}
/>
)}
Expand Down
10 changes: 9 additions & 1 deletion src/apps/opportunities/src/models/opportunity.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface ChallengePhase {
id?: string
isOpen?: boolean
name: string
/** Phase type id; Challenge API reviewers reference phases by this value. */
phaseId?: string
scheduledEndDate?: string
scheduledStartDate?: string
}
Expand Down Expand Up @@ -114,9 +116,15 @@ export interface ChallengeAiReviewConfig {
mode: ChallengeAiReviewMode
}

/** Challenge API reviewer assignment used to identify AI-reviewed challenges. */
/**
* Challenge API reviewer assignment (the challenge review definition), used to identify
* AI-reviewed challenges and the manual review scorecard.
*/
export interface ChallengeReviewer {
aiWorkflowId?: string
isMemberReview?: boolean
phaseId?: string
scorecardId?: string
}

export interface ChallengeOpportunity {
Expand Down
71 changes: 71 additions & 0 deletions src/apps/opportunities/src/utils/challenge-detail.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
challengeAllowsStockArt,
challengeFileTypes,
challengeForumUrl,
challengeManualReviewScorecardId,
challengeManualReviewScorecardUrl,
challengeReviewAppUrl,
challengeScorecardUrl,
challengeSidebarLinks,
Expand Down Expand Up @@ -210,4 +212,73 @@ describe('challenge detail utilities', () => {
expect(challengeScorecardUrl(123, 'javascript:alert(1)'))
.toBeUndefined()
})

describe('manual review scorecard', () => {
const reviewPhaseId = 'aa5a3f78-79e0-4bf7-93ff-b11e8f5b398b'
const screeningPhaseId = '2d7d3d85-0b29-4989-b3b4-be7f2b1d0aa6'
const iterativeReviewPhaseId = '003a4b14-de5d-43fc-9e35-835dbeb6af1f'
const phases = [
{ id: 'screening-instance', name: 'Screening', phaseId: screeningPhaseId },
{ id: 'review-instance', name: 'Review', phaseId: reviewPhaseId },
]

it('selects the member reviewer scorecard on the Review phase', () => {
const challenge = {
id: 'manual',
name: 'Manual review',
phases,
reviewers: [
{ isMemberReview: true, phaseId: screeningPhaseId, scorecardId: 'screening-scorecard' },
{
aiWorkflowId: 'awsH45_SAST_01',
isMemberReview: false,
phaseId: reviewPhaseId,
scorecardId: 'ai-scorecard',
},
{ isMemberReview: true, phaseId: reviewPhaseId, scorecardId: ' hFU73Ve2XlYCK- ' },
],
}

expect(challengeManualReviewScorecardId(challenge))
.toBe('hFU73Ve2XlYCK-')
expect(challengeManualReviewScorecardUrl(challenge))
.toBe('https://review.topcoder-dev.com/scorecard/hFU73Ve2XlYCK-')
expect(challengeManualReviewScorecardUrl(challenge, 'https://review.example/'))
.toBe('https://review.example/scorecard/hFU73Ve2XlYCK-')
})

it('falls back to the Iterative Review member reviewer and encodes the id', () => {
expect(challengeManualReviewScorecardUrl({
id: 'f2f',
name: 'First2Finish',
phases: [{ id: 'ir-instance', name: 'Iterative Review', phaseId: iterativeReviewPhaseId }],
reviewers: [{ isMemberReview: true, phaseId: iterativeReviewPhaseId, scorecardId: 'f2f/score' }],
}))
.toBe('https://review.topcoder-dev.com/scorecard/f2f%2Fscore')
})

it('returns undefined without a manual Review phase reviewer', () => {
expect(challengeManualReviewScorecardUrl({
id: 'ai-only',
name: 'AI only',
phases,
reviewers: [{
aiWorkflowId: 'awsH45_SAST_01',
isMemberReview: false,
phaseId: reviewPhaseId,
scorecardId: 'ai-scorecard',
}],
}))
.toBeUndefined()
expect(challengeManualReviewScorecardId({
id: 'screening-only',
name: 'Screening only',
phases,
reviewers: [{ isMemberReview: true, phaseId: screeningPhaseId, scorecardId: 'screening-scorecard' }],
}))
.toBeUndefined()
expect(challengeManualReviewScorecardId({ id: 'none', name: 'No reviewers', phases }))
.toBeUndefined()
})
})
})
57 changes: 57 additions & 0 deletions src/apps/opportunities/src/utils/challenge-detail.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,63 @@ export function submissionAiReviewAppUrl(
+ `?workflowId=${encodeURIComponent(workflowId)}`
}

/** Phase names that carry the final manual review, in priority order. */
const MANUAL_REVIEW_PHASE_NAMES = ['review', 'iterative review']

/**
* Finds the scorecard configured for the challenge's manual (member) review.
*
* Reads the review definition in `challenge.reviewers`: the member reviewer on the Review
* phase wins, First2Finish-style challenges fall back to Iterative Review, and screening,
* approval, and AI workflow reviewers are ignored.
*
* @param challenge raw Challenge API detail response.
* @returns trimmed scorecard id, or undefined when no manual review scorecard is configured.
* @throws Does not throw.
*/
export function challengeManualReviewScorecardId(challenge: ChallengeOpportunity): string | undefined {
const memberReviewers = (challenge.reviewers ?? []).filter(reviewer => (
reviewer.isMemberReview === true
&& !reviewer.aiWorkflowId?.trim()
&& !!reviewer.scorecardId?.trim()
))

return MANUAL_REVIEW_PHASE_NAMES
.map(phaseName => {
const phaseIds = (challenge.phases ?? [])
.filter(phase => phase.name?.trim()
.toLowerCase() === phaseName)
.reduce<string[]>((ids, phase) => [...ids, phase.phaseId ?? '', phase.id ?? ''], [])
.filter(Boolean)
return memberReviewers
.find(reviewer => !!reviewer.phaseId && phaseIds.includes(reviewer.phaseId))
?.scorecardId
?.trim()
})
.find(Boolean)
}

/**
* Builds the public Review App scorecard page for the challenge's manual review.
*
* Used by the challenge sidebar to render the "Manual: Scorecard Link" review style.
*
* @param challenge raw Challenge API detail response.
* @param reviewAppUrl configured Review App origin, optionally overridden by tests.
* @returns absolute, safely encoded scorecard URL, or undefined without a manual review scorecard.
* @throws Does not throw.
*/
export function challengeManualReviewScorecardUrl(
challenge: ChallengeOpportunity,
reviewAppUrl: string = EnvironmentConfig.REVIEW_APP_URL
?? `https://review.${EnvironmentConfig.TC_DOMAIN}`,
): string | undefined {
const scorecardId = challengeManualReviewScorecardId(challenge)
if (!scorecardId) return undefined

return `${reviewAppUrl.replace(/\/+$/, '')}/scorecard/${encodeURIComponent(scorecardId)}`
}

/**
* Builds a member profile URL on the environment-specific Profiles app.
*
Expand Down
Loading