Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"sass": "^1.79.0",
"styled-components": "^5.3.6",
"swr": "^1.3.0",
"tc-auth-lib": "topcoder-platform/tc-auth-lib#1.0.27",
"tc-auth-lib": "topcoder-platform/tc-auth-lib#master",
"tinymce": "^7.9.1",
"typescript": "^4.8.4",
"universal-navigation": "https://github.com/topcoder-platform/universal-navigation#9fc50d938be7182",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,29 @@
text-align: center;
}

.btnNewGroup {
margin: $sp-8 $sp-8 $sp-4 $sp-8;
.actions {
display: flex;
align-items: flex-end;
gap: $sp-4;
margin: $sp-8 $sp-8 $sp-4;

@include ltelg {
flex-direction: column;
align-items: stretch;
margin: $sp-4;
gap: $sp-3;
}
}

.searchField {
flex: 1;
}

.btnNewGroup {
margin: 0;
min-width: max-content;

@include ltelg {
width: 100%;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Permission groups page.
*/
import { FC, useContext, useState } from 'react'
import { ChangeEvent, FC, useContext, useMemo, useState } from 'react'
import classNames from 'classnames'

import { Button, LoadingSpinner, PageTitle } from '~/libs/ui'
import { Button, InputText, LoadingSpinner, PageTitle } from '~/libs/ui'
import { PlusIcon } from '@heroicons/react/solid'

import { DialogAddGroup } from '../../lib/components/DialogAddGroup'
Expand All @@ -24,6 +24,7 @@ const pageTitle = 'Groups'

export const PermissionGroupsPage: FC<Props> = (props: Props) => {
const [openDialogAddGroup, setOpenDialogAddGroup] = useState(false)
const [searchTerm, setSearchTerm] = useState('')
const { loadUser, cancelLoadUser, usersMapping }: AdminAppContextType
= useContext(AdminAppContext)
const {
Expand All @@ -37,6 +38,26 @@ export const PermissionGroupsPage: FC<Props> = (props: Props) => {
usersMapping,
)

const filteredGroups = useMemo(() => {

Choose a reason for hiding this comment

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

[⚠️ correctness]
Using useMemo for filteredGroups is appropriate to avoid unnecessary recalculations, but ensure that groups is not being mutated elsewhere in the component, as it could lead to unexpected results.

const normalized = searchTerm
.trim()
.toLowerCase()
if (!normalized) {
return groups
}

return groups.filter(group => {
const id = group.id ? group.id.toLowerCase() : ''
const name = group.name ? group.name.toLowerCase() : ''

return id.includes(normalized) || name.includes(normalized)
})
}, [groups, searchTerm])
const hasSearchTerm = useMemo(

Choose a reason for hiding this comment

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

[💡 performance]
The useMemo for hasSearchTerm is not necessary here since the computation is trivial. Removing it could simplify the code without impacting performance.

() => searchTerm.trim().length > 0,
[searchTerm],
)

return (
<div className={classNames(styles.container, props.className)}>
<PageTitle>{pageTitle}</PageTitle>
Expand All @@ -51,24 +72,40 @@ export const PermissionGroupsPage: FC<Props> = (props: Props) => {
</div>
) : (
<>
<Button
primary
size='lg'
icon={PlusIcon}
iconToLeft
label='new group'
onClick={function onClick() {
setOpenDialogAddGroup(true)
}}
className={styles.btnNewGroup}
/>
{groups.length === 0 ? (
<div className={styles.actions}>
<InputText
name='groupSearch'
type='text'
label='Search groups'
placeholder='Search by name or ID'
value={searchTerm}
onChange={function onChange(event: ChangeEvent<HTMLInputElement>) {
setSearchTerm(event.target.value)
}}
forceUpdateValue
classNameWrapper={styles.searchField}
/>
<Button
primary
size='lg'
icon={PlusIcon}
iconToLeft
label='new group'
onClick={function onClick() {
setOpenDialogAddGroup(true)
}}
className={styles.btnNewGroup}
/>
</div>
{filteredGroups.length === 0 ? (
<p className={styles.noRecordFound}>
{MSG_NO_RECORD_FOUND}
{hasSearchTerm
? 'No groups match your search.'
: MSG_NO_RECORD_FOUND}
</p>
) : (
<GroupsTable
datas={groups}
datas={filteredGroups}
usersMapping={usersMapping}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ActionLoading } from '~/apps/admin/src/lib'
import { ChallengeDetailContext } from '../../contexts'
import {
BackendSubmission,
ChallengeInfo,
ChallengeDetailContextModel,
MappingReviewAppeal,
Screening,
SubmissionInfo,
Expand Down Expand Up @@ -120,6 +120,7 @@ const buildScreeningRows = ({

interface SubmissionTabParams {
selectedTabNormalized: string
allowTopgearSubmissionList: boolean
submissions: BackendSubmission[]
screeningRows: Screening[]
screeningMinimumPassingScore: number | null | undefined
Expand All @@ -131,6 +132,7 @@ interface SubmissionTabParams {

const renderSubmissionTab = ({
selectedTabNormalized,
allowTopgearSubmissionList,
submissions,
screeningRows,
screeningMinimumPassingScore,
Expand All @@ -149,7 +151,7 @@ const renderSubmissionTab = ({
submission => normalizeType(submission.type) === 'contestsubmission',
)
: submissions
const canShowSubmissionList = !isTopgearSubmissionTab
const canShowSubmissionList = (allowTopgearSubmissionList || !isTopgearSubmissionTab)
&& selectedTabNormalized !== 'screening'
&& visibleSubmissions.length > 0

Expand Down Expand Up @@ -178,8 +180,23 @@ const renderSubmissionTab = ({
}

export const ChallengeDetailsContent: FC<Props> = (props: Props) => {
const { challengeInfo }: { challengeInfo?: ChallengeInfo } = useContext(ChallengeDetailContext)
const {
challengeInfo,
myResources,
}: ChallengeDetailContextModel = useContext(ChallengeDetailContext)
const { actionChallengeRole }: useRoleProps = useRole()
const hasIterativeReviewerRole = useMemo(
() => myResources.some(

Choose a reason for hiding this comment

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

[💡 performance]
The useMemo hook is used to compute hasIterativeReviewerRole, but the computation is straightforward and not computationally expensive. Consider removing useMemo to simplify the code unless there's a specific performance concern.

resource => resource.roleName
?.toLowerCase()
.includes('iterative reviewer'),
),
[myResources],
)
const allowTopgearSubmissionList = useMemo(
() => actionChallengeRole !== SUBMITTER || hasIterativeReviewerRole,

Choose a reason for hiding this comment

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

[💡 performance]
The useMemo hook is used here to determine allowTopgearSubmissionList, but the logic is simple and doesn't involve heavy computation. Consider removing useMemo to simplify the code unless there's a specific performance concern.

[actionChallengeRole, hasIterativeReviewerRole],
)
const { currentMemberId }: UseSubmissionDownloadAccessResult = useSubmissionDownloadAccess()
const {
isLoading: isDownloadingSubmission,
Expand Down Expand Up @@ -364,6 +381,7 @@ export const ChallengeDetailsContent: FC<Props> = (props: Props) => {

if (SUBMISSION_TAB_KEYS.has(selectedTabNormalized)) {
return renderSubmissionTab({
allowTopgearSubmissionList,
downloadSubmission: handleSubmissionDownload,
isActiveChallenge: props.isActiveChallenge,
isDownloadingSubmission,
Expand Down
Loading