diff --git a/src/components/attendance/attendance-report-view.tsx b/src/components/attendance/attendance-report-view.tsx index 363f35f..b26698d 100644 --- a/src/components/attendance/attendance-report-view.tsx +++ b/src/components/attendance/attendance-report-view.tsx @@ -33,16 +33,17 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? { id: "course", header: t("nav.courses"), + meta: { stickyLeft: true }, cell: (cell) => ( {cell.row.original.course.title} ), }, - ...ATTENDANCE_STATUSES.map((status) => ({ + ...ATTENDANCE_STATUSES.map((status, index) => ({ id: status.value, header: () => {compact() ? t(status.key).slice(0, 1) : t(status.key)}, - meta: { headerClass: "text-right", cellClass: "text-right" }, + meta: { align: "right" as const, divider: index === 0 ? ("left" as const) : undefined }, cell: (cell) => ( {cell.row.original.counts[status.value]} @@ -51,14 +52,14 @@ export function AttendanceReportView(props: { report: AttendanceReport; compact? } satisfies ColumnDef)), { id: "total", - header: () => {compact() ? "Σ" : t("common.all")}, - meta: { cellClass: "mono text-right" }, + header: () => {compact() ? "Σ" : t("common.all")}, + meta: { align: "right", cellClass: "mono" }, cell: (cell) => cell.row.original.counts.total, }, { id: "rate", - header: () => %, - meta: { cellClass: "mono text-right font-semibold" }, + header: () => %, + meta: { align: "right", cellClass: "mono font-semibold" }, cell: (cell) => percent(cell.row.original.counts.rate), }, ]); diff --git a/src/components/homework/homework-report-view.tsx b/src/components/homework/homework-report-view.tsx index b10ac7d..55b2386 100644 --- a/src/components/homework/homework-report-view.tsx +++ b/src/components/homework/homework-report-view.tsx @@ -56,7 +56,7 @@ export function HomeworkReportView(props: { userId: string }) { { id: "mark", header: t("form.mark"), - meta: { cellClass: "text-right font-medium tabular-nums" }, + meta: { align: "right", cellClass: "font-medium tabular-nums" }, cell: (cell) => cell.row.original.result?.mark ?? "—", }, { diff --git a/src/components/marks/marks-report-view.tsx b/src/components/marks/marks-report-view.tsx index e36f3ad..d1e1925 100644 --- a/src/components/marks/marks-report-view.tsx +++ b/src/components/marks/marks-report-view.tsx @@ -33,6 +33,7 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean { accessorKey: "title", header: t("marks.exam"), + meta: { stickyLeft: true }, cell: (cell) => ( @@ -54,14 +55,14 @@ export function MarksReportView(props: { report: MarksReport; compact?: boolean }, { id: "weight", - header: () => {t("marks.weight")}, - meta: { cellClass: "mono text-right" }, + header: t("marks.weight"), + meta: { align: "right", divider: "left", cellClass: "mono" }, cell: (cell) => examWeight(cell.row.original, settings()?.exam_kinds) ?? "—", }, { accessorKey: "mark", - header: () => {t("marks.mark")}, - meta: { cellClass: "mono text-right font-semibold" }, + header: t("marks.mark"), + meta: { align: "right", cellClass: "mono font-semibold" }, cell: (cell) => markWithGrade(cell.row.original.mark, cell.row.original.grade), }, ]); diff --git a/src/components/ui/data-table.test.tsx b/src/components/ui/data-table.test.tsx index 8208512..af5f955 100644 --- a/src/components/ui/data-table.test.tsx +++ b/src/components/ui/data-table.test.tsx @@ -40,10 +40,33 @@ test("keeps only the rightmost action column sticky", () => { )); const actionsHeader = screen.getByRole("columnheader", { name: "Actions" }); - expect(actionsHeader.classList).toContain("table-sticky-head"); + expect(actionsHeader.classList).toContain("table-sticky-head-right"); expect(actionsHeader.classList).toContain("z-30"); const roleHeader = screen.getAllByRole("columnheader").find((header) => header.textContent?.startsWith("Role")); - expect(roleHeader?.classList).not.toContain("table-sticky-head"); + expect(roleHeader?.classList).not.toContain("table-sticky-head-right"); +}); + +test("freezes the meta.stickyLeft column and aligns head + cell together", () => { + const alignedColumns: ColumnDef[] = [ + { accessorKey: "name", header: "Name", meta: { stickyLeft: true } }, + { accessorKey: "role", header: "Role", meta: { align: "right" } }, + ]; + render(() => ( + + + + )); + + const headers = screen.getAllByRole("columnheader"); + const nameHeader = headers.find((header) => header.textContent?.startsWith("Name")); + expect(nameHeader?.classList).toContain("table-sticky-head-left"); + expect(nameHeader?.classList).toContain("left-0"); + + const roleHeader = headers.find((header) => header.textContent?.startsWith("Role")); + const roleCell = screen.getByRole("cell", { name: "Admin" }); + // Same alignment class on head and cell so columns never drift apart. + expect(roleHeader?.classList).toContain("text-right"); + expect(roleCell.classList).toContain("text-right"); }); test("paginates tables by default", () => { diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index b7d9724..1a027a2 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -19,7 +19,7 @@ import { Button } from "@/components/ui/button"; import { DataTableSearch } from "@/components/ui/data-table-search"; import { DataTableViewMenu, type ViewMenuColumn } from "@/components/ui/data-table-view-menu"; import { TablePagination } from "@/components/ui/table-pagination"; -import { IconChevronDown } from "@/components/ui/icons"; +import { IconArrowDown, IconArrowUp, IconChevronsUpDown } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; import { createTablePreferences } from "@/lib/table-preferences"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; @@ -30,6 +30,12 @@ declare module "@tanstack/solid-table" { headerClass?: string; cellClass?: string; label?: string; + /** Header + cell horizontal alignment. Applied to both so they never drift apart. */ + align?: "left" | "center" | "right"; + /** Freeze this column to the left edge on horizontal scroll (fintables-style). */ + stickyLeft?: boolean; + /** Vertical divider on the given edge — separates frozen label from metric columns. */ + divider?: "left" | "right"; } } @@ -70,6 +76,8 @@ export type DataTableProps = { const resolveUpdater = (updater: Updater, old: T): T => typeof updater === "function" ? (updater as (value: T) => T)(old) : updater; +const alignClass = { left: "text-left", center: "text-center", right: "text-right" } as const; + export function DataTable(props: DataTableProps) { const t = useT(); const paginationEnabled = props.enablePagination ?? true; @@ -129,11 +137,27 @@ export function DataTable(props: DataTableProps columnId === "actions" || columnId === "update"; - const stickyLocked = (columnId: string) => + const stickyRightLocked = (columnId: string) => columnId === "actions" || (columnId === "update" && table.getColumn("actions") == null); - const actionColumnClass = (columnId: string) => stickyLocked(columnId) ? "w-28 min-w-28 px-2 text-center whitespace-nowrap" : undefined; - const stickyHeadClass = (columnId: string) => stickyLocked(columnId) ? "table-sticky-head sticky right-0 z-30" : undefined; - const stickyCellClass = (columnId: string) => stickyLocked(columnId) ? "table-sticky-cell sticky right-0 z-10" : undefined; + const isStickyLeft = (column: Column) => column.columnDef.meta?.stickyLeft === true; + const alignOf = (column: Column) => column.columnDef.meta?.align ?? "left"; + const dividerClass = (column: Column) => { + const divider = column.columnDef.meta?.divider; + return divider === "left" ? "border-l border-border/70" : divider === "right" ? "border-r border-border/70" : undefined; + }; + const actionColumnClass = (columnId: string) => stickyRightLocked(columnId) ? "w-28 min-w-28 px-2 text-center whitespace-nowrap" : undefined; + const stickyHeadClass = (column: Column) => + isStickyLeft(column) + ? "table-sticky-head-left sticky left-0 z-30" + : stickyRightLocked(column.id) + ? "table-sticky-head-right sticky right-0 z-30" + : undefined; + const stickyCellClass = (column: Column) => + isStickyLeft(column) + ? "table-sticky-left sticky left-0 z-10" + : stickyRightLocked(column.id) + ? "table-sticky-right sticky right-0 z-10" + : undefined; const hideableColumns = () => table.getAllColumns().filter((column) => column.getCanHide() && !hiddenLocked(column.id)); const columnLabel = (column: Column) => { const header = column.columnDef.header; @@ -149,7 +173,7 @@ export function DataTable(props: DataTableProps Math.max(1, table.getVisibleLeafColumns().length); const tableWidth = () => table.getVisibleLeafColumns().reduce( - (total, column) => total + (stickyLocked(column.id) ? 112 : column.getSize()), + (total, column) => total + (stickyRightLocked(column.id) ? 112 : column.getSize()), 0, ); const showColumnMenu = () => (props.enableColumnVisibility ?? true) && hideableColumns().length > 0; @@ -182,18 +206,33 @@ export function DataTable(props: DataTableProps[number]["headers"][number]) => { const content = flexRender(header.column.columnDef.header, header.getContext()); - if (!(props.enableSorting ?? true) || !header.column.getCanSort()) return content; + const align = alignOf(header.column); + if (!(props.enableSorting ?? true) || !header.column.getCanSort()) { + // The th already carries alignClass; the block span makes text-align resolve. + return {content}; + } const sorted = () => header.column.getIsSorted(); return ( ); }; @@ -257,14 +296,16 @@ export function DataTable(props: DataTableProps {renderHeader(header)} - +
(props: DataTableProps ( {flexRender(cell.column.columnDef.cell, cell.getContext())} diff --git a/src/components/ui/icons.tsx b/src/components/ui/icons.tsx index c4406d3..ff89e06 100644 --- a/src/components/ui/icons.tsx +++ b/src/components/ui/icons.tsx @@ -345,6 +345,33 @@ export function IconChevronDown(props: IconProps) { ); } +export function IconArrowUp(props: IconProps) { + return ( + + + + + ); +} + +export function IconArrowDown(props: IconProps) { + return ( + + + + + ); +} + +export function IconChevronsUpDown(props: IconProps) { + return ( + + + + + ); +} + export function IconHome(props: IconProps) { return ( diff --git a/src/components/ui/table-pagination.tsx b/src/components/ui/table-pagination.tsx index 299f6f4..07acb28 100644 --- a/src/components/ui/table-pagination.tsx +++ b/src/components/ui/table-pagination.tsx @@ -18,7 +18,12 @@ export type TablePaginationProps = { /** Footer: "X kayıttan a-b arası" + page-size select + prev/next + "page / total". */ export function TablePagination(props: TablePaginationProps) { const t = useT(); - const options = () => props.pageSizeOptions ?? [10, 25, 50]; + // Always include the active page size so the select shows a selected value + // instead of rendering blank when a page passes a non-standard size (e.g. 12). + const options = () => { + const base = props.pageSizeOptions ?? [10, 25, 50]; + return base.includes(props.pageSize) ? base : [...base, props.pageSize].sort((a, b) => a - b); + }; const start = () => (props.total === 0 ? 0 : props.pageIndex * props.pageSize + 1); const end = () => Math.min((props.pageIndex + 1) * props.pageSize, props.total); diff --git a/src/index.css b/src/index.css index 1171bb3..71d9270 100644 --- a/src/index.css +++ b/src/index.css @@ -141,7 +141,10 @@ } & th { - @apply h-11 overflow-hidden text-ellipsis whitespace-nowrap px-3 text-left text-[11px] font-bold uppercase tracking-[0.16em] text-muted-foreground first:pl-4 last:pr-4; + /* No text-align here: `.data-table th` would out-specify the per-column + * text-right/center utility on TableHead and force every header left. The + * TableHead base class provides the left default; alignment stays utility-driven. */ + @apply h-11 overflow-hidden text-ellipsis whitespace-nowrap px-3 text-[11px] font-bold uppercase tracking-[0.16em] text-muted-foreground first:pl-4 last:pr-4; background-color: color-mix(in srgb, hsl(var(--muted)) 55%, hsl(var(--card))); } @@ -172,16 +175,34 @@ } /* - * Yatay kaydırmada sağda sabit kalan aksiyon hücresi. Altındaki içerik görünmesin - * diye opak olmalı ama zebra/hover satır tonuyla da eşleşmeli: yarı saydam satır - * tonunun kart zemini üzerindeki karşılığı color-mix ile üretiliyor. + * Yatay kaydırmada sabit kalan (dondurulmuş) kolonlar. Altındaki içerik görünmesin + * diye opak olmalı ama zebra/hover satır tonuyla da eşleşmeli: gövde hücresi satır + * tonunu `inherit` ile alır, başlık hücresi başlık tonunu kullanır. Kayan içerikle + * arasında görsel dikiş için kenara ince çizgi + yumuşak gölge eklenir. */ -@utility table-sticky-cell { +@utility table-sticky-left { background-color: inherit; + border-right: 1px solid hsl(var(--border)); + box-shadow: 6px 0 8px -6px color-mix(in srgb, hsl(var(--foreground)) 18%, transparent); } -@utility table-sticky-head { +@utility table-sticky-right { + background-color: inherit; + border-left: 1px solid hsl(var(--border)); + box-shadow: -6px 0 8px -6px color-mix(in srgb, hsl(var(--foreground)) 18%, transparent); +} + +/* Dondurulmuş başlık hücreleri gövde hücrelerinin üstünde opak kalmalı. */ +@utility table-sticky-head-left { + background-color: color-mix(in srgb, hsl(var(--muted)) 55%, hsl(var(--card))); + border-right: 1px solid hsl(var(--border)); + box-shadow: 6px 0 8px -6px color-mix(in srgb, hsl(var(--foreground)) 18%, transparent); +} + +@utility table-sticky-head-right { background-color: color-mix(in srgb, hsl(var(--muted)) 55%, hsl(var(--card))); + border-left: 1px solid hsl(var(--border)); + box-shadow: -6px 0 8px -6px color-mix(in srgb, hsl(var(--foreground)) 18%, transparent); } /* Satır yoğunluğu (density). Normal = @utility data-table varsayılanları. */ diff --git a/src/pages/courses-page.tsx b/src/pages/courses-page.tsx index cdab560..b46584d 100644 --- a/src/pages/courses-page.tsx +++ b/src/pages/courses-page.tsx @@ -28,7 +28,7 @@ import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; -const PAGE_SIZE = 12; +const PAGE_SIZE = 10; export default function CoursesPage() { return ; diff --git a/src/pages/exams-page.tsx b/src/pages/exams-page.tsx index 758566d..cf5c368 100644 --- a/src/pages/exams-page.tsx +++ b/src/pages/exams-page.tsx @@ -32,7 +32,7 @@ import { cn } from "@/lib/cn"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; -const EXAM_PAGE_SIZE = 12; +const EXAM_PAGE_SIZE = 10; type ExamRow = Exam & { displayStatus: ExamDisplayStatus }; diff --git a/src/pages/homework-page.tsx b/src/pages/homework-page.tsx index 2f9f580..0bebe76 100644 --- a/src/pages/homework-page.tsx +++ b/src/pages/homework-page.tsx @@ -243,7 +243,7 @@ function HomeworkContent() { tableClass="table-fixed min-w-5xl" filterColumn="title" enablePagination - pageSize={12} + pageSize={10} empty={t("homework.empty")} storageKey="homework" onRowClick={(item) => void navigate({ to: "/homework/$id", params: { id: item.id } })} diff --git a/src/pages/meals-page.tsx b/src/pages/meals-page.tsx index 17b2344..eb0a0f9 100644 --- a/src/pages/meals-page.tsx +++ b/src/pages/meals-page.tsx @@ -22,7 +22,7 @@ import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; -const PAGE_SIZE = 12; +const PAGE_SIZE = 10; const today = () => new Date().toISOString().slice(0, 10); export default function MealsPage() { diff --git a/src/pages/my-students-page.tsx b/src/pages/my-students-page.tsx index 84cf650..8388e77 100644 --- a/src/pages/my-students-page.tsx +++ b/src/pages/my-students-page.tsx @@ -132,14 +132,14 @@ function StudentDetailPanel(props: { student: PersonRef | null; onClose: () => v }, { accessorKey: "weight", - header: () => {t("marks.weight")}, - meta: { cellClass: "mono text-right tabular-nums" }, + header: t("marks.weight"), + meta: { align: "right", cellClass: "mono tabular-nums" }, cell: (cell) => cell.row.original.weight, }, { accessorKey: "mark", - header: () => {t("marks.mark")}, - meta: { cellClass: "mono text-right font-semibold tabular-nums" }, + header: t("marks.mark"), + meta: { align: "right", cellClass: "mono font-semibold tabular-nums" }, cell: (cell) => formatNumber(cell.row.original.mark), }, ]); diff --git a/src/pages/notes-page.tsx b/src/pages/notes-page.tsx index 72dd802..f06e63d 100644 --- a/src/pages/notes-page.tsx +++ b/src/pages/notes-page.tsx @@ -21,7 +21,7 @@ import { createFlash } from "@/lib/flash"; import { loadListPage, totalPages as pagesOf } from "@/lib/list-page"; import { useT } from "@/stores/preferences-context"; -const NOTE_PAGE_SIZE = 12; +const NOTE_PAGE_SIZE = 10; export default function NotesPage() { return ( diff --git a/src/pages/payment-statement-page.tsx b/src/pages/payment-statement-page.tsx index 194019a..4e0e16d 100644 --- a/src/pages/payment-statement-page.tsx +++ b/src/pages/payment-statement-page.tsx @@ -28,7 +28,7 @@ import { personLabel } from "@/lib/person"; import { useAuth } from "@/stores/auth-context"; import { usePreferences, useT } from "@/stores/preferences-context"; -const STATEMENT_PAGE_SIZE = 12; +const STATEMENT_PAGE_SIZE = 10; export default function PaymentStatementPage() { return ( diff --git a/src/pages/payments-page.tsx b/src/pages/payments-page.tsx index d4f8408..04c201f 100644 --- a/src/pages/payments-page.tsx +++ b/src/pages/payments-page.tsx @@ -48,7 +48,7 @@ import { PAYMENT_METHOD_KEYS, sortStatementEntries, statementStatus } from "@/li import { personLabel } from "@/lib/person"; import { usePreferences, useT } from "@/stores/preferences-context"; -const PLAN_PAGE_SIZE = 12; +const PLAN_PAGE_SIZE = 10; const STATEMENT_PAGE_SIZE = 15; const STUDENT_PAGE_SIZE = 10; diff --git a/src/pages/question-bank-page.tsx b/src/pages/question-bank-page.tsx index 3a345d3..174565c 100644 --- a/src/pages/question-bank-page.tsx +++ b/src/pages/question-bank-page.tsx @@ -22,7 +22,7 @@ import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; -const BANK_PAGE_SIZE = 12; +const BANK_PAGE_SIZE = 10; export default function QuestionBankPage() { return ( diff --git a/src/pages/staff-work-page.tsx b/src/pages/staff-work-page.tsx index 7f0351a..162fe8b 100644 --- a/src/pages/staff-work-page.tsx +++ b/src/pages/staff-work-page.tsx @@ -24,7 +24,7 @@ import { formatDateTime, formatDurationMinutes } from "@/lib/format"; import { personLabel } from "@/lib/person"; import { usePreferences, useT } from "@/stores/preferences-context"; -const PEOPLE_PAGE_SIZE = 12; +const PEOPLE_PAGE_SIZE = 10; const WORK_PAGE_SIZE = 15; function msToDateInput(ms: number): string { const d = new Date(ms); diff --git a/src/pages/student-attendance-page.tsx b/src/pages/student-attendance-page.tsx index 1ead861..a61bbb4 100644 --- a/src/pages/student-attendance-page.tsx +++ b/src/pages/student-attendance-page.tsx @@ -15,7 +15,7 @@ import { TableRowActions } from "@/components/ui/table-row-actions"; import { personLabel } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; -const PAGE_SIZE = 12; +const PAGE_SIZE = 10; export default function StudentAttendancePage() { return ( diff --git a/src/pages/student-marks-page.tsx b/src/pages/student-marks-page.tsx index 36cfa55..bfed41a 100644 --- a/src/pages/student-marks-page.tsx +++ b/src/pages/student-marks-page.tsx @@ -16,7 +16,7 @@ import { TableRowActions } from "@/components/ui/table-row-actions"; import { personLabel } from "@/lib/person"; import { useT } from "@/stores/preferences-context"; -const PAGE_SIZE = 12; +const PAGE_SIZE = 10; 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) => @@ -91,7 +91,15 @@ function StudentMarksContent() { ); const total = () => list().length; - const rows = () => list(); + // The inline "average" column reads the separate marksMapRes resource, which + // resolves AFTER this table first renders. TanStack caches cell values by the + // data-array identity, so without a new reference the averages only appear once + // something forces a re-derive (e.g. sorting). Track marksMapRes and hand back a + // fresh array so the column fills in as soon as the marks load. + const rows = () => { + marksMapRes(); + return [...list()]; + }; const listLoading = () => list.loading; const searchPerson = (person: PersonRef, query: string) => [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); @@ -108,9 +116,9 @@ function StudentMarksContent() { }, { id: "average", - header: () => {t("marks.overall")}, + header: t("marks.overall"), accessorFn: (user) => marksOf(user.id)?.overall_average ?? -1, - meta: { headerClass: "text-right", cellClass: "text-right" }, + meta: { align: "right" }, cell: (cell) => { const rep = marksOf(cell.row.original.id); if (rep == null) return —; diff --git a/src/pages/student-pomodoro-page.tsx b/src/pages/student-pomodoro-page.tsx index 7c480e5..9cc0042 100644 --- a/src/pages/student-pomodoro-page.tsx +++ b/src/pages/student-pomodoro-page.tsx @@ -15,7 +15,7 @@ import { formatDateTime, formatDurationClock } from "@/lib/format"; import { personLabel } from "@/lib/person"; import { usePreferences, useT } from "@/stores/preferences-context"; -const PAGE_SIZE = 12; +const PAGE_SIZE = 10; export default function StudentPomodoroPage() { return ( diff --git a/src/pages/terms-page.tsx b/src/pages/terms-page.tsx index 187cb43..a99a532 100644 --- a/src/pages/terms-page.tsx +++ b/src/pages/terms-page.tsx @@ -24,7 +24,7 @@ import { createFlash } from "@/lib/flash"; import { formatDateTime } from "@/lib/format"; import { usePreferences, useT } from "@/stores/preferences-context"; -const TERM_PAGE_SIZE = 12; +const TERM_PAGE_SIZE = 10; function dateInputFromMs(ms: number): string { const date = new Date(ms);