|
|
@@ -4,6 +4,7 @@ import { DataTablePagination } from '@/components/data-table/data-table-paginati
|
|
|
import { DataTableViewOptions } from '@/components/data-table/data-table-view-options.js';
|
|
|
import { RefreshButton } from '@/components/data-table/refresh-button.js';
|
|
|
import { Input } from '@/components/ui/input.js';
|
|
|
+import { Skeleton } from '@/components/ui/skeleton.js';
|
|
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table.js';
|
|
|
import { BulkAction } from '@/framework/data-table/data-table-types.js';
|
|
|
import { useChannel } from '@/hooks/use-channel.js';
|
|
|
@@ -38,6 +39,7 @@ interface DataTableProps<TData> {
|
|
|
columns: ColumnDef<TData, any>[];
|
|
|
data: TData[];
|
|
|
totalItems: number;
|
|
|
+ isLoading?: boolean;
|
|
|
page?: number;
|
|
|
itemsPerPage?: number;
|
|
|
sorting?: SortingState;
|
|
|
@@ -63,6 +65,7 @@ export function DataTable<TData>({
|
|
|
columns,
|
|
|
data,
|
|
|
totalItems,
|
|
|
+ isLoading,
|
|
|
page,
|
|
|
itemsPerPage,
|
|
|
sorting: sortingInitialState,
|
|
|
@@ -149,6 +152,7 @@ export function DataTable<TData>({
|
|
|
onColumnVisibilityChange?.(table, columnVisibility);
|
|
|
}, [columnVisibility]);
|
|
|
|
|
|
+ const visibleColumnCount = Object.values(columnVisibility).filter(Boolean).length;
|
|
|
return (
|
|
|
<>
|
|
|
<div className="flex justify-between items-start">
|
|
|
@@ -200,7 +204,7 @@ export function DataTable<TData>({
|
|
|
</div>
|
|
|
<div className="flex items-center justify-start gap-2">
|
|
|
{!disableViewOptions && <DataTableViewOptions table={table} />}
|
|
|
- {onRefresh && <RefreshButton onRefresh={onRefresh} />}
|
|
|
+ {onRefresh && <RefreshButton onRefresh={onRefresh} isLoading={isLoading ?? false} />}
|
|
|
</div>
|
|
|
</div>
|
|
|
<DataTableBulkActions bulkActions={bulkActions ?? []} table={table} />
|
|
|
@@ -225,18 +229,38 @@ export function DataTable<TData>({
|
|
|
))}
|
|
|
</TableHeader>
|
|
|
<TableBody>
|
|
|
- {table.getRowModel().rows?.length ? (
|
|
|
+ {isLoading && !data?.length ? (
|
|
|
+ Array.from({ length: pagination.pageSize }).map((_, index) => (
|
|
|
+ <TableRow
|
|
|
+ key={`skeleton-${index}`}
|
|
|
+ className="animate-in fade-in duration-100"
|
|
|
+ >
|
|
|
+ {Array.from({ length: visibleColumnCount }).map((_, cellIndex) => (
|
|
|
+ <TableCell
|
|
|
+ key={`skeleton-cell-${index}-${cellIndex}`}
|
|
|
+ className="h-12"
|
|
|
+ >
|
|
|
+ <Skeleton className="h-4 my-2 w-full" />
|
|
|
+ </TableCell>
|
|
|
+ ))}
|
|
|
+ </TableRow>
|
|
|
+ ))
|
|
|
+ ) : table.getRowModel().rows?.length ? (
|
|
|
table.getRowModel().rows.map(row => (
|
|
|
- <TableRow key={row.id} data-state={row.getIsSelected() && 'selected'}>
|
|
|
+ <TableRow
|
|
|
+ key={row.id}
|
|
|
+ data-state={row.getIsSelected() && 'selected'}
|
|
|
+ className="animate-in fade-in duration-100"
|
|
|
+ >
|
|
|
{row.getVisibleCells().map(cell => (
|
|
|
- <TableCell key={cell.id}>
|
|
|
+ <TableCell key={cell.id} className="h-12">
|
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
|
</TableCell>
|
|
|
))}
|
|
|
</TableRow>
|
|
|
))
|
|
|
) : (
|
|
|
- <TableRow>
|
|
|
+ <TableRow className="animate-in fade-in duration-100">
|
|
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
|
|
No results.
|
|
|
</TableCell>
|