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
@@ -1,7 +1,7 @@
/**
* Content of checkpoint tab.
*/
import { FC, useContext, useMemo } from 'react'
import { FC, useCallback, useContext, useMemo } from 'react'

import { TableLoading } from '~/apps/admin/src/lib'
import { IsRemovingType } from '~/apps/admin/src/lib/models'
Expand Down Expand Up @@ -75,6 +75,32 @@ export const TabContentCheckpoint: FC<Props> = (props: Props) => {
[props.checkpointReview, myMemberIds, props.checkpointReviewMinimumPassingScore],
)

const checkpointScreeningOutcome = useMemo(
() => {
const passingSubmissionIds = new Set<string>()
const failingSubmissionIds = new Set<string>()

props.checkpoint.forEach(entry => {
if (!entry?.submissionId) {
return
}

const normalizedResult = (entry.result || '').toUpperCase()

Choose a reason for hiding this comment

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

[⚠️ maintainability]
Consider using a constant or enum for the screening results ('PASS', 'NO PASS') to avoid magic strings and potential typos.

if (normalizedResult === 'PASS') {
passingSubmissionIds.add(`${entry.submissionId}`)
} else if (normalizedResult === 'NO PASS') {
failingSubmissionIds.add(`${entry.submissionId}`)
}
})

return {
failingSubmissionIds,
passingSubmissionIds,
}
},
[props.checkpoint],
)

const filteredCheckpoint = useMemo<Screening[]>(
() => {
const baseRows = props.checkpoint ?? []
Expand Down Expand Up @@ -107,9 +133,15 @@ export const TabContentCheckpoint: FC<Props> = (props: Props) => {
],
)

const filterCheckpointReviewByScreeningResult = useCallback(
(screening: Screening[]) => screening
.filter(row => checkpointScreeningOutcome.passingSubmissionIds.has(`${row.submissionId}`)),
[checkpointScreeningOutcome],
)

const filteredCheckpointReview = useMemo<Screening[]>(
() => {
const baseRows = props.checkpointReview ?? []
const baseRows = filterCheckpointReviewByScreeningResult(props.checkpointReview ?? [])

if (isPrivilegedRole || (isChallengeCompleted && hasPassedCheckpointReviewThreshold)) {
return baseRows
Expand All @@ -135,6 +167,7 @@ export const TabContentCheckpoint: FC<Props> = (props: Props) => {
hasPassedCheckpointReviewThreshold,
checkpointReviewerResourceIds,
myMemberIds,
checkpointScreeningOutcome,
],
)

Expand Down
Loading