Skip to content

Commit 67a2a6a

Browse files
committed
Phase display fixes to match phase restrictions in review-api-v6
1 parent 27ec4b4 commit 67a2a6a

File tree

4 files changed

+43
-251
lines changed

4 files changed

+43
-251
lines changed

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

Lines changed: 19 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
/**
22
* Tab content for submissions during the submission phase.
33
*/
4-
import {
5-
FC,
6-
MouseEvent,
7-
useCallback,
8-
useContext,
9-
useMemo,
10-
useState,
11-
} from 'react'
4+
import { FC, MouseEvent, useContext, useMemo } from 'react'
125
import { toast } from 'react-toastify'
136
import _ from 'lodash'
147
import classNames from 'classnames'
@@ -21,7 +14,6 @@ import { MobileTableColumn } from '~/apps/admin/src/lib/models/MobileTableColumn
2114
import { copyTextToClipboard, useWindowSize, WindowSize } from '~/libs/shared'
2215
import { IconOutline, Table, TableColumn, Tooltip } from '~/libs/ui'
2316

24-
import { SubmissionHistoryModal } from '../SubmissionHistoryModal'
2517
import {
2618
BackendSubmission,
2719
ChallengeDetailContextModel,
@@ -35,7 +27,6 @@ import type { UseSubmissionDownloadAccessResult } from '../../hooks/useSubmissio
3527
import { ChallengeDetailContext } from '../../contexts'
3628
import {
3729
challengeHasSubmissionLimit,
38-
getSubmissionHistoryKey,
3930
hasIsLatestFlag,
4031
partitionSubmissionHistory,
4132
} from '../../utils'
@@ -66,26 +57,7 @@ export const TabContentSubmissions: FC<Props> = props => {
6657
getRestrictionMessageForMember,
6758
}: UseSubmissionDownloadAccessResult = useSubmissionDownloadAccess()
6859

69-
const {
70-
challengeInfo,
71-
myResources,
72-
}: ChallengeDetailContextModel = useContext(ChallengeDetailContext)
73-
74-
const ownedMemberIds = useMemo<Set<string>>(
75-
() => {
76-
const ids = new Set<string>()
77-
myResources.forEach(resource => {
78-
const memberId = resource?.memberId
79-
if (memberId === undefined || memberId === null) {
80-
return
81-
}
82-
83-
ids.add(String(memberId))
84-
})
85-
return ids
86-
},
87-
[myResources],
88-
)
60+
const { challengeInfo }: ChallengeDetailContextModel = useContext(ChallengeDetailContext)
8961

9062
const submissionMetaById = useMemo(
9163
() => {
@@ -109,11 +81,7 @@ export const TabContentSubmissions: FC<Props> = props => {
10981
() => partitionSubmissionHistory(submissionInfos, submissionInfos),
11082
[submissionInfos],
11183
)
112-
const {
113-
historyByMember,
114-
latestSubmissionIds,
115-
latestSubmissions,
116-
}: SubmissionHistoryPartition = submissionHistory
84+
const { latestSubmissions }: SubmissionHistoryPartition = submissionHistory
11785

11886
const latestBackendSubmissions = useMemo<BackendSubmission[]>(
11987
() => latestSubmissions
@@ -127,14 +95,14 @@ export const TabContentSubmissions: FC<Props> = props => {
12795
[challengeInfo],
12896
)
12997

130-
const shouldShowHistoryActions = useMemo(
98+
const hasLatestFlag = useMemo(
13199
() => hasIsLatestFlag(props.submissions),
132100
[props.submissions],
133101
)
134102

135103
const filteredSubmissions = useMemo<BackendSubmission[]>(
136104
() => {
137-
if (restrictToLatest && shouldShowHistoryActions) {
105+
if (restrictToLatest && hasLatestFlag) {
138106
return latestBackendSubmissions.length
139107
? latestBackendSubmissions
140108
: props.submissions
@@ -146,106 +114,10 @@ export const TabContentSubmissions: FC<Props> = props => {
146114
latestBackendSubmissions,
147115
props.submissions,
148116
restrictToLatest,
149-
shouldShowHistoryActions,
117+
hasLatestFlag,
150118
],
151119
)
152120

153-
const [historyKey, setHistoryKey] = useState<string | undefined>(undefined)
154-
155-
const openHistoryModal = useCallback(
156-
(memberId: string | undefined, submissionId: string): void => {
157-
const key = getSubmissionHistoryKey(memberId, submissionId)
158-
const entries = historyByMember.get(key)
159-
if (!entries || entries.length === 0) {
160-
return
161-
}
162-
163-
setHistoryKey(key)
164-
},
165-
[historyByMember],
166-
)
167-
168-
const closeHistoryModal = useCallback((): void => {
169-
setHistoryKey(undefined)
170-
}, [])
171-
172-
const historyEntriesForModal = useMemo<SubmissionInfo[]>(
173-
() => {
174-
if (!historyKey) {
175-
return []
176-
}
177-
178-
const entries = historyByMember.get(historyKey) ?? []
179-
if (!entries.length) {
180-
return []
181-
}
182-
183-
return entries.map(entry => {
184-
if (!entry?.id) {
185-
return entry
186-
}
187-
188-
const meta = submissionMetaById.get(entry.id)
189-
if (!meta) {
190-
return entry
191-
}
192-
193-
const metaInfo = convertBackendSubmissionToSubmissionInfo(meta)
194-
return {
195-
...metaInfo,
196-
...entry,
197-
userInfo: entry.userInfo ?? metaInfo.userInfo,
198-
}
199-
})
200-
},
201-
[historyByMember, historyKey, submissionMetaById],
202-
)
203-
204-
const getSubmissionMeta = useCallback(
205-
(submissionId: string): SubmissionInfo | undefined => {
206-
const submission = submissionMetaById.get(submissionId)
207-
return submission
208-
? convertBackendSubmissionToSubmissionInfo(submission)
209-
: undefined
210-
},
211-
[submissionMetaById],
212-
)
213-
214-
const getHistoryRestriction = useCallback(
215-
(submission: SubmissionInfo): { restricted: boolean; message?: string } => {
216-
const restrictedForMember = isSubmissionDownloadRestrictedForMember(submission.memberId)
217-
const message = restrictedForMember
218-
? getRestrictionMessageForMember(submission.memberId) ?? restrictionMessage
219-
: undefined
220-
221-
return {
222-
message,
223-
restricted: restrictedForMember,
224-
}
225-
},
226-
[
227-
getRestrictionMessageForMember,
228-
isSubmissionDownloadRestrictedForMember,
229-
restrictionMessage,
230-
],
231-
)
232-
233-
const handleHistoryButtonClick = useCallback(
234-
(event: MouseEvent<HTMLButtonElement>): void => {
235-
const submissionId = event.currentTarget.dataset.submissionId
236-
if (!submissionId) {
237-
return
238-
}
239-
240-
const memberIdValue = event.currentTarget.dataset.memberId
241-
const normalizedMemberId = memberIdValue && memberIdValue.length ? memberIdValue : undefined
242-
openHistoryModal(normalizedMemberId, submissionId)
243-
},
244-
[openHistoryModal],
245-
)
246-
247-
const isHistoryModalOpen = Boolean(historyKey)
248-
249121
const columns = useMemo<TableColumn<BackendSubmission>[]>(
250122
() => {
251123
const baseColumns: TableColumn<BackendSubmission>[] = [
@@ -369,62 +241,12 @@ export const TabContentSubmissions: FC<Props> = props => {
369241
},
370242
]
371243

372-
if (shouldShowHistoryActions) {
373-
baseColumns.push({
374-
label: 'Actions',
375-
propertyName: 'actions',
376-
renderer: (submission: BackendSubmission) => {
377-
if (!submission.id) {
378-
return <span>--</span>
379-
}
380-
381-
const isLatestSubmission = latestSubmissionIds.has(submission.id)
382-
if (!isLatestSubmission) {
383-
return <span>--</span>
384-
}
385-
386-
const ownsSubmission = ownedMemberIds.has(String(submission.memberId))
387-
if (!ownsSubmission) {
388-
return <span>--</span>
389-
}
390-
391-
const historyKeyValue = getSubmissionHistoryKey(submission.memberId, submission.id)
392-
const entries = historyByMember.get(historyKeyValue) ?? []
393-
const relevantHistory = entries.filter(
394-
historyEntry => historyEntry.id && historyEntry.id !== submission.id,
395-
)
396-
397-
if (!relevantHistory.length) {
398-
return <span>--</span>
399-
}
400-
401-
return (
402-
<button
403-
type='button'
404-
className={styles.textBlue}
405-
data-member-id={submission.memberId}
406-
data-submission-id={submission.id}
407-
onClick={handleHistoryButtonClick}
408-
>
409-
View Submission History
410-
</button>
411-
)
412-
},
413-
type: 'element',
414-
})
415-
}
416-
417244
return baseColumns
418245
},
419246
[
420247
getRestrictionMessageForMember,
421-
handleHistoryButtonClick,
422-
historyByMember,
423248
isSubmissionDownloadRestrictedForMember,
424-
latestSubmissionIds,
425-
ownedMemberIds,
426249
restrictionMessage,
427-
shouldShowHistoryActions,
428250
props.downloadSubmission,
429251
props.isDownloading,
430252
],
@@ -464,30 +286,19 @@ export const TabContentSubmissions: FC<Props> = props => {
464286
}
465287

466288
return (
467-
<>
468-
<TableWrapper className={classNames(styles.container, 'enhanced-table')}>
469-
{isTablet ? (
470-
<TableMobile columns={columnsMobile} data={filteredSubmissions} />
471-
) : (
472-
<Table
473-
columns={columns}
474-
data={filteredSubmissions}
475-
disableSorting
476-
onToggleSort={_.noop}
477-
removeDefaultSort
478-
/>
479-
)}
480-
</TableWrapper>
481-
<SubmissionHistoryModal
482-
open={isHistoryModalOpen}
483-
onClose={closeHistoryModal}
484-
submissions={historyEntriesForModal}
485-
downloadSubmission={props.downloadSubmission}
486-
isDownloading={props.isDownloading}
487-
getRestriction={getHistoryRestriction}
488-
getSubmissionMeta={getSubmissionMeta}
489-
/>
490-
</>
289+
<TableWrapper className={classNames(styles.container, 'enhanced-table')}>
290+
{isTablet ? (
291+
<TableMobile columns={columnsMobile} data={filteredSubmissions} />
292+
) : (
293+
<Table
294+
columns={columns}
295+
data={filteredSubmissions}
296+
disableSorting
297+
onToggleSort={_.noop}
298+
removeDefaultSort
299+
/>
300+
)}
301+
</TableWrapper>
491302
)
492303
}
493304

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const TableAppealsResponse: FC<TableAppealsResponseProps> = (props: Table
105105
const canViewAsReviewer = hasReviewerRole
106106
const canViewAsSubmitter = hasSubmitterRole
107107
const canRender = canViewAllAppeals || canViewAsReviewer || canViewAsSubmitter
108+
const canRespondToAppeals = hasReviewerRole
108109

109110
const isAppealsResponsePhaseOpen = useMemo<boolean>(
110111
() => (challengeInfo?.phases ?? []).some(phase => phase?.name?.toLowerCase() === 'appeals response'
@@ -137,6 +138,18 @@ export const TableAppealsResponse: FC<TableAppealsResponseProps> = (props: Table
137138
],
138139
)
139140

141+
const normalizedChallengeStatus = useMemo<string>(
142+
() => (challengeInfo?.status ?? '')
143+
.trim()
144+
.toUpperCase(),
145+
[challengeInfo?.status],
146+
)
147+
148+
const submitterCanViewAllRows = useMemo<boolean>(
149+
() => normalizedChallengeStatus.startsWith('COMPLETED'),
150+
[normalizedChallengeStatus],
151+
)
152+
140153
const submissionTypes = useMemo<Set<string>>(
141154
() => new Set<string>(
142155
datas
@@ -224,6 +237,10 @@ export const TableAppealsResponse: FC<TableAppealsResponseProps> = (props: Table
224237
return aggregatedRows
225238
}
226239

240+
if (canViewAsSubmitter && submitterCanViewAllRows) {
241+
return aggregatedRows
242+
}
243+
227244
const matchesSubmitter = (row: SubmissionRow): boolean => {
228245
if (!canViewAsSubmitter) {
229246
return false
@@ -260,6 +277,7 @@ export const TableAppealsResponse: FC<TableAppealsResponseProps> = (props: Table
260277
canViewAsSubmitter,
261278
myReviewerResourceIds,
262279
ownedMemberIds,
280+
submitterCanViewAllRows,
263281
])
264282

265283
const maxReviewCount = useMemo<number>(
@@ -401,7 +419,7 @@ export const TableAppealsResponse: FC<TableAppealsResponseProps> = (props: Table
401419
}
402420
}
403421

404-
if (isAppealsResponsePhaseOpen) {
422+
if (isAppealsResponsePhaseOpen && canRespondToAppeals) {
405423
baseColumns.push({
406424
columnId: 'actions',
407425
label: 'Actions',
@@ -465,6 +483,7 @@ export const TableAppealsResponse: FC<TableAppealsResponseProps> = (props: Table
465483
allowsAppeals,
466484
downloadButtonConfig,
467485
hideHandleColumn,
486+
canRespondToAppeals,
468487
isAppealsResponsePhaseOpen,
469488
maxReviewCount,
470489
scoreVisibilityConfig,

src/apps/review/src/lib/components/common/TableColumnRenderers.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ export function renderReviewScoreCell(
224224
canDisplayScores,
225225
canViewScorecard,
226226
viewOwnScorecardTooltip = VIEW_OWN_SCORECARD_TOOLTIP,
227-
isAppealsTab,
228-
getReviewUrl,
229227
}: ScoreVisibilityConfig = configWithDefaults
230228

231229
if (!canDisplayScores(submission)) {
@@ -283,22 +281,6 @@ export function renderReviewScoreCell(
283281
)
284282
}
285283

286-
if (isAppealsTab) {
287-
const reviewDetail = submission.aggregated?.reviews?.[0]
288-
const reviewId = reviewDetail?.reviewInfo?.id || reviewDetail?.reviewId
289-
if (reviewId) {
290-
const reviewUrl = getReviewUrl ? getReviewUrl(reviewId) : getReviewRoute(reviewId)
291-
return (
292-
<Link
293-
to={reviewUrl}
294-
className={styles.textBlue}
295-
>
296-
{rawScoreDisplay}
297-
</Link>
298-
)
299-
}
300-
}
301-
302284
return <span>{rawScoreDisplay}</span>
303285
}
304286

0 commit comments

Comments
 (0)