Skip to content

Commit 9955d88

Browse files
committed
Refactoring of large hook, and various QA fixes
1 parent 67a2a6a commit 9955d88

17 files changed

+1669
-1157
lines changed

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

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ActionLoading } from '~/apps/admin/src/lib'
77

88
import { ChallengeDetailContext } from '../../contexts'
99
import {
10-
BackendPhase,
1110
BackendSubmission,
1211
ChallengeInfo,
1312
MappingReviewAppeal,
@@ -29,6 +28,7 @@ import {
2928
import { ITERATIVE_REVIEW, SUBMITTER } from '../../../config/index.config'
3029
import { TableNoRecord } from '../TableNoRecord'
3130
import { hasIsLatestFlag } from '../../utils'
31+
import { shouldIncludeInReviewPhase } from '../../utils/reviewPhaseGuards'
3232

3333
import TabContentApproval from './TabContentApproval'
3434
import TabContentCheckpoint from './TabContentCheckpoint'
@@ -47,122 +47,6 @@ const normalizeType = (value?: string): string => (
4747
: ''
4848
)
4949

50-
const resolvePhaseNameFromId = (
51-
phaseId?: string,
52-
phases?: BackendPhase[],
53-
): string | undefined => {
54-
if (!phaseId || !Array.isArray(phases)) {
55-
return undefined
56-
}
57-
58-
const normalizedPhaseId = `${phaseId}`.trim()
59-
.toLowerCase()
60-
if (!normalizedPhaseId) {
61-
return undefined
62-
}
63-
64-
const matchingPhase = phases.find(phase => {
65-
const candidates = [phase.id, phase.phaseId]
66-
67-
return candidates.some(candidate => (
68-
typeof candidate === 'string'
69-
&& candidate.trim()
70-
.toLowerCase() === normalizedPhaseId
71-
))
72-
})
73-
74-
return matchingPhase?.name
75-
}
76-
77-
const EXCLUDED_REVIEW_TYPES = [
78-
'approval',
79-
'checkpoint',
80-
'iterative',
81-
'postmortem',
82-
'screening',
83-
'specification',
84-
] as const
85-
86-
const shouldIncludeInReviewPhase = (
87-
submission?: SubmissionInfo,
88-
phases?: BackendPhase[],
89-
): boolean => {
90-
if (!submission) {
91-
return false
92-
}
93-
94-
const normalizedCandidates = new Set<string>()
95-
const registerCandidate = (candidate?: string | null): void => {
96-
if (typeof candidate !== 'string') {
97-
return
98-
}
99-
100-
const normalized = normalizeType(candidate)
101-
if (normalized) {
102-
normalizedCandidates.add(normalized)
103-
}
104-
}
105-
106-
registerCandidate(submission.reviewTypeId)
107-
registerCandidate(submission.review?.phaseName)
108-
registerCandidate(submission.review?.reviewType)
109-
registerCandidate(resolvePhaseNameFromId(submission.review?.phaseId, phases))
110-
111-
const metadata = submission.review?.metadata
112-
if (metadata && typeof metadata === 'object') {
113-
const metadataHints: unknown[] = [
114-
(metadata as { type?: unknown }).type,
115-
(metadata as { reviewType?: unknown }).reviewType,
116-
(metadata as { review_type?: unknown }).review_type,
117-
(metadata as { phase?: unknown }).phase,
118-
(metadata as { phaseName?: unknown }).phaseName,
119-
(metadata as { reviewPhase?: unknown }).reviewPhase,
120-
]
121-
122-
metadataHints.forEach(hint => {
123-
if (typeof hint === 'string') {
124-
registerCandidate(hint)
125-
}
126-
})
127-
}
128-
129-
if (!normalizedCandidates.size) {
130-
if (process.env.NODE_ENV !== 'production') {
131-
// eslint-disable-next-line no-console
132-
console.debug('[ReviewTab] shouldIncludeInReviewPhase', {
133-
normalizedCandidates: [],
134-
reviewPhaseName: submission.review?.phaseName,
135-
reviewType: submission.review?.reviewType,
136-
reviewTypeId: submission.reviewTypeId,
137-
submissionId: submission.id ?? submission.review?.submissionId,
138-
verdict: 'included (no candidates)',
139-
})
140-
}
141-
142-
return true
143-
}
144-
145-
const normalizedCandidateList = Array.from(normalizedCandidates)
146-
const isExcluded = normalizedCandidateList
147-
.some(normalizedType => (
148-
EXCLUDED_REVIEW_TYPES.some(fragment => normalizedType.includes(fragment))
149-
))
150-
151-
if (process.env.NODE_ENV !== 'production') {
152-
// eslint-disable-next-line no-console
153-
console.debug('[ReviewTab] shouldIncludeInReviewPhase', {
154-
normalizedCandidates: normalizedCandidateList,
155-
reviewPhaseName: submission.review?.phaseName,
156-
reviewType: submission.review?.reviewType,
157-
reviewTypeId: submission.reviewTypeId,
158-
submissionId: submission.id ?? submission.review?.submissionId,
159-
verdict: isExcluded ? 'excluded' : 'included',
160-
})
161-
}
162-
163-
return !isExcluded
164-
}
165-
16650
interface Props {
16751
selectedTab: string
16852
isLoadingSubmission: boolean
@@ -244,11 +128,9 @@ const renderSubmissionTab = ({
244128
}: SubmissionTabParams): JSX.Element => {
245129
const isSubmissionTab = selectedTabNormalized === 'submission'
246130
const isTopgearSubmissionTab = selectedTabNormalized === 'topgearsubmission'
247-
const shouldRestrictToContestSubmissions = isActiveChallenge
248-
&& (
249-
selectedTabNormalized.startsWith('submission')
250-
|| isTopgearSubmissionTab
251-
)
131+
const shouldRestrictToContestSubmissions = selectedTabNormalized
132+
.startsWith('submission')
133+
|| isTopgearSubmissionTab
252134
const visibleSubmissions = shouldRestrictToContestSubmissions
253135
? submissions.filter(
254136
submission => normalizeType(submission.type) === 'contestsubmission',

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

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
ChallengeDetailContext,
1616
} from '../../contexts'
1717
import {
18-
BackendPhase,
1918
BackendResource,
2019
BackendSubmission,
2120
ChallengeDetailContextModel,
@@ -38,6 +37,7 @@ import {
3837
REVIEWER,
3938
SUBMITTER,
4039
} from '../../../config/index.config'
40+
import { shouldIncludeInReviewPhase } from '../../utils/reviewPhaseGuards'
4141

4242
interface Props {
4343
selectedTab: string
@@ -316,7 +316,7 @@ export const TabContentReview: FC<Props> = (props: Props) => {
316316
const resolvedReviews = useMemo(
317317
() => {
318318
if (providedReviews.length) {
319-
return providedReviews.filter(submission => shouldDisplayOnReviewTab(
319+
return providedReviews.filter(submission => shouldIncludeInReviewPhase(
320320
submission,
321321
challengeInfo?.phases,
322322
))
@@ -339,7 +339,7 @@ export const TabContentReview: FC<Props> = (props: Props) => {
339339
},
340340
}
341341
const converted = convertBackendSubmissionToSubmissionInfo(submissionForReviewer)
342-
if (shouldDisplayOnReviewTab(converted, challengeInfo?.phases)) {
342+
if (shouldIncludeInReviewPhase(converted, challengeInfo?.phases)) {
343343
fallbackFromBackend.push(converted)
344344
}
345345
})
@@ -355,13 +355,13 @@ export const TabContentReview: FC<Props> = (props: Props) => {
355355
}
356356

357357
const fallback = challengeSubmissions.filter(hasReviewerAssignment)
358-
const filteredFallback = fallback.filter(submission => shouldDisplayOnReviewTab(
358+
const filteredFallback = fallback.filter(submission => shouldIncludeInReviewPhase(
359359
submission,
360360
challengeInfo?.phases,
361361
))
362362
return filteredFallback.length
363363
? filteredFallback
364-
: providedReviews.filter(submission => shouldDisplayOnReviewTab(
364+
: providedReviews.filter(submission => shouldIncludeInReviewPhase(
365365
submission,
366366
challengeInfo?.phases,
367367
))
@@ -404,7 +404,7 @@ export const TabContentReview: FC<Props> = (props: Props) => {
404404
return false
405405
}
406406

407-
if (!shouldDisplayOnReviewTab(submission, challengeInfo?.phases)) {
407+
if (!shouldIncludeInReviewPhase(submission, challengeInfo?.phases)) {
408408
return false
409409
}
410410

@@ -433,7 +433,7 @@ export const TabContentReview: FC<Props> = (props: Props) => {
433433
return fallback
434434
}
435435

436-
return providedSubmitterReviews.filter(submission => shouldDisplayOnReviewTab(
436+
return providedSubmitterReviews.filter(submission => shouldIncludeInReviewPhase(
437437
submission,
438438
challengeInfo?.phases,
439439
))
@@ -549,60 +549,3 @@ export const TabContentReview: FC<Props> = (props: Props) => {
549549
}
550550

551551
export default TabContentReview
552-
function normalizeReviewType(value?: string | null): string {
553-
if (!value) {
554-
return ''
555-
}
556-
557-
return value
558-
.toLowerCase()
559-
.replace(/[^a-z]/g, '')
560-
}
561-
562-
const EXCLUDED_REVIEW_TYPE_FRAGMENTS = [
563-
'approval',
564-
'checkpoint',
565-
'iterative',
566-
'postmortem',
567-
'screening',
568-
'specification',
569-
] as const
570-
571-
function shouldDisplayOnReviewTab(
572-
submission: SubmissionInfo,
573-
phases?: BackendPhase[],
574-
): boolean {
575-
const normalized = new Set<string>()
576-
const register = (candidate?: string | null): void => {
577-
const normalizedCandidate = normalizeReviewType(candidate)
578-
if (normalizedCandidate) {
579-
normalized.add(normalizedCandidate)
580-
}
581-
}
582-
583-
register(submission.reviewTypeId)
584-
register(submission.review?.reviewType)
585-
register(submission.review?.phaseName)
586-
587-
const phaseId = submission.review?.phaseId
588-
if (phaseId && phases?.length) {
589-
const normalizedPhaseId = `${phaseId}`.trim()
590-
.toLowerCase()
591-
const matchingPhase = phases.find(phase => (
592-
(phase.id && phase.id.toLowerCase() === normalizedPhaseId)
593-
|| (phase.phaseId && phase.phaseId.toLowerCase() === normalizedPhaseId)
594-
))
595-
if (matchingPhase?.name) {
596-
register(matchingPhase.name)
597-
}
598-
}
599-
600-
if (!normalized.size) {
601-
return true
602-
}
603-
604-
return !Array.from(normalized)
605-
.some(candidate => (
606-
EXCLUDED_REVIEW_TYPE_FRAGMENTS.some(fragment => candidate.includes(fragment))
607-
))
608-
}

src/apps/review/src/lib/components/TableIterativeReview/TableIterativeReview.module.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,28 @@
142142
color: var(--GrayFontColor);
143143
}
144144

145+
.resultPill {
146+
display: inline-flex;
147+
align-items: center;
148+
justify-content: center;
149+
padding: $sp-1 $sp-2;
150+
border-radius: 999px;
151+
font-size: 12px;
152+
font-weight: 700;
153+
}
154+
155+
.resultPass {
156+
@extend .resultPill;
157+
background-color: $green-25;
158+
color: $green-140;
159+
}
160+
161+
.resultFail {
162+
@extend .resultPill;
163+
background-color: $red-25;
164+
color: $red-140;
165+
}
166+
145167
.submit {
146168
align-items: center;
147169
display: flex;

0 commit comments

Comments
 (0)