Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Favorite Button to Traces #173 #281

Open
wants to merge 34 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
034c95d
Merge pull request #111 from lmnr-ai/dev
dinmukhamedm Oct 30, 2024
3641ee2
Merge pull request #117 from lmnr-ai/dev
dinmukhamedm Oct 31, 2024
5e25639
Merge pull request #126 from lmnr-ai/dev
dinmukhamedm Nov 1, 2024
67a36ba
Merge pull request #137 from lmnr-ai/dev
dinmukhamedm Nov 2, 2024
b73967f
Merge pull request #165 from lmnr-ai/dev
dinmukhamedm Nov 6, 2024
28e698b
Merge pull request #170 from lmnr-ai/dev
dinmukhamedm Nov 7, 2024
7ae1f99
Merge pull request #172 from lmnr-ai/dev
dinmukhamedm Nov 7, 2024
11842e4
Merge pull request #175 from lmnr-ai/dev
dinmukhamedm Nov 7, 2024
e27801d
Merge pull request #177 from lmnr-ai/dev
dinmukhamedm Nov 8, 2024
00ab4ef
Merge pull request #184 from lmnr-ai/dev
dinmukhamedm Nov 9, 2024
6a4ce29
Merge pull request #186 from lmnr-ai/dev
skull8888888 Nov 9, 2024
9cccb42
Merge pull request #193 from lmnr-ai/dev
dinmukhamedm Nov 10, 2024
8553e63
Merge pull request #198 from lmnr-ai/dev
dinmukhamedm Nov 12, 2024
c7681e5
Merge pull request #206 from lmnr-ai/dev
dinmukhamedm Nov 14, 2024
124fd0d
eval time progression (#210)
skull8888888 Nov 15, 2024
d9e7d65
Merge pull request #212 from lmnr-ai/dev
skull8888888 Nov 15, 2024
f3a0450
Merge pull request #214 from lmnr-ai/dev
dinmukhamedm Nov 15, 2024
b30e993
Merge pull request #216 from lmnr-ai/dev
dinmukhamedm Nov 15, 2024
2bd68d8
Merge pull request #221 from lmnr-ai/dev
dinmukhamedm Nov 18, 2024
4a0dc5e
Merge pull request #227 from lmnr-ai/dev
skull8888888 Nov 20, 2024
74960f1
Merge pull request #235 from lmnr-ai/dev
skull8888888 Nov 22, 2024
65de466
Merge pull request #245 from lmnr-ai/dev
dinmukhamedm Dec 2, 2024
ce2dac1
Merge pull request #247 from lmnr-ai/dev
dinmukhamedm Dec 2, 2024
d244713
Merge pull request #253 from lmnr-ai/dev
dinmukhamedm Dec 3, 2024
8b91d3a
Merge pull request #259 from lmnr-ai/dev
dinmukhamedm Dec 4, 2024
09c42ce
Merge pull request #264 from lmnr-ai/dev
dinmukhamedm Dec 5, 2024
08b8592
Add Favorite to Traces
patricksolka Dec 17, 2024
42de3fb
Update favorite component
patricksolka Dec 17, 2024
1f2dbcd
Update favoriteButton inside of datatable
patricksolka Dec 17, 2024
e5dbcc4
Add placeholder functions for add and remove favorite
patricksolka Dec 17, 2024
ac8dc6f
seperate state/function to manage the fav status independently from r…
patricksolka Dec 17, 2024
5cf0c46
Merge pull request #287 from lmnr-ai/dev
dinmukhamedm Dec 21, 2024
50defb1
Merge pull request #291 from lmnr-ai/dev
dinmukhamedm Dec 25, 2024
74ad33a
Merge branch 'main' into main
patricksolka Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions frontend/components/ui/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TData> {
Expand Down Expand Up @@ -113,6 +115,14 @@ export function DataTable<TData>({
setRowSelection({});
}, [data]);

const addFavorite = () => {
console.log('Added favorite - placeholder');
};

const removeFavorite = () => {
console.log('Removed favorite - placeholder');
};

if (enableRowSelection) {
columns.unshift({
id: '__row_selection',
Expand All @@ -127,7 +137,7 @@ export function DataTable<TData>({
onSelectAllAcrossPages?.(false);
}
}}
onChange={table.getToggleAllRowsSelectedHandler()} // TODO: Think about row selection per page
onChange={table.getToggleAllRowsSelectedHandler()}
onClick={(e) => {
e.stopPropagation();
table.toggleAllRowsSelected(!table.getIsAllRowsSelected());
Expand All @@ -151,7 +161,31 @@ export function DataTable<TData>({
row.toggleSelected(!row.getIsSelected());
}}
/>
)
),
});
columns.splice(1, 0, {
id: '__favorite',
enableResizing: false,
header: ({ table }) => (
<Favorite
isSelected={allRowsAcrossAllPagesSelected}
isHeader={true}
onToggleFavorite={() => {}}
/>
),
size: 40,
cell: ({ row }) => (
<Favorite
isSelected={row.getIsSelected()}
onToggleFavorite={() => {
if (!row.getIsSelected()) {
addFavorite();
} else {
removeFavorite();
}
}}
/>
),
});
}

Expand Down
55 changes: 55 additions & 0 deletions frontend/components/ui/favorite.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div
ref={ref}
className={cn(
'h-4 w-4 bg-secondary/30 flex items-center justify-center cursor-pointer',
className
)}
onClick={(e) => {
e.stopPropagation();
handleToggle();
}}
{...props}
>
<Star
size={18}
strokeWidth={1.5}
fill={isFavorite ? '#FACC15' : 'none'}
stroke={isFavorite ? '#FACC15' : 'currentColor'}
className={isFavorite ? 'text-secondary' : 'text-gray-400'}
/>
</div>
);
});

Favorite.displayName = 'Favorite';

export { Favorite };