diff --git a/frontend/components/ui/datatable.tsx b/frontend/components/ui/datatable.tsx index 3de43d757..36aad1b35 100644 --- a/frontend/components/ui/datatable.tsx +++ b/frontend/components/ui/datatable.tsx @@ -16,11 +16,13 @@ import { Checkbox } from "@/components/ui/checkbox"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { cn } from "@/lib/utils"; -import { Button } from "./button"; -import { DataTablePagination } from "./datatable-pagination"; -import { Label } from "./label"; -import { ScrollArea, ScrollBar } from "./scroll-area"; -import { Skeleton } from "./skeleton"; +import { Button } from './button'; +import { DataTablePagination } from './datatable-pagination'; +import { Label } from './label'; +import { ScrollArea, ScrollBar } from './scroll-area'; +import { Skeleton } from './skeleton'; +import { Favorite } from '@/components/ui/favorite'; + const DEFAULT_PAGE_SIZE = 50; interface DataTableProps { @@ -150,10 +152,86 @@ export function DataTable({ setRowSelection({}); }, [data]); + + const addFavorite = () => { + console.log('Added favorite - placeholder'); + }; + + const removeFavorite = () => { + console.log('Removed favorite - placeholder'); + }; + + if (enableRowSelection) { + columns.unshift({ + id: '__row_selection', + enableResizing: false, + header: ({ table }) => ( + { + if (!checked) { + setAllRowsAcrossAllPagesSelected(false); + onSelectAllAcrossPages?.(false); + } + }} + onChange={table.getToggleAllRowsSelectedHandler()} + onClick={(e) => { + e.stopPropagation(); + table.toggleAllRowsSelected(!table.getIsAllRowsSelected()); + }} + /> + ), + size: 24, + cell: ({ row }) => ( + { + if (!checked) { + setAllRowsAcrossAllPagesSelected(false); + onSelectAllAcrossPages?.(false); + } + }} + onChange={row.getToggleSelectedHandler()} + onClick={(e) => { + e.stopPropagation(); + row.toggleSelected(!row.getIsSelected()); + }} + /> + ), + }); + columns.splice(1, 0, { + id: '__favorite', + enableResizing: false, + header: ({ table }) => ( + {}} + /> + ), + size: 40, + cell: ({ row }) => ( + { + if (!row.getIsSelected()) { + addFavorite(); + } else { + removeFavorite(); + } + }} + /> + ), + }); + } + const selectionColumns = enableRowSelection ? [checkboxColumn(setAllRowsAcrossAllPagesSelected, onSelectAllAcrossPages)] : []; + const table = useReactTable({ data: data ?? [], columns: [...selectionColumns, ...columns], diff --git a/frontend/components/ui/favorite.tsx b/frontend/components/ui/favorite.tsx new file mode 100644 index 000000000..3341c8ac8 --- /dev/null +++ b/frontend/components/ui/favorite.tsx @@ -0,0 +1,55 @@ +"use client"; + +import * as React from 'react'; +import { Star } from 'lucide-react'; +import { cn } from '@/lib/utils'; + +interface FavoriteProps { + isSelected: boolean; + isHeader?: boolean; + onToggleFavorite: () => void; + className?: string; +} + +const Favorite = React.forwardRef< + React.ElementRef<'div'>, + FavoriteProps +>(({ isSelected, onToggleFavorite, className, isHeader, ...props }, ref) => { + const [isFavorite, setIsFavorite] = React.useState(false); + + const handleToggle = () => { + if (!isHeader) { + setIsFavorite((prev) => !prev); + onToggleFavorite(); + } + }; + + return ( +
{ + e.stopPropagation(); + handleToggle(); + }} + {...props} + > + +
+ ); +}); + +Favorite.displayName = 'Favorite'; + +export { Favorite }; + +