@@ -18,9 +18,10 @@ import {
1818 ChallengeDetailContextModel ,
1919 ChallengeInfo ,
2020 MappingReviewAppeal ,
21+ ReviewAppContextModel ,
2122 SubmissionInfo ,
2223} from '../../models'
23- import { ChallengeDetailContext } from '../../contexts'
24+ import { ChallengeDetailContext , ReviewAppContext } from '../../contexts'
2425import { TableWrapper } from '../TableWrapper'
2526import { SubmissionHistoryModal } from '../SubmissionHistoryModal'
2627import {
@@ -85,6 +86,7 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
8586 const downloadSubmission : ( submissionId : string ) => void = props . downloadSubmission
8687 const isDownloading : IsRemovingType = props . isDownloading
8788 const mappingReviewAppeal : MappingReviewAppeal = props . mappingReviewAppeal
89+ const { loginUserInfo } : ReviewAppContextModel = useContext ( ReviewAppContext )
8890 const {
8991 challengeInfo,
9092 reviewers,
@@ -100,6 +102,7 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
100102 } : UseSubmissionDownloadAccessResult = downloadAccess
101103 const {
102104 ownedMemberIds : ownedMemberIdsFromRole ,
105+ canViewAllSubmissions,
103106 } : UseRolePermissionsResult = useRolePermissions ( )
104107 const ownedMemberIds = useMemo < Set < string > > ( ( ) => {
105108 if ( ownedMemberIdsFromRole . size ) {
@@ -257,6 +260,31 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
257260 [ challengeInfo ] ,
258261 )
259262
263+ const isCompletedDesignChallenge = useMemo ( ( ) => {
264+ if ( ! challengeInfo ) return false
265+ const type = challengeInfo . track . name ? String ( challengeInfo . track . name )
266+ . toLowerCase ( ) : ''
267+ const status = challengeInfo . status ? String ( challengeInfo . status )
268+ . toLowerCase ( ) : ''
269+ return type === 'design' && (
270+ status === 'completed'
271+ )
272+ } , [ challengeInfo ] )
273+
274+ const isSubmissionsViewable = useMemo ( ( ) => {
275+ if ( ! challengeInfo ?. metadata ?. length ) return false
276+ return challengeInfo . metadata . some ( m => m . name === 'submissionsViewable' && String ( m . value )
277+ . toLowerCase ( ) === 'true' )
278+ } , [ challengeInfo ] )
279+
280+ const canViewSubmissions = useMemo ( ( ) => {
281+ if ( isCompletedDesignChallenge ) {
282+ return canViewAllSubmissions || isSubmissionsViewable
283+ }
284+
285+ return true
286+ } , [ isCompletedDesignChallenge , isSubmissionsViewable , canViewAllSubmissions ] )
287+
260288 const {
261289 canDisplayScores,
262290 isChallengeCompleted,
@@ -282,12 +310,21 @@ export const TableReviewForSubmitter: FC<TableReviewForSubmitterProps> = (props:
282310 [ mappingReviewAppeal , reviewers , submissionsForAggregation ] ,
283311 )
284312
313+ const filterFunc = useCallback ( ( submissions : SubmissionRow [ ] ) : SubmissionRow [ ] => submissions
314+ . filter ( submission => {
315+ if ( ! canViewSubmissions ) {
316+ return String ( submission . memberId ) === String ( loginUserInfo ?. userId )
317+ }
318+
319+ return true
320+ } ) , [ canViewSubmissions , loginUserInfo ?. userId ] )
321+
285322 const aggregatedSubmissionRows = useMemo < SubmissionRow [ ] > (
286- ( ) => aggregatedRows . map ( row => ( {
323+ ( ) => filterFunc ( aggregatedRows . map ( row => ( {
287324 ...row . submission ,
288325 aggregated : row ,
289- } ) ) ,
290- [ aggregatedRows ] ,
326+ } ) ) ) ,
327+ [ aggregatedRows , filterFunc , canViewSubmissions , loginUserInfo ?. userId ] ,
291328 )
292329
293330 const scorecardIds = useMemo < Set < string > > ( ( ) => {
0 commit comments