-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(fe): replace data table admin component to new components (2) (
#2177) * refactor(fe): refactor participant table * refactor(fe): refactor contest submission table * refactor(fe): refactor user score table and user submission table * chore(fe): fix width style * chore(fe): fix fallback ui * chore(fe): remove unnecessary components
- Loading branch information
Showing
21 changed files
with
279 additions
and
1,366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/frontend/app/admin/contest/[id]/(overall)/@tabs/_components/ParticipantTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use client' | ||
|
||
import DataTable from '@/app/admin/_components/table/DataTable' | ||
import DataTableFallback from '@/app/admin/_components/table/DataTableFallback' | ||
import DataTablePagination from '@/app/admin/_components/table/DataTablePagination' | ||
import DataTableRoot from '@/app/admin/_components/table/DataTableRoot' | ||
import DataTableSearchBar from '@/app/admin/_components/table/DataTableSearchBar' | ||
import { Skeleton } from '@/components/ui/skeleton' | ||
import { GET_CONTEST_SCORE_SUMMARIES } from '@/graphql/contest/queries' | ||
import { GET_CONTEST_PROBLEMS } from '@/graphql/problem/queries' | ||
import { useSuspenseQuery } from '@apollo/client' | ||
import { createColumns } from './Columns' | ||
|
||
export function ParticipantTable({ contestId }: { contestId: number }) { | ||
const summaries = useSuspenseQuery(GET_CONTEST_SCORE_SUMMARIES, { | ||
variables: { contestId, take: 300 } | ||
}) | ||
const summariesData = summaries.data.getContestScoreSummaries.map((item) => ({ | ||
...item, | ||
id: item.userId | ||
})) | ||
|
||
const problems = useSuspenseQuery(GET_CONTEST_PROBLEMS, { | ||
variables: { groupId: 1, contestId } | ||
}) | ||
|
||
const problemData = problems.data.getContestProblems | ||
.slice() | ||
.sort((a, b) => a.order - b.order) | ||
|
||
return ( | ||
<div> | ||
<p className="mb-3 font-medium"> | ||
<span className="text-primary font-bold">{summariesData.length}</span>{' '} | ||
Participants | ||
</p> | ||
<DataTableRoot data={summariesData} columns={createColumns(problemData)}> | ||
<DataTableSearchBar columndId="realName" placeholder="Search Name" /> | ||
<DataTable | ||
getHref={(data) => | ||
`/admin/contest/${contestId}/participant/${data.id}` | ||
} | ||
/> | ||
<DataTablePagination /> | ||
</DataTableRoot> | ||
</div> | ||
) | ||
} | ||
|
||
export function ParticipantTableFallback() { | ||
return ( | ||
<div> | ||
<Skeleton className="mb-3 h-[24px] w-2/12" /> | ||
<DataTableFallback columns={createColumns([])} /> | ||
</div> | ||
) | ||
} |
72 changes: 9 additions & 63 deletions
72
apps/frontend/app/admin/contest/[id]/(overall)/@tabs/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,13 @@ | ||
'use client' | ||
|
||
import { DataTableAdmin } from '@/components/DataTableAdmin' | ||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area' | ||
import { Skeleton } from '@/components/ui/skeleton' | ||
import { GET_CONTEST_SCORE_SUMMARIES } from '@/graphql/contest/queries' | ||
import { GET_CONTEST_PROBLEMS } from '@/graphql/problem/queries' | ||
import { useQuery } from '@apollo/client' | ||
import { useParams } from 'next/navigation' | ||
import type { ScoreSummary, ProblemData } from '../../../utils' | ||
import { columns } from './_components/Columns' | ||
|
||
export default function Submission() { | ||
const { id } = useParams() | ||
|
||
const summaries = useQuery(GET_CONTEST_SCORE_SUMMARIES, { | ||
variables: { contestId: Number(id), take: 300 } | ||
}) | ||
const summariesData = summaries.data?.getContestScoreSummaries | ||
const summariesLoading = summaries.loading | ||
|
||
const problems = | ||
useQuery(GET_CONTEST_PROBLEMS, { | ||
variables: { groupId: 1, contestId: Number(id) } | ||
}) || [] | ||
const problemData = problems.data?.getContestProblems | ||
.slice() | ||
.sort((a, b) => a.order - b.order) | ||
const problemLoading = problems.loading | ||
import { Suspense } from 'react' | ||
import { | ||
ParticipantTable, | ||
ParticipantTableFallback | ||
} from './_components/ParticipantTable' | ||
|
||
export default function Submission({ params }: { params: { id: string } }) { | ||
return ( | ||
<div> | ||
{summariesLoading || problemLoading ? ( | ||
<> | ||
<div className="mb-16 flex gap-4"> | ||
<span className="w-2/12"> | ||
<Skeleton className="h-10 w-full" /> | ||
</span> | ||
</div> | ||
{[...Array(8)].map((_, i) => ( | ||
<Skeleton key={i} className="my-2 flex h-12 w-full rounded-xl" /> | ||
))} | ||
</> | ||
) : ( | ||
<> | ||
<p className="mb-3 font-medium"> | ||
<span className="text-primary font-bold"> | ||
{summariesData?.length} | ||
</span>{' '} | ||
Participants | ||
</p> | ||
<ScrollArea> | ||
<DataTableAdmin | ||
columns={columns(problemData as ProblemData[])} | ||
data={summariesData as ScoreSummary[]} | ||
enableSearch={true} | ||
searchColumn="realName" | ||
enablePagination={true} | ||
/> | ||
<div className="mt-6" /> | ||
<ScrollBar orientation="horizontal" /> | ||
</ScrollArea> | ||
</> | ||
)} | ||
</div> | ||
<Suspense fallback={<ParticipantTableFallback />}> | ||
<ParticipantTable contestId={Number(params.id)} /> | ||
</Suspense> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
62 changes: 62 additions & 0 deletions
62
...rontend/app/admin/contest/[id]/(overall)/@tabs/submission/_components/SubmissionTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use client' | ||
|
||
import DataTable from '@/app/admin/_components/table/DataTable' | ||
import DataTableFallback from '@/app/admin/_components/table/DataTableFallback' | ||
import DataTablePagination from '@/app/admin/_components/table/DataTablePagination' | ||
import DataTableProblemFilter from '@/app/admin/_components/table/DataTableProblemFilter' | ||
import DataTableRoot from '@/app/admin/_components/table/DataTableRoot' | ||
import DataTableSearchBar from '@/app/admin/_components/table/DataTableSearchBar' | ||
import { Dialog, DialogContent } from '@/components/ui/dialog' | ||
import { GET_CONTEST_SUBMISSIONS } from '@/graphql/submission/queries' | ||
import { useSuspenseQuery } from '@apollo/client' | ||
import { useState } from 'react' | ||
import { columns } from './Columns' | ||
import SubmissionDetailAdmin from './SubmissionDetailAdmin' | ||
|
||
export function SubmissionTable({ contestId }: { contestId: number }) { | ||
const { data } = useSuspenseQuery(GET_CONTEST_SUBMISSIONS, { | ||
variables: { | ||
input: { | ||
contestId | ||
}, | ||
take: 1000 | ||
} | ||
}) | ||
|
||
const [isSubmissionDialogOpen, setIsSubmissionDialogOpen] = useState(false) | ||
const [submissionId, setSubmissionId] = useState(0) | ||
|
||
return ( | ||
<> | ||
<DataTableRoot | ||
data={data.getContestSubmissions} | ||
columns={columns} | ||
defaultSortState={[{ id: 'submissionTime', desc: true }]} | ||
> | ||
<div className="flex gap-4"> | ||
<DataTableSearchBar columndId="realname" /> | ||
<DataTableProblemFilter contestId={contestId} /> | ||
</div> | ||
<DataTable | ||
onRowClick={(_, row) => { | ||
setSubmissionId(row.original.id) | ||
setIsSubmissionDialogOpen(true) | ||
}} | ||
/> | ||
<DataTablePagination /> | ||
</DataTableRoot> | ||
<Dialog | ||
open={isSubmissionDialogOpen} | ||
onOpenChange={setIsSubmissionDialogOpen} | ||
> | ||
<DialogContent className="max-h-[620px] max-w-[800px] justify-center"> | ||
<SubmissionDetailAdmin submissionId={submissionId} /> | ||
</DialogContent> | ||
</Dialog> | ||
</> | ||
) | ||
} | ||
|
||
export function SubmissionTableFallback() { | ||
return <DataTableFallback columns={columns} /> | ||
} |
54 changes: 9 additions & 45 deletions
54
apps/frontend/app/admin/contest/[id]/(overall)/@tabs/submission/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,13 @@ | ||
'use client' | ||
import { Suspense } from 'react' | ||
import { | ||
SubmissionTable, | ||
SubmissionTableFallback | ||
} from './_components/SubmissionTable' | ||
|
||
import type { OverallSubmission } from '@/app/admin/contest/utils' | ||
import { DataTableAdmin } from '@/components/DataTableAdmin' | ||
import { Skeleton } from '@/components/ui/skeleton' | ||
import { GET_CONTEST_SUBMISSIONS } from '@/graphql/submission/queries' | ||
import { useQuery } from '@apollo/client' | ||
import { useParams } from 'next/navigation' | ||
import { columns } from './_components/Columns' | ||
|
||
export default function Submission() { | ||
const { id } = useParams() | ||
const { data, loading } = useQuery(GET_CONTEST_SUBMISSIONS, { | ||
variables: { | ||
input: { | ||
contestId: Number(id) | ||
}, | ||
take: 5000 | ||
} | ||
}) | ||
const submissions = data?.getContestSubmissions || [] | ||
export default function Submission({ params }: { params: { id: string } }) { | ||
return ( | ||
<div> | ||
{loading ? ( | ||
<> | ||
<div className="mb-16 flex gap-4"> | ||
<span className="w-2/12"> | ||
<Skeleton className="h-10 w-full" /> | ||
</span> | ||
</div> | ||
{[...Array(8)].map((_, i) => ( | ||
<Skeleton key={i} className="my-2 flex h-12 w-full rounded-xl" /> | ||
))} | ||
</> | ||
) : ( | ||
<DataTableAdmin | ||
columns={columns} | ||
data={submissions as OverallSubmission[]} | ||
enableSearch={true} | ||
searchColumn="realname" | ||
enablePagination={true} | ||
enableFilter={true} | ||
enableProblemFilter={true} | ||
defaultSortColumn={{ id: 'submissionTime', desc: true }} | ||
/> | ||
)} | ||
</div> | ||
<Suspense fallback={<SubmissionTableFallback />}> | ||
<SubmissionTable contestId={Number(params.id)} /> | ||
</Suspense> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.