From b385b4e6d67b8c526a0f4a9137d92ad5dd575e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:54:34 +0300 Subject: [PATCH] =?UTF-8?q?feat(marks):=20=F0=9F=93=8A=20inline=20overall-?= =?UTF-8?q?average=20column=20on=20manager=20student=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit managers had to open each student's side panel to see any grade; add an inline, sortable 'overall average' column (number + letter grade, color- tinted) so key marks show without drilling into detail. per-student getUserMarks fetch for the listed set, capped at 200 — mirrors the payments roster balance pattern --- src/pages/student-marks-page.tsx | 52 ++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/pages/student-marks-page.tsx b/src/pages/student-marks-page.tsx index 82a2aed..cd51a75 100644 --- a/src/pages/student-marks-page.tsx +++ b/src/pages/student-marks-page.tsx @@ -3,7 +3,8 @@ import type { ColumnDef } from "@tanstack/solid-table"; import { getUserMarks } from "@/api/reports"; import { getUserSearch } from "@/api/users"; import { ApiError, formatApiError } from "@/api/client"; -import type { PersonRef } from "@/api/client"; +import type { MarksReport, PersonRef } from "@/api/client"; +import { cn } from "@/lib/cn"; import { MarksReportView } from "@/components/marks/marks-report-view"; import { RouteGuard } from "@/components/layout/route-guard"; import { Alert } from "@/components/ui/alert"; @@ -16,6 +17,10 @@ import { personLabel } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; const PAGE_SIZE = 12; +const round = (n: number) => (Math.round(n * 100) / 100).toString(); +// ponytail: display-only color tiers (70/40 on a 0-100 scale), not a pass/fail rule +const avgTone = (v: number) => + v >= 70 ? "text-emerald-600 dark:text-emerald-400" : v >= 40 ? "text-amber-600 dark:text-amber-400" : "text-red-600 dark:text-red-400"; export default function StudentMarksPage() { return ( @@ -43,6 +48,31 @@ function StudentMarksContent() { { initialValue: [] }, ); + // Per-student overall marks for the inline "average" column. No bulk endpoint + // exists, so this is one getUserMarks call per listed student, bounded by cap. + // ponytail: N+1 marks fetch, capped at 200; add a bulk /reports/marks endpoint + // if whole-school listing is needed. Mirrors the payments roster balance fetch. + const MARKS_FETCH_CAP = 200; + const [marksMapRes] = createResource( + () => { + const ids = list().map((user) => user.id); + return ids.length > 0 && ids.length <= MARKS_FETCH_CAP ? ids : null; + }, + async (ids) => { + const pairs = await Promise.all( + ids.map(async (id) => { + try { + return [id, await getUserMarks(id)] as const; + } catch { + return [id, null] as const; + } + }), + ); + return Object.fromEntries(pairs) as Record; + }, + ); + const marksOf = (id: string) => marksMapRes()?.[id]; + const [report, { refetch: refetchReport }] = createResource( () => viewUser()?.id ?? null, async (id) => { @@ -76,6 +106,24 @@ function StudentMarksContent() { header: t("profile.name"), cell: (cell) => {cell.row.original.display_name || "—"}, }, + { + id: "average", + header: () => {t("marks.overall")}, + accessorFn: (user) => marksOf(user.id)?.overall_average ?? -1, + meta: { headerClass: "text-right", cellClass: "text-right" }, + cell: (cell) => { + const rep = marksOf(cell.row.original.id); + if (rep == null) return —; + if (rep.overall_average == null) + return {rep.overall_grade ?? "—"}; + return ( + + {round(rep.overall_average)} + {(g) => / {g()}} + + ); + }, + }, { accessorKey: "id", header: t("admin.id"), @@ -110,7 +158,7 @@ function StudentMarksContent() { {error()} - }> + }>