import { EventIcon } from '@/components/events/event-icon'; import { ProjectLink } from '@/components/links'; import { SerieIcon } from '@/components/report-chart/common/serie-icon'; import { useNumber } from '@/hooks/use-numer-formatter'; import { pushModal } from '@/modals'; import { getProfileName } from '@/utils/getters'; import type { ColumnDef } from '@tanstack/react-table'; import { ColumnCreatedAt } from '@/components/column-created-at'; import { ProfileAvatar } from '@/components/profiles/profile-avatar'; import { KeyValueGrid } from '@/components/ui/key-value-grid'; import type { IServiceEvent } from '@openpanel/db'; export function useColumns() { const number = useNumber(); const columns: ColumnDef[] = [ { accessorKey: 'createdAt', header: 'Created at', size: ColumnCreatedAt.size, cell: ({ row }) => { const session = row.original; return {session.createdAt}; }, }, { size: 300, accessorKey: 'name', header: 'Name', cell({ row }) { const { name, path, duration, properties, revenue } = row.original; const renderName = () => { if (name === 'screen_view') { if (path.includes('/')) { return {path}; } return ( <> Screen: {path} ); } if (name === 'revenue' && revenue) { return `${name} (${number.currency(revenue / 100)})`; } return name.replace(/_/g, ' '); }; const renderDuration = () => { if (name === 'screen_view') { return ( {number.shortWithUnit(duration / 1000, 'min')} ); } return null; }; return (
{renderDuration()}
); }, }, { accessorKey: 'profileId', header: 'Profile', cell({ row }) { const { profile, profileId, deviceId } = row.original; if (profile) { return ( {getProfileName(profile)} ); } if (profileId && profileId !== deviceId) { return ( Unknown ); } if (deviceId) { return ( Anonymous ); } return null; }, }, { accessorKey: 'sessionId', header: 'Session ID', size: 320, meta: { hidden: true, }, }, { accessorKey: 'deviceId', header: 'Device ID', size: 320, meta: { hidden: true, }, }, { accessorKey: 'country', header: 'Country', size: 150, cell({ row }) { const { country, city } = row.original; return (
{city}
); }, }, { accessorKey: 'os', header: 'OS', size: 130, cell({ row }) { const { os } = row.original; return (
{os}
); }, }, { accessorKey: 'browser', header: 'Browser', size: 110, cell({ row }) { const { browser } = row.original; return (
{browser}
); }, }, { accessorKey: 'properties', header: 'Properties', size: 400, meta: { hidden: true, }, cell({ row }) { const { properties } = row.original; const filteredProperties = Object.fromEntries( Object.entries(properties || {}).filter( ([key]) => !key.startsWith('__'), ), ); const items = Object.entries(filteredProperties); const limit = 2; const data = items.slice(0, limit).map(([key, value]) => ({ name: key, value: value, })); if (items.length > limit) { data.push({ name: '', value: `${items.length - limit} more item${items.length - limit === 1 ? '' : 's'}`, }); } if (data.length === 0) { return null; } return ; }, }, ]; return columns; }