diff --git a/frontend/components/ui/datatable.tsx b/frontend/components/ui/datatable.tsx index ffe8a3e..6f3845f 100644 --- a/frontend/components/ui/datatable.tsx +++ b/frontend/components/ui/datatable.tsx @@ -28,6 +28,8 @@ 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 { @@ -113,6 +115,14 @@ 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', @@ -127,7 +137,7 @@ export function DataTable({ onSelectAllAcrossPages?.(false); } }} - onChange={table.getToggleAllRowsSelectedHandler()} // TODO: Think about row selection per page + onChange={table.getToggleAllRowsSelectedHandler()} onClick={(e) => { e.stopPropagation(); table.toggleAllRowsSelected(!table.getIsAllRowsSelected()); @@ -151,7 +161,31 @@ export function DataTable({ row.toggleSelected(!row.getIsSelected()); }} /> - ) + ), + }); + columns.splice(1, 0, { + id: '__favorite', + enableResizing: false, + header: ({ table }) => ( + {}} + /> + ), + size: 40, + cell: ({ row }) => ( + { + if (!row.getIsSelected()) { + addFavorite(); + } else { + removeFavorite(); + } + }} + /> + ), }); } diff --git a/frontend/components/ui/favorite.tsx b/frontend/components/ui/favorite.tsx new file mode 100644 index 0000000..3341c8a --- /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 }; + +