All files / src/ahuora-design-system/ui paginated-table.tsx

90.9% Statements 20/22
69.23% Branches 9/13
100% Functions 1/1
93.33% Lines 14/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                  20x           120x 20x     20x   3x     23x   20x 31x 20x     60x 62x 3x 40x   80x      
import { ScrollArea } from "@radix-ui/react-scroll-area";
import {
  DataTable,
  DataTableProps,
} from "@/ahuora-design-system/ui/data-table";
import Paginator from "@/ahuora-design-system/ui/paginator";
import { ScrollBar } from "@/ahuora-design-system/ui/scroll-area";
import { cn } from "@/lib/utils";
 
export interface PaginatedTableProps<TData, TValue>
  extends Omit<DataTableProps<TData, TValue>, "data"> {
  data:
    | {
        count?: number;
        next?: string | null;
        pages?: number;
        previous?: string | null;
        results?: TData[];
      }
    | undefined;
  page: number;
  setPage: (page: number) => void;
  className?: string;
}
 
export function PaginatedTable<TData, TValue>({
  data,
  page,
  setPage,
  className,
  ...props
}: PaginatedTableProps<TData, TValue>) {
  const fullTable = data?.results;
 
  return (
    <ScrollArea className="h-full w-full min-w-0">
      <div
        className={cn(
          "relative flex h-full min-w-0 w-full flex-col gap-4 p-4",
          className,
        )}
      >
        <DataTable
          data={fullTable || []}
          rowSelection={{}}
          columnSelection
          {...props}
        />
        <Paginator page={page} setPage={setPage} data={data} />
        <ScrollBar orientation="vertical" />
        <ScrollBar orientation="horizontal" />
      </div>
    </ScrollArea>
  );
}