"use client" import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" import { formatDate } from "@/lib/utils" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { ExtendedPageVisit } from "../validation" import { Eye, ExternalLink, Clock, User, Ellipsis } from "lucide-react" interface GetColumnsProps { setRowAction: React.Dispatch | null>> } export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { return [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-0.5" /> ), enableSorting: false, enableHiding: false, }, { id: "사용자", header: "사용자", columns: [ { accessorKey: "userEmail", header: ({ column }) => ( ), cell: ({ row }) => { const userEmail = row.getValue("userEmail") as string | null const userName = row.original.userName if (!userEmail) { return (
익명
) } return (
{userEmail} {userName && ( {userName} )}
) }, }, ], }, { id: "페이지 정보", header: "페이지 정보", columns: [ { accessorKey: "route", header: ({ column }) => ( ), cell: ({ row }) => { const route = row.getValue("route") as string const pageTitle = row.original.pageTitle return (
{route} {pageTitle && ( {pageTitle} )}
) }, }, { accessorKey: "visitedAt", header: ({ column }) => ( ), cell: ({ row }) => { const date = row.getValue("visitedAt") as Date return (
{formatDate(date, 'KR')}
{formatDate(date)}
) }, }, { accessorKey: "duration", header: ({ column }) => ( ), cell: ({ row }) => { const duration = row.getValue("duration") as number | null const isLongVisit = row.original.isLongVisit if (!duration) { return - } const minutes = Math.floor(duration / 60) const seconds = duration % 60 let displayText = "" if (minutes > 0) { displayText = `${minutes}분 ${seconds}초` } else { displayText = `${seconds}초` } return (
{isLongVisit && } {displayText}
) }, }, ], }, { id: "환경 정보", header: "환경 정보", columns: [ { accessorKey: "deviceType", header: ({ column }) => ( ), cell: ({ row }) => { const deviceType = row.getValue("deviceType") as string const variants = { desktop: "default", mobile: "secondary", tablet: "outline", } as const return ( {deviceType} ) }, }, { accessorKey: "browserName", header: ({ column }) => ( ), cell: ({ row }) => { const browserName = row.getValue("browserName") as string | null const osName = row.original.osName return (
{browserName || "Unknown"} {osName && ( {osName} )}
) }, }, { accessorKey: "ipAddress", header: ({ column }) => ( ), cell: ({ row }) => ( {row.getValue("ipAddress")} ), }, ], }, { id: "추가 정보", header: "추가 정보", columns: [ { accessorKey: "referrer", header: ({ column }) => ( ), cell: ({ row }) => { const referrer = row.getValue("referrer") as string | null if (!referrer) { return 직접 접근 } try { const url = new URL(referrer) return (
{url.hostname}
) } catch { return ( {referrer} ) } }, }, ], }, // { // id: "actions", // cell: function Cell({ row }) { // const visit = row.original // return ( // // // // // // setRowAction({ type: "view", row })} // > // // {visit.userEmail && ( // setRowAction({ type: "viewUserActivity", row })} // > // // )} // {visit.route && ( // setRowAction({ type: "viewPageStats", row })} // > // // )} // // // ) // }, // enableSorting: false, // enableHiding: false, // }, ] }