forge
Explore
Log in

Don't you dare go Hollow

📋 report card and marks tables use DataTable

Browse files at this commit

50506d2e5b558b05108e45c8d14cc6c1e2f42323Burak BoduroğluParent: 41a3aba
  • refactor
    • 📋 report card and marks tables use DataTable
Show full message
refactor: 📋 report card and marks tables use DataTable
- the karne lines and the marks overview were the last raw <table>s in
  domain code; they now render through DataTable (no pager, sort or
  column menu), so they share its styling and get the phone card layout
- fix: the marks overview column holding the "open section" link was
  headed "Teacher"; it is headed by the section now
src/components/marks/karne-view.tsxmodified+32 -31
@@ -1,7 +1,8 @@
1-import { For, Show } from "solid-js";1+import { For, Show, createMemo } from "solid-js";
2-import type { KarneReport, Term } from "@/api/client";2+import type { ColumnDef } from "@tanstack/solid-table";
3+import type { KarneInstance, KarneReport, Term } from "@/api/client";
3 import { Badge } from "@/components/ui/badge";4 import { Badge } from "@/components/ui/badge";
4-import { DataTableEmpty } from "@/components/ui/data-table";5+import { DataTable, DataTableEmpty } from "@/components/ui/data-table";
5 import { Select } from "@/components/ui/select";6 import { Select } from "@/components/ui/select";
6 import { useT } from "@/stores/preferences-context";7 import { useT } from "@/stores/preferences-context";
7 8
@@ -26,6 +27,26 @@ export function KarneView(props: {
26 return verdict ?? "—";27 return verdict ?? "—";
27 };28 };
28 29
30+ const columns = createMemo<ColumnDef<KarneInstance>[]>(() => [
31+ { accessorKey: "course", header: t("nav.courses"), meta: { cellClass: "font-medium" } },
32+ { accessorKey: "ders_saati", header: t("instances.dersSaati"), meta: { cellClass: "mono tabular-nums text-muted-foreground" } },
33+ {
34+ id: "average",
35+ accessorFn: (line) => formatAverage(line.average),
36+ header: t("marks.courseAvg"),
37+ meta: { cellClass: "mono font-semibold tabular-nums" },
38+ },
39+ {
40+ id: "band",
41+ header: t("karne.band"),
42+ cell: (cell) => (
43+ <Show when={cell.row.original.band} fallback="—">
44+ {(band) => <Badge variant="outline" class="rounded-full">{band()}</Badge>}
45+ </Show>
46+ ),
47+ },
48+ ]);
49+
29 return (50 return (
30 <div class="space-y-4">51 <div class="space-y-4">
31 <div class="flex flex-wrap items-end justify-between gap-3">52 <div class="flex flex-wrap items-end justify-between gap-3">
@@ -59,34 +80,14 @@ export function KarneView(props: {
59 when={props.report.instances.length > 0}80 when={props.report.instances.length > 0}
60 fallback={<DataTableEmpty class="rounded-lg border border-border bg-card py-10">{t("karne.empty")}</DataTableEmpty>}81 fallback={<DataTableEmpty class="rounded-lg border border-border bg-card py-10">{t("karne.empty")}</DataTableEmpty>}
61 >82 >
62- <div class="overflow-x-auto rounded-lg border border-border bg-card">83+ <DataTable
63- <table class="w-full text-sm">84+ columns={columns()}
64- <thead class="border-b border-border/60 text-left text-xs text-muted-foreground">85+ data={props.report.instances}
65- <tr>86+ enablePagination={false}
66- <th class="p-3 font-medium">{t("nav.courses")}</th>87+ enableColumnVisibility={false}
67- <th class="p-3 font-medium">{t("instances.dersSaati")}</th>88+ enableSorting={false}
68- <th class="p-3 font-medium">{t("marks.courseAvg")}</th>89+ tableClass="min-w-[28rem]"
69- <th class="p-3 font-medium">{t("karne.band")}</th>90+ />
70- </tr>
71- </thead>
72- <tbody>
73- <For each={props.report.instances}>
74- {(line) => (
75- <tr class="border-b border-border/60 last:border-0">
76- <td class="min-w-0 p-3 font-medium">{line.course}</td>
77- <td class="mono p-3 tabular-nums text-muted-foreground">{line.ders_saati}</td>
78- <td class="mono p-3 font-semibold tabular-nums">{formatAverage(line.average)}</td>
79- <td class="p-3">
80- <Show when={line.band} fallback="—">
81- {(band) => <Badge variant="outline" class="rounded-full">{band()}</Badge>}
82- </Show>
83- </td>
84- </tr>
85- )}
86- </For>
87- </tbody>
88- </table>
89- </div>
90 </Show>91 </Show>
91 </div>92 </div>
92 );93 );
src/components/marks/marks-report-view.tsxmodified+44 -42
@@ -27,6 +27,42 @@ function scoreWidth(mark: number | null): string {
27 27
28 export function MarksReportView(props: { report: MarksReport; compact?: boolean }) {28 export function MarksReportView(props: { report: MarksReport; compact?: boolean }) {
29 const t = useT();29 const t = useT();
30+ type CourseBlock = MarksReport["courses"][number];
31+ const courseColumns = createMemo<ColumnDef<CourseBlock>[]>(() => [
32+ {
33+ id: "course",
34+ header: t("nav.courses"),
35+ meta: { headerClass: "w-[42%]" },
36+ cell: (cell) => (
37+ <Link to="/courses/$id" params={{ id: cell.row.original.course.id }} class="block truncate font-medium hover:text-primary-text hover:underline">
38+ {cell.row.original.course.title}
39+ </Link>
40+ ),
41+ },
42+ {
43+ id: "instance",
44+ header: t("instances.title"),
45+ meta: { headerClass: "w-[28%]", cellClass: "text-muted-foreground" },
46+ cell: (cell) => (
47+ <Link to="/instances/$id" params={{ id: cell.row.original.instance }} class="block truncate hover:text-primary-text hover:underline">
48+ {t("instances.open")}
49+ </Link>
50+ ),
51+ },
52+ {
53+ id: "average",
54+ header: t("marks.courseAvg"),
55+ meta: { headerClass: "w-[30%]" },
56+ cell: (cell) => (
57+ <div class="flex items-center gap-2">
58+ <div class="h-1.5 w-12 min-w-8 shrink overflow-hidden rounded-full bg-muted">
59+ <div class="h-full rounded-full bg-primary" style={{ width: scoreWidth(cell.row.original.average) }} />
60+ </div>
61+ <span class="mono shrink-0 text-xs font-semibold tabular-nums">{markWithGrade(cell.row.original.average, cell.row.original.average_grade)}</span>
62+ </div>
63+ ),
64+ },
65+ ]);
30 const [settings] = createResource(() => getSettings());66 const [settings] = createResource(() => getSettings());
31 const compact = () => props.compact === true;67 const compact = () => props.compact === true;
32 const resultCount = createMemo(() => props.report.courses.reduce((total, course) => total + course.results.length, 0));68 const resultCount = createMemo(() => props.report.courses.reduce((total, course) => total + course.results.length, 0));
@@ -111,48 +147,14 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean
111 </Tabs>147 </Tabs>
112 148
113 <Show when={tab() === "general"}>149 <Show when={tab() === "general"}>
114- <div class="overflow-x-auto rounded-lg border border-border bg-card shadow-xs">150+ <DataTable
115- <table class="w-full min-w-[28rem] table-fixed text-sm">151+ columns={courseColumns()}
116- <colgroup>152+ data={props.report.courses}
117- <col class="w-[42%]" />153+ enablePagination={false}
118- <col class="w-[28%]" />154+ enableColumnVisibility={false}
119- <col class="w-[30%]" />155+ enableSorting={false}
120- </colgroup>156+ tableClass="min-w-[28rem]"
121- <thead>157+ />
122- <tr class="border-b border-border text-left text-xs text-muted-foreground">
123- <th class="p-3 font-medium">{t("nav.courses")}</th>
124- <th class="p-3 font-medium">{t("appointments.teacher")}</th>
125- <th class="p-3 font-medium">{t("marks.courseAvg")}</th>
126- </tr>
127- </thead>
128- <tbody>
129- <For each={props.report.courses}>
130- {(block) => (
131- <tr class="border-b border-border/60 last:border-0">
132- <td class="min-w-0 p-3">
133- <Link to="/courses/$id" params={{ id: block.course.id }} class="block truncate font-medium hover:text-primary-text hover:underline">
134- {block.course.title}
135- </Link>
136- </td>
137- <td class="min-w-0 p-3 text-muted-foreground">
138- <Link to="/instances/$id" params={{ id: block.instance }} class="block truncate hover:text-primary-text hover:underline">
139- {t("instances.open")}
140- </Link>
141- </td>
142- <td class="min-w-0 p-3">
143- <div class="flex items-center gap-2">
144- <div class="h-1.5 w-12 min-w-8 shrink overflow-hidden rounded-full bg-muted">
145- <div class="h-full rounded-full bg-primary" style={{ width: scoreWidth(block.average) }} />
146- </div>
147- <span class="mono shrink-0 text-xs font-semibold tabular-nums">{markWithGrade(block.average, block.average_grade)}</span>
148- </div>
149- </td>
150- </tr>
151- )}
152- </For>
153- </tbody>
154- </table>
155- </div>
156 </Show>158 </Show>
157 159
158 <Show when={tab() === "byCourse"}>160 <Show when={tab() === "byCourse"}>