import { useFlag } from 'common' import { motion } from 'framer-motion' import { MoreVertical } from 'lucide-react' import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, TableCell, TableRow, } from 'ui' import { ShimmeringLoader, TimestampInfo } from 'ui-patterns' import { APIKeyDeleteDialog } from './APIKeyDeleteDialog' import { ApiKeyPill } from './ApiKeyPill' import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper' import type { APIKeysData } from '@/data/api-keys/api-keys-query' export const APIKeyRow = ({ apiKey, lastSeen, isDeleting, isDeleteModalOpen, isLoadingLastSeen = false, showLastSeen = true, onDelete, setKeyToDelete, }: { apiKey: Extract lastSeen?: { timestamp: number; relative: string } showLastSeen?: boolean isDeleting: boolean isDeleteModalOpen: boolean isLoadingLastSeen?: boolean onDelete: () => void setKeyToDelete: (id: string | null) => void }) => { const MotionTableRow = motion.create(TableRow) const showApiKeysLastUsed = useFlag('showApiKeysLastUsed') return ( <>
{apiKey.name}
{apiKey.description || No description}
{showLastSeen && showApiKeysLastUsed && (
{isLoadingLastSeen ? ( ) : lastSeen?.timestamp ? ( ) : ( Never used )}
)}
setKeyToDelete(null)} onConfirm={onDelete} title={`Delete ${apiKey.type} API key: ${apiKey.name}`} confirmString={apiKey.name} confirmLabel="Yes, irreversibly delete this API key" confirmPlaceholder="Type the name of the API key to confirm" loading={isDeleting} variant="destructive" alert={{ title: 'This cannot be undone', description: lastSeen ? `This API key was used ${lastSeen.timestamp}. Make sure all backend components using it have been updated. Deletion will cause them to receive HTTP 401 Unauthorized status codes on all Supabase APIs.` : `This API key has not been used in the past 24 hours. Make sure you've updated all backend components using it before deletion.`, }} /> ) }