📊 improve student marks report panel
Browse files at this commit0b3228b547ce510485c349d527b3eef55223c9beParent: abf1dc0- feat
- 📊 improve student marks report panel
2 changed files +94 -56
src/components/marks/marks-report-view.tsxmodified+72 -44
| @@ -9,7 +9,9 @@ import { Badge } from "@/components/ui/badge"; | ||
| 9 | 9 | import { buttonVariants } from "@/components/ui/button"; |
| 10 | 10 | import { IconExternalLink } from "@/components/ui/icons"; |
| 11 | 11 | import { DataTable, DataTableEmpty } from "@/components/ui/data-table"; |
| 12 | +import { EmptyInline } from "@/components/ui/empty-inline"; | |
| 12 | 13 | import { ExamLink } from "@/components/exams/exam-link"; |
| 14 | +import { SearchableSelect } from "@/components/ui/searchable-select"; | |
| 13 | 15 | import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 14 | 16 | import { cn } from "@/lib/cn"; |
| 15 | 17 | import { examKindLabel } from "@/lib/exam-labels"; |
| @@ -27,7 +29,11 @@ function scoreWidth(mark: number | null): string { | ||
| 27 | 29 | /** How many sections we bother reading before giving up on naming one. */ |
| 28 | 30 | const MAX_SECTIONS = 3; |
| 29 | 31 | |
| 30 | -export function MarksReportView(props: { report: MarksReport; compact?: boolean }) { | |
| 32 | +export function MarksReportView(props: { | |
| 33 | + report: MarksReport; | |
| 34 | + compact?: boolean; | |
| 35 | + identity?: { name: string; studentNumber?: string | null; classes: string[] }; | |
| 36 | +}) { | |
| 31 | 37 | const t = useT(); |
| 32 | 38 | const { locale } = usePreferences(); |
| 33 | 39 | // "68,2 · Bant 3": the grade is the school's band label, and "68,2 / 3" |
| @@ -125,6 +131,10 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | ||
| 125 | 131 | const courses = props.report.courses; |
| 126 | 132 | return (id ? courses.find((c) => c.instance === id) : undefined) ?? courses[0]; |
| 127 | 133 | }); |
| 134 | + const courseOptions = createMemo(() => props.report.courses.map((block) => ({ | |
| 135 | + value: block.instance, | |
| 136 | + label: block.course.title, | |
| 137 | + }))); | |
| 128 | 138 | const columns = createMemo<ColumnDef<MarkRow>[]>(() => [ |
| 129 | 139 | { |
| 130 | 140 | accessorKey: "title", |
| @@ -166,32 +176,58 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | ||
| 166 | 176 | ]); |
| 167 | 177 | |
| 168 | 178 | return ( |
| 169 | - <div class="min-w-0 space-y-4"> | |
| 170 | - <section class="grid gap-4 rounded-lg border border-border bg-card p-4 shadow-xs sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center"> | |
| 171 | - <div> | |
| 172 | - <p class="text-xs font-medium text-muted-foreground">{t("marks.overall")}</p> | |
| 173 | - <p class={cn("mt-1 font-semibold tabular-nums", compact() ? "text-3xl" : "text-4xl")}> | |
| 174 | - {markWithGrade(props.report.overall_average, props.report.overall_grade)} | |
| 175 | - </p> | |
| 176 | - <div class="mt-3 h-2 max-w-xl overflow-hidden rounded-full bg-muted"> | |
| 177 | - <div class="h-full rounded-full bg-primary" style={{ width: scoreWidth(props.report.overall_average) }} /> | |
| 179 | + <div class="@container min-w-0 space-y-4"> | |
| 180 | + <section class="overflow-hidden rounded-lg border border-border bg-card"> | |
| 181 | + <Show when={props.identity}> | |
| 182 | + {(identity) => ( | |
| 183 | + <div class="border-b border-border bg-muted/25 px-4 py-4"> | |
| 184 | + <p class="truncate text-base font-semibold text-foreground">{identity().name}</p> | |
| 185 | + <div class="mt-2 flex flex-wrap items-center gap-1.5"> | |
| 186 | + <For each={identity().classes}> | |
| 187 | + {(className) => <Badge variant="secondary">{className}</Badge>} | |
| 188 | + </For> | |
| 189 | + <Show when={identity().studentNumber}> | |
| 190 | + <span class="text-xs tabular-nums text-muted-foreground"> | |
| 191 | + {t("roster.studentNumber")}: {identity().studentNumber} | |
| 192 | + </span> | |
| 193 | + </Show> | |
| 194 | + </div> | |
| 195 | + </div> | |
| 196 | + )} | |
| 197 | + </Show> | |
| 198 | + <div class="grid gap-4 p-4 @lg:grid-cols-[minmax(0,1fr)_auto] @lg:items-center"> | |
| 199 | + <div class="min-w-0"> | |
| 200 | + <p class="text-xs font-medium text-muted-foreground">{t("marks.overall")}</p> | |
| 201 | + <div class="mt-1 flex flex-wrap items-center gap-2"> | |
| 202 | + <p class={cn("font-semibold tabular-nums leading-none", compact() ? "text-3xl" : "text-4xl")}> | |
| 203 | + {props.report.overall_average == null ? "—" : formatDecimal(props.report.overall_average, locale())} | |
| 204 | + </p> | |
| 205 | + <Show when={props.report.overall_grade}> | |
| 206 | + <Badge variant="outline">{t("marks.bandLabel", { grade: props.report.overall_grade! })}</Badge> | |
| 207 | + </Show> | |
| 208 | + </div> | |
| 209 | + <Show when={props.report.overall_average != null}> | |
| 210 | + <div class="mt-3 h-2 max-w-xl overflow-hidden rounded-full bg-muted"> | |
| 211 | + <div class="h-full rounded-full bg-primary" style={{ width: scoreWidth(props.report.overall_average) }} /> | |
| 212 | + </div> | |
| 213 | + </Show> | |
| 178 | 214 | </div> |
| 215 | + <dl class="grid grid-cols-2 gap-2 @lg:min-w-56"> | |
| 216 | + <div class="rounded-lg bg-muted/45 p-3"> | |
| 217 | + <dt class="text-xs text-muted-foreground">{t("nav.courses")}</dt> | |
| 218 | + <dd class="mt-1 text-2xl font-semibold tabular-nums">{props.report.courses.length}</dd> | |
| 219 | + </div> | |
| 220 | + <div class="rounded-lg bg-muted/45 p-3"> | |
| 221 | + <dt class="text-xs text-muted-foreground">{t("marks.examCount")}</dt> | |
| 222 | + <dd class="mt-1 text-2xl font-semibold tabular-nums">{resultCount()}</dd> | |
| 223 | + </div> | |
| 224 | + </dl> | |
| 179 | 225 | </div> |
| 180 | - <dl class="grid grid-cols-2 gap-2 sm:min-w-56"> | |
| 181 | - <div class="rounded-xl bg-muted/45 p-3"> | |
| 182 | - <dt class="text-[11px] text-muted-foreground">{t("nav.courses")}</dt> | |
| 183 | - <dd class="mt-1 text-2xl font-semibold tabular-nums">{props.report.courses.length}</dd> | |
| 184 | - </div> | |
| 185 | - <div class="rounded-xl bg-muted/45 p-3"> | |
| 186 | - <dt class="text-[11px] text-muted-foreground">{t("exams.results")}</dt> | |
| 187 | - <dd class="mt-1 text-2xl font-semibold tabular-nums">{resultCount()}</dd> | |
| 188 | - </div> | |
| 189 | - </dl> | |
| 190 | 226 | </section> |
| 191 | 227 | |
| 192 | - <Show when={props.report.courses.length > 0} fallback={<DataTableEmpty class="rounded-lg border border-border bg-card py-10">{t("marks.empty")}</DataTableEmpty>}> | |
| 228 | + <Show when={props.report.courses.length > 0} fallback={<div class="rounded-lg border border-border bg-card p-4"><EmptyInline illustration="exams" title={t("marks.empty")} /></div>}> | |
| 193 | 229 | <Tabs value={tab()} onChange={(value) => setTab(value === "byCourse" ? "byCourse" : "general")}> |
| 194 | - <TabsList class="w-full sm:w-fit"> | |
| 230 | + <TabsList class="w-full @lg:w-fit"> | |
| 195 | 231 | <TabsTrigger value="general" class="min-w-0">{t("marks.tabGeneral")}</TabsTrigger> |
| 196 | 232 | <TabsTrigger value="byCourse" class="min-w-0">{t("marks.tabByCourse")}</TabsTrigger> |
| 197 | 233 | </TabsList> |
| @@ -210,44 +246,36 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | ||
| 210 | 246 | |
| 211 | 247 | <Show when={tab() === "byCourse"}> |
| 212 | 248 | <div class="space-y-3"> |
| 213 | - <div class="flex flex-wrap gap-1.5"> | |
| 214 | - <For each={props.report.courses}> | |
| 215 | - {(block) => ( | |
| 216 | - <button | |
| 217 | - type="button" | |
| 218 | - class={cn( | |
| 219 | - "rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors", | |
| 220 | - activeCourse()?.instance === block.instance | |
| 221 | - ? "border-border bg-surface-base text-foreground shadow-xs" | |
| 222 | - : "border-transparent text-muted-foreground hover:bg-muted/60", | |
| 223 | - )} | |
| 224 | - onClick={() => setActiveInstanceId(block.instance)} | |
| 225 | - > | |
| 226 | - {block.course.title} | |
| 227 | - </button> | |
| 228 | - )} | |
| 229 | - </For> | |
| 249 | + <div class="max-w-md space-y-1.5"> | |
| 250 | + <label for="marks-course-select" class="text-xs font-medium text-muted-foreground">{t("marks.selectCourse")}</label> | |
| 251 | + <SearchableSelect | |
| 252 | + id="marks-course-select" | |
| 253 | + value={activeCourse()?.instance ?? ""} | |
| 254 | + onChange={setActiveInstanceId} | |
| 255 | + options={courseOptions()} | |
| 256 | + placeholder={t("marks.selectCourse")} | |
| 257 | + /> | |
| 230 | 258 | </div> |
| 231 | 259 | |
| 232 | 260 | <Show when={activeCourse()} keyed> |
| 233 | 261 | {(block) => ( |
| 234 | 262 | <div class="rounded-lg border border-border bg-card p-4 shadow-xs"> |
| 235 | - <div class="flex flex-wrap items-center justify-between gap-3"> | |
| 263 | + <div class="grid gap-3 @lg:grid-cols-[minmax(0,1fr)_auto] @lg:items-start"> | |
| 236 | 264 | <div class="min-w-0"> |
| 237 | - <Link to="/courses/$id" params={{ id: block.course.id }} class="inline-flex truncate text-sm font-semibold text-primary-text hover:underline"> | |
| 265 | + <Link to="/courses/$id" params={{ id: block.course.id }} class="block truncate text-sm font-semibold text-primary-text hover:underline"> | |
| 238 | 266 | {block.course.title} |
| 239 | 267 | </Link> |
| 240 | 268 | <Link |
| 241 | 269 | to="/instances/$id" |
| 242 | 270 | params={{ id: block.instance }} |
| 243 | - class={cn(buttonVariants({ variant: "outline", size: "sm" }), "mt-1.5 h-8 max-w-full rounded-lg")} | |
| 271 | + class="mt-1.5 inline-flex max-w-full items-center gap-1.5 text-xs text-muted-foreground hover:text-primary-text hover:underline" | |
| 244 | 272 | aria-label={openAria()} |
| 245 | 273 | > |
| 246 | 274 | <IconExternalLink class="h-3.5 w-3.5 shrink-0" /> |
| 247 | 275 | <span class="truncate">{openLabel()}</span> |
| 248 | 276 | </Link> |
| 249 | 277 | </div> |
| 250 | - <div class="text-right"> | |
| 278 | + <div class="@lg:text-right"> | |
| 251 | 279 | <p class="text-[11px] font-medium uppercase tracking-wider text-muted-foreground">{t("marks.courseAvg")}</p> |
| 252 | 280 | <p class="mt-0.5 text-xl font-semibold tabular-nums">{markWithGrade(block.average, block.average_grade)}</p> |
| 253 | 281 | </div> |
| @@ -258,7 +286,7 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean | ||
| 258 | 286 | class="min-w-0" |
| 259 | 287 | columns={columns()} |
| 260 | 288 | data={block.results} |
| 261 | - tableClass={cn("w-full", compact() ? "text-xs" : "table-fixed sm:min-w-xl")} | |
| 289 | + tableClass={cn("w-full min-w-xl", compact() ? "text-xs" : "table-fixed")} | |
| 262 | 290 | enableColumnVisibility={false} |
| 263 | 291 | /> |
| 264 | 292 | </Show> |
src/pages/student-marks-page.tsxmodified+22 -12
| @@ -3,7 +3,7 @@ import { createResource } from "@/lib/create-resource"; | ||
| 3 | 3 | import type { ColumnDef } from "@tanstack/solid-table"; |
| 4 | 4 | import { getUserMarks } from "@/api/reports"; |
| 5 | 5 | import { ApiError, formatApiError } from "@/api/client"; |
| 6 | -import type { MarksReport, PersonRef } from "@/api/client"; | |
| 6 | +import type { MarksReport } from "@/api/client"; | |
| 7 | 7 | import { cn } from "@/lib/cn"; |
| 8 | 8 | import { MarksReportView } from "@/components/marks/marks-report-view"; |
| 9 | 9 | import { RouteGuard } from "@/components/layout/route-guard"; |
| @@ -16,7 +16,6 @@ import { SidePanel } from "@/components/ui/side-panel"; | ||
| 16 | 16 | import { studentDirectoryColumns } from "@/components/users/student-directory-columns"; |
| 17 | 17 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 18 | 18 | import { matchesSearch } from "@/lib/search-text"; |
| 19 | -import { personLabel } from "@/lib/person"; | |
| 20 | 19 | import { getStudentDirectory, type StudentDirectoryRow } from "@/lib/student-directory"; |
| 21 | 20 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 22 | 21 | import { formatDecimal } from "@/lib/format"; |
| @@ -38,7 +37,7 @@ const MARKS_FETCH_CAP = 200; | ||
| 38 | 37 | function StudentMarksContent() { |
| 39 | 38 | const t = useT(); |
| 40 | 39 | const { locale } = usePreferences(); |
| 41 | - const [viewUser, setViewUser] = createSignal<PersonRef | null>(null); | |
| 40 | + const [viewStudent, setViewStudent] = createSignal<StudentDirectoryRow | null>(null); | |
| 42 | 41 | const [error, setError] = createSignal(""); |
| 43 | 42 | |
| 44 | 43 | const [list] = createResource(async () => { |
| @@ -80,7 +79,7 @@ function StudentMarksContent() { | ||
| 80 | 79 | }; |
| 81 | 80 | |
| 82 | 81 | const [report, { refetch: refetchReport }] = createResource( |
| 83 | - () => viewUser()?.id ?? null, | |
| 82 | + () => viewStudent()?.person.id ?? null, | |
| 84 | 83 | async (id) => { |
| 85 | 84 | if (!id) return null; |
| 86 | 85 | try { |
| @@ -158,7 +157,7 @@ function StudentMarksContent() { | ||
| 158 | 157 | icon: <IconEye class="h-4 w-4" />, |
| 159 | 158 | onSelect: () => { |
| 160 | 159 | setError(""); |
| 161 | - setViewUser(cell.row.original.person); | |
| 160 | + setViewStudent(cell.row.original); | |
| 162 | 161 | }, |
| 163 | 162 | }, |
| 164 | 163 | ]} |
| @@ -170,7 +169,7 @@ function StudentMarksContent() { | ||
| 170 | 169 | return ( |
| 171 | 170 | <div class="space-y-6"> |
| 172 | 171 | <section class="space-y-4 p-0"> |
| 173 | - <Show when={error() && !viewUser()}> | |
| 172 | + <Show when={error() && !viewStudent()}> | |
| 174 | 173 | <Alert variant="destructive">{error()}</Alert> |
| 175 | 174 | </Show> |
| 176 | 175 | |
| @@ -190,7 +189,7 @@ function StudentMarksContent() { | ||
| 190 | 189 | storageKey="student-marks" |
| 191 | 190 | onRowClick={(row) => { |
| 192 | 191 | setError(""); |
| 193 | - setViewUser(row.person); | |
| 192 | + setViewStudent(row); | |
| 194 | 193 | }} |
| 195 | 194 | /> |
| 196 | 195 | </Show> |
| @@ -198,15 +197,14 @@ function StudentMarksContent() { | ||
| 198 | 197 | |
| 199 | 198 | <SidePanel |
| 200 | 199 | size="wide" |
| 201 | - open={viewUser() != null} | |
| 200 | + open={viewStudent() != null} | |
| 202 | 201 | onOpenChange={(open) => { |
| 203 | 202 | if (!open) { |
| 204 | - setViewUser(null); | |
| 203 | + setViewStudent(null); | |
| 205 | 204 | setError(""); |
| 206 | 205 | } |
| 207 | 206 | }} |
| 208 | - title={t("marks.forUser", { user: personLabel(viewUser()) })} | |
| 209 | - description={t("marks.lookup")} | |
| 207 | + title={t("nav.studentMarks")} | |
| 210 | 208 | > |
| 211 | 209 | <div class="min-w-0 space-y-3"> |
| 212 | 210 | <Show when={error()}> |
| @@ -215,7 +213,19 @@ function StudentMarksContent() { | ||
| 215 | 213 | <Show when={report.loading}> |
| 216 | 214 | <p class="text-sm text-muted-foreground">{t("common.loading")}</p> |
| 217 | 215 | </Show> |
| 218 | - <Show when={report()}>{(r) => <MarksReportView report={r()} compact />}</Show> | |
| 216 | + <Show when={report()?.user === viewStudent()?.person.id && viewStudent()} keyed> | |
| 217 | + {(student) => ( | |
| 218 | + <MarksReportView | |
| 219 | + report={report()!} | |
| 220 | + compact | |
| 221 | + identity={{ | |
| 222 | + name: student.person.display_name || student.person.username, | |
| 223 | + studentNumber: student.person.student_number, | |
| 224 | + classes: student.classes.map((cls) => cls.name), | |
| 225 | + }} | |
| 226 | + /> | |
| 227 | + )} | |
| 228 | + </Show> | |
| 219 | 229 | </div> |
| 220 | 230 | </SidePanel> |
| 221 | 231 | </div> |