import { formatDateTime, formatTime } from '@/utils/date'; import type { ColumnDef } from '@tanstack/react-table'; import { isToday } from 'date-fns'; import { ColumnCreatedAt } from '@/components/column-created-at'; import { ProjectLink } from '@/components/links'; import { SerieIcon } from '@/components/report-chart/common/serie-icon'; import { createHeaderColumn } from '@/components/ui/data-table/data-table-helpers'; import type { RouterOutputs } from '@/trpc/client'; import type { INotificationPayload } from '@openpanel/db'; function getEventFromPayload(payload: INotificationPayload | null) { if (payload?.type === 'event') { return payload.event; } if (payload?.type === 'funnel') { return payload.funnel[0] || null; } return null; } export function useColumns() { const columns: ColumnDef[] = [ { accessorKey: 'title', header: 'Title', cell({ row }) { const { title } = row.original; return (
{/* {isReadAt === null && Unread} */} {title}
); }, meta: { variant: 'text', placeholder: 'Search', label: 'Title', }, }, { accessorKey: 'message', header: 'Message', cell({ row }) { const { message } = row.original; return (
{message}
); }, meta: { label: 'Message', hidden: true, }, }, { accessorKey: 'integration', header: 'Integration', cell({ row }) { const integration = row.original.integration; return
{integration?.name}
; }, meta: { label: 'Integration', }, }, { accessorKey: 'notificationRule', header: 'Rule', cell({ row }) { const rule = row.original.notificationRule; return
{rule?.name}
; }, meta: { label: 'Rule', hidden: true, }, }, { accessorKey: 'country', header: 'Country', cell({ row }) { const { payload } = row.original; const event = getEventFromPayload(payload); if (!event) { return null; } return (
{event.city}
); }, meta: { label: 'Country', }, }, { accessorKey: 'os', header: 'OS', cell({ row }) { const { payload } = row.original; const event = getEventFromPayload(payload); if (!event) { return null; } return (
{event.os}
); }, meta: { label: 'OS', }, }, { accessorKey: 'browser', header: 'Browser', cell({ row }) { const { payload } = row.original; const event = getEventFromPayload(payload); if (!event) { return null; } return (
{event.browser}
); }, meta: { label: 'Browser', }, }, { accessorKey: 'profile', header: createHeaderColumn('Profile'), cell({ row }) { const { payload } = row.original; const event = getEventFromPayload(payload); if (!event) { return null; } return ( {event.profileId} ); }, meta: { label: 'Profile', }, }, { accessorKey: 'createdAt', header: 'Created at', size: ColumnCreatedAt.size, cell: ({ row }) => { const item = row.original; return {item.createdAt}; }, filterFn: 'isWithinRange', meta: { variant: 'dateRange', placeholder: 'Created at', label: 'Created at', }, }, ]; return columns; }