'use client'; import { useCallback } from 'react'; import { format } from 'date-fns'; import { ColumnDef } from '@tanstack/react-table'; import { zhCN, enUS } from 'date-fns/locale'; import { FileText } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { extractNumberID } from '@/lib/utils'; import { usePaginationSearch } from '@/hooks/use-pagination-search'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { DataTableColumnHeader } from '@/components/data-table-column-header'; import type { Thread } from '../data/schema'; export function useThreadsColumns(): ColumnDef[] { const { t, i18n } = useTranslation(); const locale = i18n.language === 'zh' ? zhCN : enUS; const { navigateWithSearch } = usePaginationSearch({ defaultPageSize: 20 }); const columns: ColumnDef[] = [ { accessorKey: 'id', header: ({ column }) => , cell: ({ row }) => { const handleClick = useCallback(() => { navigateWithSearch({ to: '/project/threads/$threadId', params: { threadId: row.original.id }, }); }, [row.original.id, navigateWithSearch]); return ( ); }, enableSorting: true, enableHiding: false, }, { accessorKey: 'threadID', header: ({ column }) => , cell: ({ row }) => { const threadID = row.getValue('threadID') as string; return (
{threadID}
); }, enableSorting: false, }, { accessorKey: 'firstUserQuery', header: ({ column }) => , cell: ({ row }) => { const query = row.getValue('firstUserQuery') as string | null | undefined; return (
{query || '-'}
); }, enableSorting: false, }, // { // id: 'project', // header: ({ column }) => , // cell: ({ row }) => { // const project = row.original.project // return ( //
// {project?.name || t('threads.columns.unknownProject')} //
// ) // }, // enableSorting: false, // }, { id: 'traceCount', header: ({ column }) => , cell: ({ row }) => { const count = row.original.tracesSummary?.totalCount ?? 0; return ( {count} ); }, enableSorting: false, }, { accessorKey: 'createdAt', header: ({ column }) => , cell: ({ row }) => { const date = new Date(row.getValue('createdAt')); return
{format(date, 'yyyy-MM-dd HH:mm:ss', { locale })}
; }, }, { id: 'details', header: ({ column }) => , cell: ({ row }) => { const handleViewDetails = () => { navigateWithSearch({ to: '/project/threads/$threadId', params: { threadId: row.original.id }, }); }; return ( ); }, }, ]; return columns; }