🚚 courses/exams pages use DataTable empty prop, action column width
Browse files at this commit249dfed185ed266f43390de237fdabdc28d1f99aParent: a001b1b- refactor
- 🚚 courses/exams pages use DataTable empty prop, action column width
3 changed files +61 -94
- src/components/ui/data-table.tsx +3 -2
- src/pages/courses-page.tsx +29 -46
- src/pages/exams-page.tsx +29 -46
src/components/ui/data-table.tsxmodified+3 -2
| @@ -109,6 +109,7 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | ||
| 109 | 109 | }, |
| 110 | 110 | }); |
| 111 | 111 | const hiddenLocked = (columnId: string) => columnId === "actions" || columnId === "update"; |
| 112 | + const actionColumnClass = (columnId: string) => hiddenLocked(columnId) ? "w-20 min-w-20 max-w-20 px-1 text-center" : undefined; | |
| 112 | 113 | const hideableColumns = () => table.getAllColumns().filter((column) => column.getCanHide() && !hiddenLocked(column.id)); |
| 113 | 114 | const columnLabel = (column: Column<TData, unknown>) => { |
| 114 | 115 | const header = column.columnDef.header; |
| @@ -193,7 +194,7 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | ||
| 193 | 194 | <TableRow> |
| 194 | 195 | <For each={headerGroup.headers}> |
| 195 | 196 | {(header) => ( |
| 196 | - <TableHead colSpan={header.colSpan} class={header.column.columnDef.meta?.headerClass}> | |
| 197 | + <TableHead colSpan={header.colSpan} class={cn(actionColumnClass(header.column.id), header.column.columnDef.meta?.headerClass)}> | |
| 197 | 198 | <Show when={!header.isPlaceholder}>{renderHeader(header)}</Show> |
| 198 | 199 | </TableHead> |
| 199 | 200 | )} |
| @@ -218,7 +219,7 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | ||
| 218 | 219 | <TableRow data-state={row.getIsSelected() ? "selected" : undefined}> |
| 219 | 220 | <For each={row.getVisibleCells()}> |
| 220 | 221 | {(cell) => ( |
| 221 | - <TableCell class={cell.column.columnDef.meta?.cellClass}> | |
| 222 | + <TableCell class={cn(actionColumnClass(cell.column.id), cell.column.columnDef.meta?.cellClass)}> | |
| 222 | 223 | {flexRender(cell.column.columnDef.cell, cell.getContext())} |
| 223 | 224 | </TableCell> |
| 224 | 225 | )} |
src/pages/courses-page.tsxmodified+29 -46
| @@ -14,7 +14,6 @@ import { PageHeader } from "@/components/layout/page-header"; | ||
| 14 | 14 | import { Badge } from "@/components/ui/badge"; |
| 15 | 15 | import { Button } from "@/components/ui/button"; |
| 16 | 16 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; |
| 17 | -import { EmptyState } from "@/components/ui/empty-state"; | |
| 18 | 17 | import { IconEye, IconPlus } from "@/components/ui/icons"; |
| 19 | 18 | import { Input } from "@/components/ui/input"; |
| 20 | 19 | import { Label } from "@/components/ui/label"; |
| @@ -232,53 +231,37 @@ function CoursesContent() { | ||
| 232 | 231 | <Show when={list.error}> |
| 233 | 232 | <Alert variant="destructive">{formatApiError(list.error)}</Alert> |
| 234 | 233 | </Show> |
| 235 | - <Show | |
| 236 | - when={rows().length > 0} | |
| 237 | - fallback={ | |
| 238 | - <EmptyState | |
| 239 | - title={t("courses.empty", { item: pageLabel() })} | |
| 240 | - action={ | |
| 241 | - canCreate() ? ( | |
| 242 | - <Button type="button" size="sm" class="rounded-lg" onClick={() => setShowForm(true)}> | |
| 243 | - <IconPlus class="h-4 w-4" /> | |
| 244 | - {t("common.createItem", { item: pageLabel() })} | |
| 245 | - </Button> | |
| 246 | - ) : undefined | |
| 247 | - } | |
| 248 | - /> | |
| 249 | - } | |
| 250 | - > | |
| 251 | - <div class="space-y-4"> | |
| 252 | - <div class="flex flex-wrap items-center justify-between gap-3"> | |
| 253 | - <div> | |
| 254 | - <h2 class="font-display text-lg font-semibold">{t("courses.listTitle", { item: pageLabel() })}</h2> | |
| 255 | - <p class="mt-1 text-sm text-muted-foreground"> | |
| 256 | - {t("common.countItem", { count: rows().length, item: pageLabel() })} | |
| 257 | - </p> | |
| 258 | - </div> | |
| 234 | + <div class="space-y-4"> | |
| 235 | + <div class="flex flex-wrap items-center justify-between gap-3"> | |
| 236 | + <div> | |
| 237 | + <h2 class="font-display text-lg font-semibold">{t("courses.listTitle", { item: pageLabel() })}</h2> | |
| 238 | + <p class="mt-1 text-sm text-muted-foreground"> | |
| 239 | + {t("common.countItem", { count: rows().length, item: pageLabel() })} | |
| 240 | + </p> | |
| 259 | 241 | </div> |
| 260 | - <DataTable | |
| 261 | - columns={columns()} | |
| 262 | - data={rows()} | |
| 263 | - tableClass="table-fixed min-w-[44rem]" | |
| 264 | - searchPredicate={searchCourse} | |
| 265 | - enablePagination | |
| 266 | - pageSize={COURSE_PAGE_SIZE} | |
| 267 | - filters={ | |
| 268 | - <Select | |
| 269 | - class="h-9 w-full rounded-sm sm:w-44" | |
| 270 | - value={termFilter()} | |
| 271 | - aria-label={t("terms.term")} | |
| 272 | - onChange={(event) => setTermFilter(event.currentTarget.value)} | |
| 273 | - > | |
| 274 | - <option value="all">{t("common.all")}</option> | |
| 275 | - <option value="unassigned">{t("terms.unassigned")}</option> | |
| 276 | - <For each={terms() ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For> | |
| 277 | - </Select> | |
| 278 | - } | |
| 279 | - /> | |
| 280 | 242 | </div> |
| 281 | - </Show> | |
| 243 | + <DataTable | |
| 244 | + columns={columns()} | |
| 245 | + data={rows()} | |
| 246 | + tableClass="table-fixed min-w-[44rem]" | |
| 247 | + searchPredicate={searchCourse} | |
| 248 | + enablePagination | |
| 249 | + pageSize={COURSE_PAGE_SIZE} | |
| 250 | + empty={t("courses.empty", { item: pageLabel() })} | |
| 251 | + filters={ | |
| 252 | + <Select | |
| 253 | + class="h-9 w-full rounded-sm sm:w-44" | |
| 254 | + value={termFilter()} | |
| 255 | + aria-label={t("terms.term")} | |
| 256 | + onChange={(event) => setTermFilter(event.currentTarget.value)} | |
| 257 | + > | |
| 258 | + <option value="all">{t("common.all")}</option> | |
| 259 | + <option value="unassigned">{t("terms.unassigned")}</option> | |
| 260 | + <For each={terms() ?? []}>{(term) => <option value={term.id}>{term.name}</option>}</For> | |
| 261 | + </Select> | |
| 262 | + } | |
| 263 | + /> | |
| 264 | + </div> | |
| 282 | 265 | </Suspense> |
| 283 | 266 | </section> |
| 284 | 267 | </div> |
src/pages/exams-page.tsxmodified+29 -46
| @@ -15,7 +15,6 @@ import { Alert } from "@/components/ui/alert"; | ||
| 15 | 15 | import { Badge } from "@/components/ui/badge"; |
| 16 | 16 | import { Button } from "@/components/ui/button"; |
| 17 | 17 | import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; |
| 18 | -import { EmptyState } from "@/components/ui/empty-state"; | |
| 19 | 18 | import { IconEdit, IconEye, IconPlus } from "@/components/ui/icons"; |
| 20 | 19 | import { Select } from "@/components/ui/select"; |
| 21 | 20 | import { SidePanel } from "@/components/ui/side-panel"; |
| @@ -244,53 +243,37 @@ function ExamsContent() { | ||
| 244 | 243 | <Show when={list.error}> |
| 245 | 244 | <Alert variant="destructive">{formatApiError(list.error)}</Alert> |
| 246 | 245 | </Show> |
| 247 | - <Show | |
| 248 | - when={rows().length > 0} | |
| 249 | - fallback={ | |
| 250 | - <EmptyState | |
| 251 | - title={t("exams.empty")} | |
| 252 | - action={ | |
| 253 | - canCreate() ? ( | |
| 254 | - <Button type="button" size="sm" class="rounded-lg" onClick={() => setCreateOpen(true)}> | |
| 255 | - <IconPlus class="h-4 w-4" /> | |
| 256 | - {t("exams.create")} | |
| 257 | - </Button> | |
| 258 | - ) : undefined | |
| 259 | - } | |
| 260 | - /> | |
| 261 | - } | |
| 262 | - > | |
| 263 | - <DataTable | |
| 264 | - columns={columns()} | |
| 265 | - data={rows()} | |
| 266 | - tableClass="table-fixed min-w-[64rem]" | |
| 267 | - filterPlaceholder={t("exams.searchPlaceholder")} | |
| 268 | - searchPredicate={searchExam} | |
| 269 | - enablePagination | |
| 270 | - pageSize={EXAM_PAGE_SIZE} | |
| 271 | - filters={ | |
| 272 | - <> | |
| 273 | - <Select class="h-9 w-full rounded-sm sm:w-40" value={statusFilter()} onChange={(event) => setStatusFilter(event.currentTarget.value as ExamStatus | "all")}> | |
| 246 | + <DataTable | |
| 247 | + columns={columns()} | |
| 248 | + data={rows()} | |
| 249 | + tableClass="table-fixed min-w-[64rem]" | |
| 250 | + filterPlaceholder={t("exams.searchPlaceholder")} | |
| 251 | + searchPredicate={searchExam} | |
| 252 | + enablePagination | |
| 253 | + pageSize={EXAM_PAGE_SIZE} | |
| 254 | + empty={t("exams.empty")} | |
| 255 | + filters={ | |
| 256 | + <> | |
| 257 | + <Select class="h-9 w-full rounded-sm sm:w-40" value={statusFilter()} onChange={(event) => setStatusFilter(event.currentTarget.value as ExamStatus | "all")}> | |
| 258 | + <option value="all">{t("common.all")}</option> | |
| 259 | + <option value="draft">{t("exams.draft")}</option> | |
| 260 | + <option value="upcoming">{t("exams.upcoming")}</option> | |
| 261 | + <option value="active">{t("exams.active")}</option> | |
| 262 | + <option value="finished">{t("exams.finished")}</option> | |
| 263 | + <option value="unscheduled">{t("exams.unscheduled")}</option> | |
| 264 | + </Select> | |
| 265 | + <Show when={showMoreFilters()}> | |
| 266 | + <Select class="h-9 w-full rounded-sm sm:w-52" value={courseFilter()} onChange={(event) => setCourseFilter(event.currentTarget.value)}> | |
| 274 | 267 | <option value="all">{t("common.all")}</option> |
| 275 | - <option value="draft">{t("exams.draft")}</option> | |
| 276 | - <option value="upcoming">{t("exams.upcoming")}</option> | |
| 277 | - <option value="active">{t("exams.active")}</option> | |
| 278 | - <option value="finished">{t("exams.finished")}</option> | |
| 279 | - <option value="unscheduled">{t("exams.unscheduled")}</option> | |
| 268 | + <For each={visibleCourses()}>{(course) => <option value={course.id}>{course.title}</option>}</For> | |
| 280 | 269 | </Select> |
| 281 | - <Show when={showMoreFilters()}> | |
| 282 | - <Select class="h-9 w-full rounded-sm sm:w-52" value={courseFilter()} onChange={(event) => setCourseFilter(event.currentTarget.value)}> | |
| 283 | - <option value="all">{t("common.all")}</option> | |
| 284 | - <For each={visibleCourses()}>{(course) => <option value={course.id}>{course.title}</option>}</For> | |
| 285 | - </Select> | |
| 286 | - </Show> | |
| 287 | - <Button type="button" variant="outline" size="sm" class="h-9 rounded-sm" onClick={() => setShowMoreFilters((value) => !value)}> | |
| 288 | - {showMoreFilters() ? t("common.lessFilters") : t("common.moreFilters")} | |
| 289 | - </Button> | |
| 290 | - </> | |
| 291 | - } | |
| 292 | - /> | |
| 293 | - </Show> | |
| 270 | + </Show> | |
| 271 | + <Button type="button" variant="outline" size="sm" class="h-9 rounded-sm" onClick={() => setShowMoreFilters((value) => !value)}> | |
| 272 | + {showMoreFilters() ? t("common.lessFilters") : t("common.moreFilters")} | |
| 273 | + </Button> | |
| 274 | + </> | |
| 275 | + } | |
| 276 | + /> | |
| 294 | 277 | </Suspense> |
| 295 | 278 | </section> |
| 296 | 279 |