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";
3 import { getUserMarks } from "@/api/reports";3 import { getUserMarks } from "@/api/reports";
4 import { getUserSearch } from "@/api/users";4 import { getUserSearch } from "@/api/users";
5 import { ApiError, formatApiError } from "@/api/client";5 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";
7 import { MarksReportView } from "@/components/marks/marks-report-view";8 import { MarksReportView } from "@/components/marks/marks-report-view";
8 import { RouteGuard } from "@/components/layout/route-guard";9 import { RouteGuard } from "@/components/layout/route-guard";
9 import { Alert } from "@/components/ui/alert";10 import { Alert } from "@/components/ui/alert";
@@ -16,6 +17,10 @@ import { personLabel } from "@/lib/person";
16 import { useT } from "@/stores/preferences-context";17 import { useT } from "@/stores/preferences-context";
17 18
18 const PAGE_SIZE = 12;19 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";
19 24
20 export default function StudentMarksPage() {25 export default function StudentMarksPage() {
21 return (26 return (
@@ -43,6 +48,31 @@ function StudentMarksContent() {
43 { initialValue: [] },48 { initialValue: [] },
44 );49 );
45 50
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+
46 const [report, { refetch: refetchReport }] = createResource(76 const [report, { refetch: refetchReport }] = createResource(
47 () => viewUser()?.id ?? null,77 () => viewUser()?.id ?? null,
48 async (id) => {78 async (id) => {
@@ -76,6 +106,24 @@ function StudentMarksContent() {
76 header: t("profile.name"),106 header: t("profile.name"),
77 cell: (cell) => <span class="text-muted-foreground">{cell.row.original.display_name || "—"}</span>,107 cell: (cell) => <span class="text-muted-foreground">{cell.row.original.display_name || "—"}</span>,
78 },108 },
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+ },
79 {127 {
80 accessorKey: "id",128 accessorKey: "id",
81 header: t("admin.id"),129 header: t("admin.id"),
@@ -110,7 +158,7 @@ function StudentMarksContent() {
110 <Alert variant="destructive">{error()}</Alert>158 <Alert variant="destructive">{error()}</Alert>
111 </Show>159 </Show>
112 160
113- <Show when={!listLoading()} fallback={<DataTableSkeleton columns={4} rows={6} />}>161+ <Show when={!listLoading()} fallback={<DataTableSkeleton columns={5} rows={6} />}>
114 <DataTable162 <DataTable
115 title={t("nav.studentMarks")}163 title={t("nav.studentMarks")}
116 description={`${t("marks.lookup")} · ${rows().length} / ${total()}`}164 description={`${t("marks.lookup")} · ${rows().length} / ${total()}`}