@@ -7,7 +7,6 @@ import { ActionLoading } from '~/apps/admin/src/lib'
77
88import { ChallengeDetailContext } from '../../contexts'
99import {
10- BackendPhase ,
1110 BackendSubmission ,
1211 ChallengeInfo ,
1312 MappingReviewAppeal ,
@@ -29,6 +28,7 @@ import {
2928import { ITERATIVE_REVIEW , SUBMITTER } from '../../../config/index.config'
3029import { TableNoRecord } from '../TableNoRecord'
3130import { hasIsLatestFlag } from '../../utils'
31+ import { shouldIncludeInReviewPhase } from '../../utils/reviewPhaseGuards'
3232
3333import TabContentApproval from './TabContentApproval'
3434import 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-
16650interface 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' ,
0 commit comments