Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import {
ChallengeDetailContextModel,
ChallengeInfo,
MappingReviewAppeal,
ReviewAppContextModel,
SubmissionInfo,
} from '../../models'
import { ChallengeDetailContext } from '../../contexts'
import { ChallengeDetailContext, ReviewAppContext } from '../../contexts'
import { TableWrapper } from '../TableWrapper'
import { SubmissionHistoryModal } from '../SubmissionHistoryModal'
import {
Expand Down Expand Up @@ -85,6 +86,7 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
const downloadSubmission: (submissionId: string) => void = props.downloadSubmission
const isDownloading: IsRemovingType = props.isDownloading
const mappingReviewAppeal: MappingReviewAppeal = props.mappingReviewAppeal
const { loginUserInfo }: ReviewAppContextModel = useContext(ReviewAppContext)
const {
challengeInfo,
reviewers,
Expand All @@ -100,6 +102,7 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
}: UseSubmissionDownloadAccessResult = downloadAccess
const {
ownedMemberIds: ownedMemberIdsFromRole,
canViewAllSubmissions,
}: UseRolePermissionsResult = useRolePermissions()
const ownedMemberIds = useMemo<Set<string>>(() => {
if (ownedMemberIdsFromRole.size) {
Expand Down Expand Up @@ -257,6 +260,31 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
[challengeInfo],
)

const isCompletedDesignChallenge = useMemo(() => {
if (!challengeInfo) return false
const type = challengeInfo.track.name ? String(challengeInfo.track.name)
.toLowerCase() : ''
const status = challengeInfo.status ? String(challengeInfo.status)
.toLowerCase() : ''
return type === 'design' && (
status === 'completed'
)
}, [challengeInfo])

const isSubmissionsViewable = useMemo(() => {
if (!challengeInfo?.metadata?.length) return false
return challengeInfo.metadata.some(m => m.name === 'submissionsViewable' && String(m.value)
.toLowerCase() === 'true')
}, [challengeInfo])

const canViewSubmissions = useMemo(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 readability]
The canViewSubmissions logic could be simplified by directly returning the result of the condition without the if statement. This would improve readability.

if (isCompletedDesignChallenge) {
return canViewAllSubmissions || isSubmissionsViewable
}

return true
}, [isCompletedDesignChallenge, isSubmissionsViewable, canViewAllSubmissions])

const {
canDisplayScores,
isChallengeCompleted,
Expand All @@ -282,12 +310,21 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
[mappingReviewAppeal, reviewers, submissionsForAggregation],
)

const filterFunc = useCallback((submissions: SubmissionRow[]): SubmissionRow[] => submissions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The useCallback hook is used here, which is appropriate for memoizing the filterFunc function. However, ensure that the dependencies [canViewSubmissions, loginUserInfo?.userId] are correct and complete. If any other variables from the outer scope are used within filterFunc, they should be included in the dependency array to prevent stale closures.

.filter(submission => {
if (!canViewSubmissions) {
return String(submission.memberId) === String(loginUserInfo?.userId)
}

return true
}), [canViewSubmissions, loginUserInfo?.userId])

const aggregatedSubmissionRows = useMemo<SubmissionRow[]>(
() => aggregatedRows.map(row => ({
() => filterFunc(aggregatedRows.map(row => ({
...row.submission,
aggregated: row,
})),
[aggregatedRows],
}))),
[aggregatedRows, filterFunc, canViewSubmissions, loginUserInfo?.userId],
)

const scorecardIds = useMemo<Set<string>>(() => {
Expand Down
Loading