forge
Explore
Log in

Don't you dare go Hollow

📊 inline overall-average column on manager student list

Browse files at this commit

b385b4e6d67b8c526a0f4a9137d92ad5dd575e9bBurak BoduroğluParent: 7122d71
  • feat
    • 📊 inline overall-average column on manager student list
Show full message
feat(marks): 📊 inline overall-average column on manager student list

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.tsxmodified+50 -2
@@ -3,7 +3,8 @@ import type { ColumnDef } from "@tanstack/solid-table";
33 import { getUserMarks } from "@/api/reports";
44 import { getUserSearch } from "@/api/users";
55 import { ApiError, formatApiError } from "@/api/client";
6-import type { PersonRef } from "@/api/client";
6+import type { MarksReport, PersonRef } from "@/api/client";
7+import { cn } from "@/lib/cn";
78 import { MarksReportView } from "@/components/marks/marks-report-view";
89 import { RouteGuard } from "@/components/layout/route-guard";
910 import { Alert } from "@/components/ui/alert";
@@ -16,6 +17,10 @@ import { personLabel } from "@/lib/person";
1617 import { useT } from "@/stores/preferences-context";
1718
1819 const PAGE_SIZE = 12;
20+const round = (n: number) => (Math.round(n * 100) / 100).toString();
21+// ponytail: display-only color tiers (70/40 on a 0-100 scale), not a pass/fail rule
22+const avgTone = (v: number) =>
23+ 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";
1924
2025 export default function StudentMarksPage() {
2126 return (
@@ -43,6 +48,31 @@ function StudentMarksContent() {
4348 { initialValue: [] },
4449 );
4550
51+ // Per-student overall marks for the inline "average" column. No bulk endpoint
52+ // exists, so this is one getUserMarks call per listed student, bounded by cap.
53+ // ponytail: N+1 marks fetch, capped at 200; add a bulk /reports/marks endpoint
54+ // if whole-school listing is needed. Mirrors the payments roster balance fetch.
55+ const MARKS_FETCH_CAP = 200;
56+ const [marksMapRes] = createResource(
57+ () => {
58+ const ids = list().map((user) => user.id);
59+ return ids.length > 0 && ids.length <= MARKS_FETCH_CAP ? ids : null;
60+ },
61+ async (ids) => {
62+ const pairs = await Promise.all(
63+ ids.map(async (id) => {
64+ try {
65+ return [id, await getUserMarks(id)] as const;
66+ } catch {
67+ return [id, null] as const;
68+ }
69+ }),
70+ );
71+ return Object.fromEntries(pairs) as Record<string, MarksReport | null>;
72+ },
73+ );
74+ const marksOf = (id: string) => marksMapRes()?.[id];
75+
4676 const [report, { refetch: refetchReport }] = createResource(
4777 () => viewUser()?.id ?? null,
4878 async (id) => {
@@ -76,6 +106,24 @@ function StudentMarksContent() {
76106 header: t("profile.name"),
77107 cell: (cell) => <span class="text-muted-foreground">{cell.row.original.display_name || "—"}</span>,
78108 },
109+ {
110+ id: "average",
111+ header: () => <span class="block text-right">{t("marks.overall")}</span>,
112+ accessorFn: (user) => marksOf(user.id)?.overall_average ?? -1,
113+ meta: { headerClass: "text-right", cellClass: "text-right" },
114+ cell: (cell) => {
115+ const rep = marksOf(cell.row.original.id);
116+ if (rep == null) return <span class="text-sm text-muted-foreground">—</span>;
117+ if (rep.overall_average == null)
118+ return <span class="text-sm text-muted-foreground">{rep.overall_grade ?? "—"}</span>;
119+ return (
120+ <span class={cn("mono font-semibold tabular-nums", avgTone(rep.overall_average))}>
121+ {round(rep.overall_average)}
122+ <Show when={rep.overall_grade}>{(g) => <span class="ml-1 font-medium text-muted-foreground">/ {g()}</span>}</Show>
123+ </span>
124+ );
125+ },
126+ },
79127 {
80128 accessorKey: "id",
81129 header: t("admin.id"),
@@ -110,7 +158,7 @@ function StudentMarksContent() {
110158 <Alert variant="destructive">{error()}</Alert>
111159 </Show>
112160
113- <Show when={!listLoading()} fallback={<DataTableSkeleton columns={4} rows={6} />}>
161+ <Show when={!listLoading()} fallback={<DataTableSkeleton columns={5} rows={6} />}>
114162 <DataTable
115163 title={t("nav.studentMarks")}
116164 description={`${t("marks.lookup")} · ${rows().length} / ${total()}`}