// Shared Status Badge Components /** * Job status configuration */ const JOB_STATUS_CONFIG = { queued: { color: 'bg-slate-100 text-slate-700', icon: '⏳', label: 'In coda' }, running: { color: 'bg-blue-100 text-blue-700', icon: '⚡', label: 'In esecuzione' }, completed: { color: 'bg-emerald-100 text-emerald-700', icon: '✓', label: 'Completato' }, error: { color: 'bg-red-100 text-red-700', icon: '✕', label: 'Errore' }, cancelled: { color: 'bg-amber-100 text-amber-700', icon: '⛔', label: 'Annullato' }, }; /** * Priority configuration */ const PRIORITY_CONFIG = { low: { color: 'bg-slate-100 text-slate-600', label: 'Bassa' }, medium: { color: 'bg-orange-100 text-orange-700', label: 'Media' }, high: { color: 'bg-red-100 text-red-700', label: 'Alta' }, }; /** * Progress bar color based on percentage */ const PROGRESS_COLORS = { complete: 'bg-green-500', high: 'bg-blue-500', medium: 'bg-amber-500', low: 'bg-slate-300', }; /** * Get job status configuration * @param {string} status - Job status (queued, running, completed, error, cancelled) * @returns {Object} Status configuration with color, icon, label */ const getJobStatusConfig = (status) => { return JOB_STATUS_CONFIG[status] || JOB_STATUS_CONFIG.queued; }; /** * Get priority configuration * @param {string} priority - Priority level (low, medium, high) * @returns {Object} Priority configuration with color, label */ const getPriorityConfig = (priority) => { return PRIORITY_CONFIG[priority] || { color: 'bg-gray-100 text-gray-700', label: priority }; }; /** * Get progress bar color based on percentage * @param {number} percent - Progress percentage (0-100) * @returns {string} Tailwind CSS class for the color */ const getProgressColor = (percent) => { if (percent === 100) return PROGRESS_COLORS.complete; if (percent >= 50) return PROGRESS_COLORS.high; if (percent > 0) return PROGRESS_COLORS.medium; return PROGRESS_COLORS.low; }; /** * Job Status Badge Component * Displays a badge with icon for job status */ const JobStatusBadge = ({ status, showSpinner = true, className = '' }) => { const config = getJobStatusConfig(status); return (
{config.icon} {config.label} {showSpinner && status === 'running' && }
); }; /** * Priority Badge Component * Displays a badge for priority level */ const PriorityBadge = ({ priority, className = '' }) => { const config = getPriorityConfig(priority); return ( {config.label} ); }; /** * Status Indicator Component * A smaller indicator with just icon and optional color background */ const StatusIndicator = ({ status, size = 'md', className = '' }) => { const config = getJobStatusConfig(status); const sizes = { sm: 'w-5 h-5 text-xs', md: 'w-7 h-7 text-sm', lg: 'w-9 h-9 text-base', }; return (
{status === 'running' ? ( ) : ( {config.icon} )}
); }; /** * Progress Bar Component * Displays a progress bar with automatic coloring */ const ProgressBar = ({ percent, height = 'h-2', className = '' }) => { const color = getProgressColor(percent); return (
); }; /** * Progress Badge Component * Displays progress as text with optional progress bar */ const ProgressBadge = ({ completed, total, showBar = false, className = '' }) => { const percent = total > 0 ? Math.round((completed / total) * 100) : 0; const color = getProgressColor(percent); const textColor = percent === 100 ? 'text-green-600' : percent >= 50 ? 'text-blue-600' : percent > 0 ? 'text-amber-600' : 'text-slate-500'; return (
{completed}/{total} {showBar && (
)}
); }; // Export to global scope window.StatusBadge = { // Config objects JOB_STATUS_CONFIG, PRIORITY_CONFIG, PROGRESS_COLORS, // Helper functions getJobStatusConfig, getPriorityConfig, getProgressColor, // Components JobStatusBadge, PriorityBadge, StatusIndicator, ProgressBar, ProgressBadge, }; // Also export individual components for direct use window.JobStatusBadge = JobStatusBadge; window.PriorityBadge = PriorityBadge; window.StatusIndicator = StatusIndicator; window.ProgressBar = ProgressBar; window.ProgressBadge = ProgressBadge; window.getJobStatusConfig = getJobStatusConfig; window.getPriorityConfig = getPriorityConfig; window.getProgressColor = getProgressColor;