From b68322cb87b2822abcc6d17816ee420191986476 Mon Sep 17 00:00:00 2001 From: Kwon Seo Jin <97675977+B0XERCAT@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:52:22 +0900 Subject: [PATCH] feat(fe): add major realName studentId in submission modal (#2206) * feat(fe): add major realName studentId in submission modal * feat(fe): specify whether testcase is sample or hidden * feat(fe): add test summary --- .../_components/SubmissionDetailAdmin.tsx | 131 +++++++++++++++--- .../_components/SubmissionTable.tsx | 2 +- apps/frontend/graphql/problem/queries.ts | 17 ++- apps/frontend/graphql/submission/queries.ts | 1 + 4 files changed, 129 insertions(+), 22 deletions(-) diff --git a/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionDetailAdmin.tsx b/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionDetailAdmin.tsx index 37c42c9d76..a18aa4ef83 100644 --- a/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionDetailAdmin.tsx +++ b/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionDetailAdmin.tsx @@ -10,10 +10,11 @@ import { TableHeader, TableRow } from '@/components/shadcn/table' +import { GET_PROBLEM_TESTCASE } from '@/graphql/problem/queries' import { GET_SUBMISSION } from '@/graphql/submission/queries' import { dateFormatter, getResultColor } from '@/lib/utils' import type { Language } from '@/types/type' -import { useQuery } from '@apollo/client' +import { useLazyQuery, useQuery } from '@apollo/client' export default function SubmissionDetailAdmin({ submissionId @@ -23,13 +24,51 @@ export default function SubmissionDetailAdmin({ const { data, loading } = useQuery(GET_SUBMISSION, { variables: { id: Number(submissionId) + }, + onCompleted: (data) => { + if (data?.getSubmission?.problemId) { + fetchTestcase({ + variables: { groupId: 1, id: data.getSubmission.problemId } + }) + } } }) const submission = data?.getSubmission + + const [fetchTestcase, { data: testcaseData }] = + useLazyQuery(GET_PROBLEM_TESTCASE) + + const { correctTestcases, wrongTestcases } = (() => { + if (!testcaseData?.getProblem?.testcase || !submission?.testcaseResult) { + return { correctTestcases: [], wrongTestcases: [] } + } + + let sampleIndex = 1 + let hiddenIndex = 1 + + const correct: string[] = [] + const wrong: string[] = [] + + testcaseData.getProblem.testcase.forEach((testcase, index) => { + const label = testcase.isHidden + ? `Hidden #${hiddenIndex++}` + : `Sample #${sampleIndex++}` + const matchingResult = submission.testcaseResult[index] + + if (matchingResult?.result === 'Accepted') { + correct.push(label) + } else { + wrong.push(label) + } + }) + + return { correctTestcases: correct, wrongTestcases: wrong } + })() + return ( - + {!loading && ( -
+

{submission?.user?.userProfile?.realName}( @@ -46,7 +85,21 @@ export default function SubmissionDetailAdmin({
-

User

+

Name

+

{submission?.user?.userProfile?.realName}

+
+
+

Student ID

+

{submission?.user?.studentId}

+
+
+

Major

+

+ {submission?.user?.major} +

+
+
+

User ID

{submission?.user?.username}

@@ -75,6 +128,27 @@ export default function SubmissionDetailAdmin({ {submission?.testcaseResult.length !== 0 && (

Testcase

+ + + + + + + {wrongTestcases.length > 0 && ( + + + + + )} + +
Correct Testcase: + {correctTestcases.length}/ + {testcaseData?.getProblem?.testcase?.length || 0} +
+ Wrong Testcase Number: + + {wrongTestcases.join(', ') || 'None'} +
@@ -91,22 +165,39 @@ export default function SubmissionDetailAdmin({ - {submission?.testcaseResult.map((item) => ( - - {item.id} - - {item.result} - - {item.cpuTime} ms - - {( - (item?.memoryUsage as number) / - (1024 * 1024) - ).toFixed(2)}{' '} - MB - - - ))} + {(() => { + let sampleIndex = 1 + let hiddenIndex = 1 + + return testcaseData?.getProblem?.testcase?.map( + (testcase, index) => { + const matchingResult = submission?.testcaseResult[index] + + const label = testcase.isHidden + ? `Hidden #${hiddenIndex++}` + : `Sample #${sampleIndex++}` + + return ( + + {label} + + {matchingResult?.result || 'N/A'} + + + {matchingResult?.cpuTime || 'N/A'} ms + + + {matchingResult?.memoryUsage + ? `${(matchingResult.memoryUsage / (1024 * 1024)).toFixed(2)} MB` + : 'N/A'} + + + ) + } + ) + })()}
diff --git a/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionTable.tsx b/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionTable.tsx index 863f328477..a76aabfc6f 100644 --- a/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionTable.tsx +++ b/apps/frontend/app/admin/contest/[contestId]/(overall)/@tabs/submission/_components/SubmissionTable.tsx @@ -49,7 +49,7 @@ export function SubmissionTable({ contestId }: { contestId: number }) { open={isSubmissionDialogOpen} onOpenChange={setIsSubmissionDialogOpen} > - + diff --git a/apps/frontend/graphql/problem/queries.ts b/apps/frontend/graphql/problem/queries.ts index 42ab44a8fe..33fa3e8945 100644 --- a/apps/frontend/graphql/problem/queries.ts +++ b/apps/frontend/graphql/problem/queries.ts @@ -97,10 +97,25 @@ const GET_TAGS = gql(` } `) +const GET_PROBLEM_TESTCASE = gql(` + query GetProblemTestcase($groupId: Int!, $id: Int!) { + getProblem(groupId: $groupId, id: $id) { + testcase { + id + input + output + isHidden + scoreWeight + } + } + } +`) + export { GET_PROBLEM, GET_PROBLEMS, GET_PROBLEM_DETAIL, GET_CONTEST_PROBLEMS, - GET_TAGS + GET_TAGS, + GET_PROBLEM_TESTCASE } diff --git a/apps/frontend/graphql/submission/queries.ts b/apps/frontend/graphql/submission/queries.ts index 2b25bffb94..8e299de71e 100644 --- a/apps/frontend/graphql/submission/queries.ts +++ b/apps/frontend/graphql/submission/queries.ts @@ -73,6 +73,7 @@ const GET_SUBMISSION = gql(`query GetSubmission( user { id studentId + major username userProfile { realName