/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { flexRender, type Cell, type Table } from '@tanstack/react-table' import { Database } from 'lucide-react' import { useTranslation } from 'react-i18next' import { formatTimestampToDate } from '@/lib/format' import { cn } from '@/lib/utils' import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from '@/components/ui/empty' import { Skeleton } from '@/components/ui/skeleton' import { dotColorMap, textColorMap, type StatusVariant, } from '@/components/status-badge' import { LOG_TYPE_ENUM } from '../constants' import { getLogTypeConfig } from '../lib/utils' import type { LogCategory } from '../types' const logTypeRowTint: Record = { [LOG_TYPE_ENUM.ERROR]: 'bg-rose-50/40 dark:bg-rose-950/20 border-rose-200/50 dark:border-rose-900/30', [LOG_TYPE_ENUM.REFUND]: 'bg-blue-50/30 dark:bg-blue-950/15 border-blue-200/50 dark:border-blue-900/30', } interface UsageLogsMobileListProps { table: Table isLoading?: boolean emptyTitle?: string emptyDescription?: string logCategory: LogCategory } function UsageLogsMobileSkeleton() { return (
{[1, 2, 3].map((i) => (
{[1, 2, 3, 4, 5, 6].map((j) => (
))}
))}
) } function CompactCell({ cell, fallback = '-', className, primaryOnly = false, }: { cell?: Cell fallback?: string className?: string primaryOnly?: boolean }) { return (
*:not(:first-child)]:hidden', className )} > {cell ? ( flexRender(cell.column.columnDef.cell, cell.getContext()) ) : ( {fallback} )}
) } function SummaryField({ label, cell, className, valueClassName, primaryOnly = false, }: { label: string cell?: Cell className?: string valueClassName?: string primaryOnly?: boolean }) { if (!cell) return null return (
{label}
) } function MobileLogTimeStatus({ createdAt, type, }: { createdAt: unknown type: unknown }) { const { t } = useTranslation() const timestamp = typeof createdAt === 'number' ? createdAt : undefined const logType = typeof type === 'number' ? type : undefined const config = getLogTypeConfig(logType ?? LOG_TYPE_ENUM.UNKNOWN) const variant = config.color as StatusVariant return (
{formatTimestampToDate(timestamp)}
) } function CommonLogsCard({ cells, }: { cells: Map> }) { const { t } = useTranslation() const modelCell = cells.get('model_name') const quotaCell = cells.get('quota') const rowData = cells.get('created_at')?.row.original as | Record | undefined return (
{t('Time')}
) } function TaskLogsCard({ cells, }: { cells: Map> }) { const { t } = useTranslation() const taskIdCell = cells.get('task_id') const statusCell = cells.get('status') const submitTimeCell = cells.get('submit_time') return (
) } function DrawingLogsCard({ cells, }: { cells: Map> }) { const { t } = useTranslation() const actionCell = cells.get('action') const codeCell = cells.get('code') const submitTimeCell = cells.get('submit_time') return (
) } export function UsageLogsMobileList({ table, isLoading = false, emptyTitle, emptyDescription, logCategory, }: UsageLogsMobileListProps) { const { t } = useTranslation() const resolvedEmptyTitle = emptyTitle ?? t('No Logs Found') const resolvedEmptyDescription = emptyDescription ?? t('No usage logs available. Logs will appear here once API calls are made.') if (isLoading) { return } const rows = table.getRowModel().rows if (!rows || rows.length === 0) { return (
{resolvedEmptyTitle} {resolvedEmptyDescription}
) } return (
{rows.map((row) => { const cells = new Map( row.getVisibleCells().map((cell) => [cell.column.id, cell]) ) const logType = (row.original as Record).type as | number | undefined const tintClass = logType != null ? (logTypeRowTint[logType] ?? '') : '' return (
{logCategory === 'common' && } {logCategory === 'task' && } {logCategory === 'drawing' && }
) })}
) }