-
Notifications
You must be signed in to change notification settings - Fork 21
Fix 2446 #1268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 2446 #1268
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,6 @@ import { | |
| aggregateSubmissionReviews, | ||
| challengeHasSubmissionLimit, | ||
| isReviewPhase, | ||
| isReviewPhaseCurrentlyOpen, | ||
| refreshChallengeReviewData, | ||
| REOPEN_MESSAGE_OTHER, | ||
| REOPEN_MESSAGE_SELF, | ||
|
|
@@ -85,69 +84,6 @@ type RestrictionResult = { | |
| message?: string | ||
| } | ||
|
|
||
| function createReopenActionButtons( | ||
| challengeInfo: ChallengeDetailContextModel['challengeInfo'], | ||
| submission: SubmissionRow, | ||
| aggregatedReviews: AggregatedReviewDetail[] | undefined, | ||
| { | ||
| canManageCompletedReviews, | ||
| isReopening, | ||
| openReopenDialog, | ||
| pendingReopen, | ||
| }: { | ||
| canManageCompletedReviews: boolean | ||
| isReopening: boolean | ||
| openReopenDialog: (submission: SubmissionRow, review: AggregatedReviewDetail) => void | ||
| pendingReopen: PendingReopenState | undefined | ||
| }, | ||
| ): JSX.Element[] { | ||
| if (!canManageCompletedReviews) { | ||
| return [] | ||
| } | ||
|
|
||
| const buttons: JSX.Element[] = [] | ||
| const reviews = aggregatedReviews ?? [] | ||
|
|
||
| reviews.forEach(review => { | ||
| const reviewInfo = review.reviewInfo | ||
| if (!reviewInfo?.id) { | ||
| return | ||
| } | ||
|
|
||
| if ((reviewInfo.status ?? '').toUpperCase() !== 'COMPLETED') { | ||
| return | ||
| } | ||
|
|
||
| if (!isReviewPhaseCurrentlyOpen(challengeInfo, reviewInfo.phaseId)) { | ||
| return | ||
| } | ||
|
|
||
| const isTargetReview = pendingReopen?.review?.reviewInfo?.id === reviewInfo.id | ||
|
|
||
| function handleReopenClick(): void { | ||
| openReopenDialog(submission, { | ||
| ...review, | ||
| reviewInfo, | ||
| } as AggregatedReviewDetail) | ||
| } | ||
|
|
||
| buttons.push( | ||
| <button | ||
| key={`reopen-${reviewInfo.id}`} | ||
| type='button' | ||
| className={classNames(styles.actionButton, styles.textBlue)} | ||
| onClick={handleReopenClick} | ||
| disabled={isReopening && isTargetReview} | ||
| > | ||
| <i className='icon-reopen' /> | ||
| Reopen review | ||
| </button>, | ||
| ) | ||
| }) | ||
|
|
||
| return buttons | ||
| } | ||
|
|
||
| export const TableReview: FC<TableReviewProps> = (props: TableReviewProps) => { | ||
| const className: string | undefined = props.className | ||
| const datas: SubmissionInfo[] = props.datas | ||
|
|
@@ -493,20 +429,6 @@ export const TableReview: FC<TableReviewProps> = (props: TableReviewProps) => { | |
| } | ||
|
|
||
| appendAction(buildPrimaryAction(), 'primary') | ||
|
|
||
| const reopenButtons = createReopenActionButtons( | ||
| challengeInfo, | ||
| submission, | ||
| reviews, | ||
| { | ||
| canManageCompletedReviews, | ||
| isReopening, | ||
| openReopenDialog, | ||
| pendingReopen, | ||
| }, | ||
| ) | ||
|
|
||
| reopenButtons.forEach(button => appendAction(button, 'reopen')) | ||
| appendAction(buildHistoryAction(), 'history') | ||
|
|
||
| if (!actionEntries.length) { | ||
|
|
@@ -536,16 +458,11 @@ export const TableReview: FC<TableReviewProps> = (props: TableReviewProps) => { | |
| </span> | ||
| ) | ||
| }, [ | ||
| canManageCompletedReviews, | ||
| canViewHistory, | ||
| challengeInfo, | ||
| handleHistoryButtonClick, | ||
| hasReviewRole, | ||
| historyByMember, | ||
| isReopening, | ||
| myReviewerResourceIds, | ||
| openReopenDialog, | ||
| pendingReopen, | ||
| shouldShowHistoryActions, | ||
| ]) | ||
|
|
||
|
|
@@ -600,7 +517,16 @@ export const TableReview: FC<TableReviewProps> = (props: TableReviewProps) => { | |
| { | ||
| columnId: `score-${index}`, | ||
| label: `Score ${index + 1}`, | ||
| renderer: (submission: SubmissionRow) => renderScoreCell(submission, index, scoreVisibilityConfig), | ||
| renderer: (submission: SubmissionRow) => renderScoreCell( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| submission, | ||
| index, | ||
| scoreVisibilityConfig, | ||
| challengeInfo, | ||
| pendingReopen, | ||
| canManageCompletedReviews, | ||
| isReopening, | ||
| openReopenDialog, | ||
| ), | ||
| type: 'element', | ||
| }, | ||
| ) | ||
|
|
@@ -624,6 +550,11 @@ export const TableReview: FC<TableReviewProps> = (props: TableReviewProps) => { | |
| renderActionsCell, | ||
| scoreVisibilityConfig, | ||
| shouldShowAggregatedActions, | ||
| canManageCompletedReviews, | ||
| isReopening, | ||
| openReopenDialog, | ||
| challengeInfo, | ||
| pendingReopen, | ||
| ]) | ||
|
|
||
| const columnsMobile = useMemo<MobileTableColumn<SubmissionRow>[][]>( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,16 @@ import { | |
| VIRUS_SCAN_FAILED_MESSAGE, | ||
| } from '../../utils/constants' | ||
| import { getReviewRoute } from '../../utils/routes' | ||
| import { ChallengeDetailContextModel, ChallengeInfo } from '../../models' | ||
| import { isReviewPhaseCurrentlyOpen } from '../../utils' | ||
|
|
||
| import { | ||
| formatScoreDisplay, | ||
| getHandleColor, | ||
| getProfileUrl, | ||
| } from './columnUtils' | ||
| import type { | ||
| AggregatedReviewDetail, | ||
| DownloadButtonConfig, | ||
| ScoreVisibilityConfig, | ||
| SubmissionRow, | ||
|
|
@@ -301,13 +304,88 @@ export function renderReviewerCell( | |
| ) | ||
| } | ||
|
|
||
| interface PendingReopenState { | ||
| review?: AggregatedReviewDetail | ||
| submission?: SubmissionRow | ||
| isOwnReview?: boolean | ||
| } | ||
|
|
||
| function createReopenActionButtons( | ||
| challengeInfo: ChallengeDetailContextModel['challengeInfo'], | ||
| submission: SubmissionRow, | ||
| aggregatedReviews: AggregatedReviewDetail[] | undefined, | ||
| { | ||
| canManageCompletedReviews, | ||
| isReopening, | ||
| openReopenDialog, | ||
| pendingReopen, | ||
| }: { | ||
| canManageCompletedReviews: boolean | ||
| isReopening: boolean | ||
| openReopenDialog: (submission: SubmissionRow, review: AggregatedReviewDetail) => void | ||
| pendingReopen: PendingReopenState | undefined | ||
| }, | ||
| ): JSX.Element[] { | ||
| if (!canManageCompletedReviews) { | ||
| return [] | ||
| } | ||
|
|
||
| const buttons: JSX.Element[] = [] | ||
| const reviews = aggregatedReviews ?? [] | ||
|
|
||
| reviews.forEach(review => { | ||
| const reviewInfo = review.reviewInfo | ||
| if (!reviewInfo?.id) { | ||
| return | ||
| } | ||
|
|
||
| if ((reviewInfo.status ?? '').toUpperCase() !== 'COMPLETED') { | ||
| return | ||
| } | ||
|
|
||
| if (!isReviewPhaseCurrentlyOpen(challengeInfo, reviewInfo.phaseId)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| return | ||
| } | ||
|
|
||
| const isTargetReview = pendingReopen?.review?.reviewInfo?.id === reviewInfo.id | ||
|
|
||
| function handleReopenClick(): void { | ||
| openReopenDialog(submission, { | ||
| ...review, | ||
| reviewInfo, | ||
| } as AggregatedReviewDetail) | ||
| } | ||
|
|
||
| buttons.push( | ||
| // eslint-disable-next-line jsx-a11y/control-has-associated-label | ||
| <button | ||
| key={`reopen-${reviewInfo.id}`} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| type='button' | ||
| className={classNames(styles.actionButton, styles.textBlue)} | ||
| onClick={handleReopenClick} | ||
| disabled={isReopening && isTargetReview} | ||
| title='Reopen review' | ||
| > | ||
| <i className='icon-reopen' /> | ||
| </button>, | ||
| ) | ||
| }) | ||
|
|
||
| return buttons | ||
| } | ||
|
|
||
| /** | ||
| * Renders an individual review score, linking to the review detail when allowed. | ||
| */ | ||
| export function renderScoreCell( | ||
| submission: SubmissionRow, | ||
| reviewIndex: number, | ||
| config: ScoreVisibilityConfig, | ||
| challengeInfo?: ChallengeInfo | undefined, | ||
| pendingReopen?: PendingReopenState | undefined, | ||
| canManageCompletedReviews?: boolean, | ||
| isReopening?: boolean, | ||
| openReopenDialog?: (submission: SubmissionRow, review: AggregatedReviewDetail) => void, | ||
| ): JSX.Element { | ||
| const configWithDefaults: ScoreVisibilityConfig = config | ||
| const { | ||
|
|
@@ -349,6 +427,20 @@ export function renderScoreCell( | |
| const formattedScore = formatScoreDisplay(reviewDetail.finalScore) | ||
| const scoreLabel = formattedScore ?? '--' | ||
|
|
||
| const reopenButtons = createReopenActionButtons( | ||
| challengeInfo, | ||
| submission, | ||
| [reviewDetail], // pass single review in an array | ||
| { | ||
| canManageCompletedReviews: !!canManageCompletedReviews, | ||
| isReopening: !!isReopening, | ||
| openReopenDialog: openReopenDialog as (submission: SubmissionRow, review: AggregatedReviewDetail) => void, | ||
| pendingReopen, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| }, | ||
| ) | ||
|
|
||
| const reopenButton = reopenButtons.length ? reopenButtons[0] : undefined | ||
|
|
||
| if (!canViewScorecard) { | ||
| return ( | ||
| <Tooltip | ||
|
|
@@ -367,13 +459,18 @@ export function renderScoreCell( | |
| const reviewUrl = getReviewUrl ? getReviewUrl(reviewId) : getReviewRoute(reviewId) | ||
|
|
||
| return ( | ||
| <Link | ||
| to={reviewUrl} | ||
| className={styles.textBlue} | ||
| > | ||
| {scoreLabel} | ||
| </Link> | ||
| <div className={styles.scoreReopenBlock}> | ||
| <Link | ||
| to={reviewUrl} | ||
| className={styles.textBlue} | ||
| > | ||
| {scoreLabel} | ||
|
|
||
| </Link> | ||
| <span>{reopenButton}</span> | ||
| </div> | ||
| ) | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗
security]Using
replaceto convert newlines to<br>tags could lead to unexpected behavior ifcommentItem.contentcontains HTML or special characters. Consider using a library likeDOMPurifyto sanitize the content before rendering it as HTML to prevent XSS vulnerabilities.