Skip to content

Commit

Permalink
feat(fe): add major realName studentId in submission modal (#2206)
Browse files Browse the repository at this point in the history
* feat(fe): add major realName studentId in submission modal

* feat(fe): specify whether testcase is sample or hidden

* feat(fe): add test summary
  • Loading branch information
B0XERCAT authored Nov 16, 2024
1 parent f332c3c commit b68322c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
<ScrollArea className="mt-5 max-h-[540px] w-[760px]">
<ScrollArea className="mt-5 max-h-[760px] w-[1000px]">
{!loading && (
<div className="ml-20 flex w-[612px] flex-col gap-4">
<div className="mx-14 flex flex-col gap-4">
<h1 className="flex text-lg font-semibold">
<span className="max-w-[30%] truncate text-gray-400">
{submission?.user?.userProfile?.realName}(
Expand All @@ -46,7 +85,21 @@ export default function SubmissionDetailAdmin({
<ScrollArea className="max-w-full shrink-0 rounded-md">
<div className="flex items-center justify-around gap-5 bg-gray-100 p-5 text-xs [&>div]:flex [&>div]:flex-col [&>div]:items-center [&>div]:gap-1 [&_*]:whitespace-nowrap [&_p]:text-slate-400">
<div>
<h2>User</h2>
<h2>Name</h2>
<p>{submission?.user?.userProfile?.realName}</p>
</div>
<div>
<h2>Student ID</h2>
<p>{submission?.user?.studentId}</p>
</div>
<div>
<h2>Major</h2>
<p className="max-w-[20ch] truncate">
{submission?.user?.major}
</p>
</div>
<div>
<h2>User ID</h2>
<p>{submission?.user?.username}</p>
</div>
<div>
Expand Down Expand Up @@ -75,6 +128,27 @@ export default function SubmissionDetailAdmin({
{submission?.testcaseResult.length !== 0 && (
<div>
<h2 className="font-bold">Testcase</h2>
<table>
<tbody className="text-sm font-light">
<tr>
<td className="w-52 py-1">Correct Testcase:</td>
<td className="py-1 text-slate-500">
{correctTestcases.length}/
{testcaseData?.getProblem?.testcase?.length || 0}
</td>
</tr>
{wrongTestcases.length > 0 && (
<tr>
<td className="w-52 py-1 align-top">
Wrong Testcase Number:
</td>
<td className="py-1 text-slate-500">
{wrongTestcases.join(', ') || 'None'}
</td>
</tr>
)}
</tbody>
</table>
<Table className="[&_*]:text-center [&_*]:text-xs [&_*]:hover:bg-transparent [&_td]:p-2 [&_tr]:!border-neutral-200">
<TableHeader>
<TableRow>
Expand All @@ -91,22 +165,39 @@ export default function SubmissionDetailAdmin({
</TableRow>
</TableHeader>
<TableBody className="text-slate-400">
{submission?.testcaseResult.map((item) => (
<TableRow key={item.id}>
<TableCell className="!py-4">{item.id}</TableCell>
<TableCell className={getResultColor(item.result)}>
{item.result}
</TableCell>
<TableCell>{item.cpuTime} ms</TableCell>
<TableCell>
{(
(item?.memoryUsage as number) /
(1024 * 1024)
).toFixed(2)}{' '}
MB
</TableCell>
</TableRow>
))}
{(() => {
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 (
<TableRow key={testcase.id}>
<TableCell className="!py-4">{label}</TableCell>
<TableCell
className={getResultColor(matchingResult?.result)}
>
{matchingResult?.result || 'N/A'}
</TableCell>
<TableCell>
{matchingResult?.cpuTime || 'N/A'} ms
</TableCell>
<TableCell>
{matchingResult?.memoryUsage
? `${(matchingResult.memoryUsage / (1024 * 1024)).toFixed(2)} MB`
: 'N/A'}
</TableCell>
</TableRow>
)
}
)
})()}
</TableBody>
</Table>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function SubmissionTable({ contestId }: { contestId: number }) {
open={isSubmissionDialogOpen}
onOpenChange={setIsSubmissionDialogOpen}
>
<DialogContent className="max-h-[620px] max-w-[800px] justify-center">
<DialogContent className="max-h-[840px] max-w-[1000px] justify-center">
<SubmissionDetailAdmin submissionId={submissionId} />
</DialogContent>
</Dialog>
Expand Down
17 changes: 16 additions & 1 deletion apps/frontend/graphql/problem/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions apps/frontend/graphql/submission/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const GET_SUBMISSION = gql(`query GetSubmission(
user {
id
studentId
major
username
userProfile {
realName
Expand Down

0 comments on commit b68322c

Please sign in to comment.