"use client" import { Button } from "@/components/ui/button" import type { ColumnDef } from "@tanstack/react-table" import { ArrowUpDown, Clock, Loader2, CheckCircle2, XCircle, Trash2, Check, ListFilter } from "lucide-react" import Image from "next/image" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" import { cn, getRepoImageSrc } from "@/lib/utils" import { RepoIndexingStatus } from "@sourcebot/db"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import Link from "next/link" import { getBrowsePath } from "../browse/hooks/utils" export type RepositoryColumnInfo = { repoId: number repoName: string; repoDisplayName: string imageUrl?: string repoIndexingStatus: RepoIndexingStatus lastIndexed: string } const statusLabels = { [RepoIndexingStatus.NEW]: "Queued", [RepoIndexingStatus.IN_INDEX_QUEUE]: "Queued", [RepoIndexingStatus.INDEXING]: "Indexing", [RepoIndexingStatus.INDEXED]: "Indexed", [RepoIndexingStatus.FAILED]: "Failed", [RepoIndexingStatus.IN_GC_QUEUE]: "Deleting", [RepoIndexingStatus.GARBAGE_COLLECTING]: "Deleting", [RepoIndexingStatus.GARBAGE_COLLECTION_FAILED]: "Deletion Failed" }; const StatusIndicator = ({ status }: { status: RepoIndexingStatus }) => { let icon = null let description = "" let className = "" switch (status) { case RepoIndexingStatus.NEW: case RepoIndexingStatus.IN_INDEX_QUEUE: icon = description = "Repository is queued for indexing" className = "text-yellow-600 bg-yellow-50 dark:bg-yellow-900/20 dark:text-yellow-400" break case RepoIndexingStatus.INDEXING: icon = description = "Repository is being indexed" className = "text-blue-600 bg-blue-50 dark:bg-blue-900/20 dark:text-blue-400" break case RepoIndexingStatus.INDEXED: icon = description = "Repository has been successfully indexed" className = "text-green-600 bg-green-50 dark:bg-green-900/20 dark:text-green-400" break case RepoIndexingStatus.FAILED: icon = description = "Repository indexing failed" className = "text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400" break case RepoIndexingStatus.IN_GC_QUEUE: case RepoIndexingStatus.GARBAGE_COLLECTING: icon = description = "Repository is being deleted" className = "text-gray-600 bg-gray-50 dark:bg-gray-900/20 dark:text-gray-400" break case RepoIndexingStatus.GARBAGE_COLLECTION_FAILED: icon = description = "Repository deletion failed" className = "text-red-600 bg-red-50 dark:bg-red-900/20 dark:text-red-400" break } return (
{icon} {statusLabels[status]}

{description}

) } export const columns = (domain: string): ColumnDef[] => [ { accessorKey: "repoDisplayName", header: 'Repository', cell: ({ row: { original: { repoId, repoName, repoDisplayName, imageUrl } } }) => { return (
{imageUrl ? ( {`${repoDisplayName} ) : (
{repoDisplayName.charAt(0)}
)}
{repoDisplayName.length > 40 ? `${repoDisplayName.slice(0, 40)}...` : repoDisplayName}
) }, }, { accessorKey: "repoIndexingStatus", header: ({ column }) => { const uniqueLabels = Array.from(new Set(Object.values(statusLabels))); const currentFilter = column.getFilterValue() as string | undefined; return (
column.setFilterValue(undefined)}> All {uniqueLabels.map((label) => ( column.setFilterValue(label)}> {label} ))}
) }, cell: ({ row }) => { return }, filterFn: (row, id, value) => { if (value === undefined) return true; const status = row.getValue(id) as RepoIndexingStatus; return statusLabels[status] === value; }, }, { accessorKey: "lastIndexed", header: ({ column }) => (
), cell: ({ row }) => { if (!row.original.lastIndexed) { return
-
; } const date = new Date(row.original.lastIndexed) return (
{date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", })}
{date .toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit", hour12: false, }) .toLowerCase()}
) }, }, ]