-
Notifications
You must be signed in to change notification settings - Fork 21
Topgear Iterative Reviewer visibility fix #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
de6b71d
c213504
fb1cc20
6544d15
c329669
bd29900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' | ||
|
|
@@ -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 { | ||
|
|
@@ -37,6 +38,26 @@ export const PermissionGroupsPage: FC<Props> = (props: Props) => { | |
| usersMapping, | ||
| ) | ||
|
|
||
| const filteredGroups = useMemo(() => { | ||
| 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( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💡 |
||
| () => searchTerm.trim().length > 0, | ||
| [searchTerm], | ||
| ) | ||
|
|
||
| return ( | ||
| <div className={classNames(styles.container, props.className)}> | ||
| <PageTitle>{pageTitle}</PageTitle> | ||
|
|
@@ -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} | ||
| /> | ||
| )} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { ActionLoading } from '~/apps/admin/src/lib' | |
| import { ChallengeDetailContext } from '../../contexts' | ||
| import { | ||
| BackendSubmission, | ||
| ChallengeInfo, | ||
| ChallengeDetailContextModel, | ||
| MappingReviewAppeal, | ||
| Screening, | ||
| SubmissionInfo, | ||
|
|
@@ -120,6 +120,7 @@ const buildScreeningRows = ({ | |
|
|
||
| interface SubmissionTabParams { | ||
| selectedTabNormalized: string | ||
| allowTopgearSubmissionList: boolean | ||
| submissions: BackendSubmission[] | ||
| screeningRows: Screening[] | ||
| screeningMinimumPassingScore: number | null | undefined | ||
|
|
@@ -131,6 +132,7 @@ interface SubmissionTabParams { | |
|
|
||
| const renderSubmissionTab = ({ | ||
| selectedTabNormalized, | ||
| allowTopgearSubmissionList, | ||
| submissions, | ||
| screeningRows, | ||
| screeningMinimumPassingScore, | ||
|
|
@@ -149,7 +151,7 @@ const renderSubmissionTab = ({ | |
| submission => normalizeType(submission.type) === 'contestsubmission', | ||
| ) | ||
| : submissions | ||
| const canShowSubmissionList = !isTopgearSubmissionTab | ||
| const canShowSubmissionList = (allowTopgearSubmissionList || !isTopgearSubmissionTab) | ||
| && selectedTabNormalized !== 'screening' | ||
| && visibleSubmissions.length > 0 | ||
|
|
||
|
|
@@ -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( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💡 |
||
| resource => resource.roleName | ||
| ?.toLowerCase() | ||
| .includes('iterative reviewer'), | ||
| ), | ||
| [myResources], | ||
| ) | ||
| const allowTopgearSubmissionList = useMemo( | ||
| () => actionChallengeRole !== SUBMITTER || hasIterativeReviewerRole, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [💡 |
||
| [actionChallengeRole, hasIterativeReviewerRole], | ||
| ) | ||
| const { currentMemberId }: UseSubmissionDownloadAccessResult = useSubmissionDownloadAccess() | ||
| const { | ||
| isLoading: isDownloadingSubmission, | ||
|
|
@@ -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, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[⚠️
correctness]Using
useMemoforfilteredGroupsis appropriate to avoid unnecessary recalculations, but ensure thatgroupsis not being mutated elsewhere in the component, as it could lead to unexpected results.