🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
perf(sessions): display only first 10 users; show rest in paginated popover (#5599)
marliessophie0263b4098772
diff --git a/web/src/components/session/index.tsx b/web/src/components/session/index.tsxindex 334eb4d359..2ae61b562f 100644--- a/web/src/components/session/index.tsx+++ b/web/src/components/session/index.tsx@@ -18,9 +18,107 @@ import useLocalStorage from "@/src/components/useLocalStorage";import { CommentDrawerButton } from "@/src/features/comments/CommentDrawerButton";import { useSession } from "next-auth/react";import Page from "@/src/components/layouts/page";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/src/components/ui/popover";+import { ScrollArea } from "@/src/components/ui/scroll-area";+import { Label } from "@/src/components/ui/label";// some projects have thousands of traces in a sessions, paginate to avoid rendering all at onceconst PAGE_SIZE = 50;+// some projects have thousands of users in a session, paginate to avoid rendering all at once+const INITIAL_USERS_DISPLAY_COUNT = 10;+const USERS_PER_PAGE_IN_POPOVER = 50;++export function SessionUsers({+ projectId,+ users,+}: {+ projectId: string;+ users?: string[];+}) {+ const [page, setPage] = useState(0);++ if (!users) return null;++ const initialUsers = users?.slice(0, INITIAL_USERS_DISPLAY_COUNT);+ const remainingUsers = users?.slice(INITIAL_USERS_DISPLAY_COUNT);++ return (+ <div className="flex flex-wrap items-center gap-2">+ {initialUsers.map((userId: string) => (+ <Link+ key={userId}+ href={`/project/${projectId}/users/${encodeURIComponent(userId ?? "")}`}+ >+ <Badge className="max-w-[300px] truncate">User ID: {userId}</Badge>+ </Link>+ ))}++ {remainingUsers.length > 0 && (+ <Popover modal>+ <PopoverTrigger asChild>+ <Button variant="outline" size="sm" className="mt-0.5">+ +{remainingUsers.length} more users+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-[300px]">+ <Label className="text-base capitalize">Session Users</Label>+ <ScrollArea className="h-[300px]">+ <div className="flex flex-col gap-2 p-2">+ {remainingUsers+ .slice(+ page * USERS_PER_PAGE_IN_POPOVER,+ (page + 1) * USERS_PER_PAGE_IN_POPOVER,+ )+ .map((userId: string) => (+ <Link+ key={userId}+ href={`/project/${projectId}/users/${encodeURIComponent(userId ?? "")}`}+ className="block hover:bg-accent"+ >+ <Badge className="max-w-[260px] truncate">+ User ID: {userId}+ </Badge>+ </Link>+ ))}+ </div>+ </ScrollArea>+ {remainingUsers.length > USERS_PER_PAGE_IN_POPOVER && (+ <div className="flex items-center justify-between border-t p-2 pt-4">+ <Button+ variant="outline"+ size="sm"+ onClick={() => setPage((p) => Math.max(0, p - 1))}+ disabled={page === 0}+ >+ Previous+ </Button>+ <span className="text-sm text-muted-foreground">+ Page {page + 1} of{" "}+ {Math.ceil(remainingUsers.length / USERS_PER_PAGE_IN_POPOVER)}+ </span>+ <Button+ variant="outline"+ size="sm"+ onClick={() => setPage((p) => p + 1)}+ disabled={+ (page + 1) * USERS_PER_PAGE_IN_POPOVER >=+ remainingUsers.length+ }+ >+ Next+ </Button>+ </div>+ )}+ </PopoverContent>+ </Popover>+ )}+ </div>+ );+}export const SessionPage: React.FC<{sessionId: string;@@ -139,16 +237,7 @@ export const SessionPage: React.FC<{}}><div className="flex flex-wrap gap-2">- {session.data?.users.filter(Boolean).map((userId) => (- <Link- key={userId}- href={`/project/${projectId}/users/${encodeURIComponent(- userId ?? "",- )}`}- >- <Badge className="max-w-[300px] truncate">User ID: {userId}</Badge>- </Link>- ))}+ <SessionUsers projectId={projectId} users={session.data?.users} /><Badge variant="outline">Traces: {session.data?.traces.length}</Badge>{session.data && (<Badge variant="outline">diff --git a/web/src/components/trace/index.tsx b/web/src/components/trace/index.tsxindex 322ba173c6..dc958fedea 100644--- a/web/src/components/trace/index.tsx+++ b/web/src/components/trace/index.tsx@@ -383,7 +383,9 @@ export function TracePage({return (<PageheaderProps={{- title: `${trace.data.name}: ${trace.data.id}`,+ title: trace.data.name+ ? `${trace.data.name}: ${trace.data.id}`+ : trace.data.id,itemType: "TRACE",breadcrumb: [{