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