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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | 36x 69x 36x 69x 69x 69x 69x 1x 1x 3x 36x 36x 36x 69x | /**
* Collections table component
* Displays collections with sorting and actions
*/
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Eye, Pencil, Trash2, Database } from 'lucide-react';
import type { CollectionListItem } from '@/services/collections.service';
import { DataTable, type Column, type DispatchPagination, type DispatchSorting } from '@/components/common/DataTable';
interface CollectionsTableProps {
collections: CollectionListItem[];
sortBy: string;
sortOrder: 'asc' | 'desc';
onSort: (column: string) => void;
onView: (collection: CollectionListItem) => void;
onEdit: (collection: CollectionListItem) => void;
onDelete: (collection: CollectionListItem) => void;
onManageRecords?: (collection: CollectionListItem) => void;
// Pagination props
totalItems: number;
page: number;
pageSize: number;
onPageChange: (page: number) => void;
onPageSizeChange: (pageSize: number) => void;
}
export default function CollectionsTable({
collections,
sortBy,
sortOrder,
onSort,
onView,
onEdit,
onDelete,
onManageRecords,
totalItems,
page,
pageSize,
onPageChange,
onPageSizeChange,
}: CollectionsTableProps) {
const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
};
const columns: Column<CollectionListItem>[] = [
{
header: 'Name',
accessorKey: 'name',
sortable: true,
className: 'font-medium',
style: { minWidth: 180 },
render: (collection) => (
<span className="flex items-center gap-2">
<span className="font-medium">{collection.name}</span>
{collection.has_public_access && (
<Badge variant="outline" className="text-xs border-green-500 text-green-600">
Public
</Badge>
)}
</span>
),
},
{
header: 'ID',
accessorKey: 'id',
style: { minWidth: 120, maxWidth: 120 },
render: (collection) => (
<span className="font-mono text-xs text-muted-foreground">
{collection.id.substring(0, 8)}...
</span>
),
},
{
header: 'Fields',
accessorKey: 'fields_count',
sortable: true,
style: { minWidth: 80, maxWidth: 100 },
},
{
header: 'Records',
accessorKey: 'records_count',
sortable: true,
style: { minWidth: 90, maxWidth: 110 },
},
{
header: 'Created',
accessorKey: 'created_at',
sortable: true,
style: { minWidth: 130 },
render: (collection) => <span>{formatDate(collection.created_at)}</span>,
},
{
header: 'Actions',
className: 'text-right',
style: { minWidth: 160 },
render: (collection) => (
<div className="flex justify-end gap-2">
<Button
variant="ghost"
size="icon"
onClick={() => onManageRecords?.(collection)}
title="Manage records"
>
<Database className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={() => onView(collection)}
title="View schema"
>
<Eye className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={() => onEdit(collection)}
title="Edit schema"
>
<Pencil className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={() => onDelete(collection)}
title="Delete collection"
>
<Trash2 className="h-4 w-4 text-destructive" />
</Button>
</div>
),
},
];
const pagination: DispatchPagination = {
page,
pageSize,
onPageChange,
onPageSizeChange,
};
const sorting: DispatchSorting = {
sortBy,
sortOrder,
onSort,
};
return (
<DataTable
data={collections}
columns={columns}
keyExtractor={(item) => item.id}
pagination={pagination}
sorting={sorting}
totalItems={totalItems}
noDataMessage="No collections found"
/>
);
}
|