import { useNumber } from '@/hooks/use-numer-formatter'; import { useTRPC } from '@/integrations/trpc/react'; import { useQuery } from '@tanstack/react-query'; import { ExternalLinkIcon } from 'lucide-react'; import { prop, uniqBy } from 'ramda'; import { OverviewWidgetTable } from '../overview/overview-widget-table'; import { SerieIcon } from '../report-chart/common/serie-icon'; import { Tooltiper } from '../ui/tooltip'; interface RealtimePathsProps { projectId: string; } export function RealtimePaths({ projectId }: RealtimePathsProps) { const trpc = useTRPC(); const query = useQuery( trpc.realtime.paths.queryOptions({ projectId, }), ); const data = query.data ?? []; const maxCount = Math.max(...data.map((item) => item.count)); const number = useNumber(); // Get unique origins for header icons const unique = uniqBy(prop('origin'), data) .filter((i) => !!i.origin.trim()) .slice(0, 5); return (
Paths
{unique.map((item) => ( ))}
item.path + item.origin} getColumnPercentage={(item) => item.count / maxCount} columns={[ { name: 'Path', width: 'w-full', render(item) { return (
{item.path || '(Not set)'} {item.origin && ( )}
); }, }, { name: 'Duration', width: '75px', render(item) { return number.shortWithUnit(item.avg_duration, 'min'); }, }, { name: 'Events', width: '60px', render(item) { return (
{number.short(item.count)}
); }, }, { name: 'Sessions', width: '82px', render(item) { return (
{number.short(item.unique_sessions)}
); }, }, ]} />
); }