"use client" import { Button } from "@/components/ui/button" import type { ColumnDef } from "@tanstack/react-table" import { ArrowUpDown, ExternalLink, Clock, Loader2, CheckCircle2, XCircle, Trash2, Check, ListFilter } from "lucide-react" import Image from "next/image" import { Badge } from "@/components/ui/badge" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" import { cn } from "@/lib/utils" import { RepoIndexingStatus } from "@sourcebot/db"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { AddRepoButton } from "./addRepoButton" export type RepositoryColumnInfo = { name: string imageUrl?: string connections: { id: number name: string }[] repoIndexingStatus: RepoIndexingStatus lastIndexed: string url: 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, isAddNewRepoButtonVisible: boolean): ColumnDef[] => [ { accessorKey: "name", header: () => (
Repository {isAddNewRepoButtonVisible && }
), cell: ({ row }) => { const repo = row.original const url = repo.url const isRemoteRepo = url.length > 0 return (
{repo.imageUrl ? ( {`${repo.name} ) : (
{repo.name.charAt(0)}
)}
{ if (isRemoteRepo) { window.open(url, "_blank") } }} > {repo.name.length > 40 ? `${repo.name.slice(0, 40)}...` : repo.name} {isRemoteRepo && }
) }, }, { accessorKey: "connections", header: () =>
Connections
, cell: ({ row }) => { const connections = row.original.connections if (!connections || connections.length === 0) { return
} return (
{connections.map((connection) => ( { window.location.href = `/${domain}/connections/${connection.id}` }} > {connection.name} ))}
) }, }, { 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()}
) }, }, ]