import React, { useMemo } from 'react'; import type { Backup } from '../app'; interface BackupListProps { backups: Backup[]; filters: { customer: string; environment: string; service: string; dateFrom: string; dateTo: string; }; onFilterChange: (filters: unknown) => void; onSelectBackup: (backup: Backup) => void; onRestore: (backup: Backup) => void; onAssign?: (backup: Backup) => void; onRefresh: () => void; } export function BackupList({ backups, filters, onFilterChange, onSelectBackup, onRestore, onAssign, onRefresh }: BackupListProps) { const [groupBy, setGroupBy] = React.useState<'none' | 'environment' | 'customer'>('customer'); const filteredBackups = useMemo(() => { return backups.filter(backup => { if (filters.customer && !backup.customer_name.toLowerCase().includes(filters.customer.toLowerCase())) { return false; } if (filters.environment) { const environment = backup.metadata?.environment || ''; if (!environment.toLowerCase().includes(filters.environment.toLowerCase())) { return false; } } if (filters.service && backup.service !== filters.service) { return false; } if (filters.dateFrom) { if (new Date(backup.created_at) < new Date(filters.dateFrom)) { return false; } } if (filters.dateTo) { if (new Date(backup.created_at) > new Date(filters.dateTo)) { return false; } } return true; }).sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); }, [backups, filters]); const uniqueCustomers = useMemo(() => { const customers = new Set(backups.map(b => b.customer_name)); return Array.from(customers).sort(); }, [backups]); const uniqueEnvironments = useMemo(() => { const environments = new Set(backups.map(b => b.metadata?.environment).filter(Boolean)); return Array.from(environments).sort(); }, [backups]); const formatFileSize = (bytes: number) => { const sizes = ['Bytes', 'KB', 'MB', 'GB']; if (bytes === 0) return '0 Bytes'; const i = Math.floor(Math.log(bytes) / Math.log(1024)); return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i]; }; const formatDate = (dateString: string) => { return new Date(dateString).toLocaleString(); }; const getEnvironmentBadgeColor = (environment: string) => { switch (environment?.toLowerCase()) { case 'production': return 'bg-red-100 text-red-800'; case 'staging': return 'bg-yellow-100 text-yellow-800'; case 'testing': return 'bg-green-100 text-green-800'; default: return 'bg-gray-100 text-gray-800'; } }; const groupedBackups = useMemo(() => { if (groupBy === 'none') { return { 'All Backups': filteredBackups }; } const grouped = filteredBackups.reduce((acc, backup) => { const groupKey = groupBy === 'environment' ? backup.metadata?.environment || 'Unknown Environment' : backup.customer_name; if (!acc[groupKey]) acc[groupKey] = []; acc[groupKey].push(backup); return acc; }, {} as Record); // Sort groups and backups within groups const sortedGroups: Record = {}; Object.keys(grouped).sort().forEach(key => { sortedGroups[key] = grouped[key].sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime() ); }); return sortedGroups; }, [filteredBackups, groupBy]); return (
{/* Architecture Explanation */}
📋

Backup Architecture Overview

Environments: We manage 3 Tavus account environments - Production, Staging, and Testing.

Customers: Each environment contains multiple customer accounts with their own data (personas, conversations, etc.).

Customers can exist across multiple environments, maintaining their identity while having environment-specific data.

{/* Filters */}

Filter Backups

onFilterChange({ ...filters, dateFrom: e.target.value })} className="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm" />
onFilterChange({ ...filters, dateTo: e.target.value })} className="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm" />
{/* Group By Controls */}
{/* Backup List */}

Backups ({filteredBackups.length})

{filteredBackups.length === 0 ? (

No backups found

Try adjusting your filters or run a new backup.

) : (
{Object.entries(groupedBackups).map(([groupName, groupBackups]) => (
{/* Group Header (only show if not "All Backups") */} {groupName !== 'All Backups' && (

{groupBy === 'environment' ? `${groupName} Environment` : groupName}

({groupBackups.length} backups)
)} {/* Group Table */}
{(groupName === 'All Backups' || Object.keys(groupedBackups).indexOf(groupName) === 0) && ( )} {groupBackups.map((backup) => ( ))}
Customer Account
In Tavus Environment
Date Size Content Status Actions
{backup.customer_id === 'customer-unassigned-catchall-000' ? '⚠️' : '👤'}
{backup.customer_name}
Customer ID: {backup.customer_id}
{backup.customer_id === 'customer-unassigned-catchall-000' && (
Contains {backup.metadata?.personas_count || 0} unassigned personas that need review
)}
{groupBy !== 'environment' && (
in {backup.metadata?.environment || 'Unknown'} Environment
)}
{formatDate(backup.created_at)} {formatFileSize(backup.file_size)}
👤 {backup.metadata?.personas_count || 0} personas
💬 {backup.metadata?.conversations_count || 0} conversations
🎭 {backup.metadata?.replicas_count || 0} replicas
🎯 {backup.metadata?.objectives_count || 0} objectives
{backup.metadata?.api_status || 'Unknown'} {backup.customer_id === 'customer-unassigned-catchall-000' ? ( ) : ( )}
))}
)}
); }