import React, { useState, useEffect, useCallback } from 'react'; import { LineChart, Line, BarChart, Bar, PieChart, Pie, Cell, AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from 'recharts'; import { Activity, Clock, Database, AlertTriangle, CheckCircle, XCircle, TrendingUp, TrendingDown, Search, Filter, RefreshCw, Settings, Play, Pause, RotateCcw, FileText, ChevronRight, Layers, Zap, Shield } from 'lucide-react'; // Mock data matching BigQuery Jobs API structure const MOCK_JOBS = [ { job_id: "daily_customer_etl", state: "RUNNING", creationTime: 1771059781456, startTime: 1771059782203, endTime: null, totalBytesProcessed: 1073741824, totalSlotMs: 12500, errorResult: null, pipeline: "customer-data" }, { job_id: "hourly_sales_agg", state: "DONE", creationTime: 1771056181456, startTime: 1771056182203, endTime: 1771056242324, totalBytesProcessed: 524288000, totalSlotMs: 8200, errorResult: null, pipeline: "sales-analytics" }, { job_id: "daily_inventory_sync", state: "FAILED", creationTime: 1771052581456, startTime: 1771052582203, endTime: 1771052642324, totalBytesProcessed: 0, totalSlotMs: 1500, errorResult: { message: "Table not found: inventory.raw_stock" }, pipeline: "inventory" }, { job_id: "weekly_user_cohort", state: "DONE", creationTime: 1771048981456, startTime: 1771048982203, endTime: 1771049282324, totalBytesProcessed: 2147483648, totalSlotMs: 45000, errorResult: null, pipeline: "user-analytics" }, { job_id: "realtime_clickstream", state: "RUNNING", creationTime: 1771063381456, startTime: 1771063382203, endTime: null, totalBytesProcessed: 268435456, totalSlotMs: 3200, errorResult: null, pipeline: "clickstream" }, { job_id: "daily_fraud_detect", state: "PENDING", creationTime: 1771066981456, startTime: null, endTime: null, totalBytesProcessed: 0, totalSlotMs: 0, errorResult: null, pipeline: "fraud-prevention" }, { job_id: "hourly_metrics_rollup", state: "DONE", creationTime: 1771059781456, startTime: 1771059782203, endTime: 1771059842324, totalBytesProcessed: 134217728, totalSlotMs: 5600, errorResult: null, pipeline: "platform-metrics" }, { job_id: "daily_product_catalog", state: "DONE", creationTime: 1771056181456, startTime: 1771056182203, endTime: 1771056302324, totalBytesProcessed: 805306368, totalSlotMs: 15200, errorResult: null, pipeline: "product-data" }, ]; const MOCK_TIMELINE_DATA = [ { time: "00:00", jobs: 12, failed: 1, bytes: 1.2 }, { time: "04:00", jobs: 18, failed: 0, bytes: 2.1 }, { time: "08:00", jobs: 24, failed: 2, bytes: 3.4 }, { time: "12:00", jobs: 31, failed: 1, bytes: 4.2 }, { time: "16:00", jobs: 28, failed: 0, bytes: 3.8 }, { time: "20:00", jobs: 22, failed: 1, bytes: 2.9 }, ]; const MOCK_STATUS_DISTRIBUTION = [ { name: "Running", value: 2, color: "#3b82f6" }, { name: "Success", value: 4, color: "#22c55e" }, { name: "Failed", value: 1, color: "#ef4444" }, { name: "Pending", value: 1, color: "#f59e0b" }, ]; const MOCK_QUALITY_METRICS = { completeness: 98.2, accuracy: 97.5, timeliness: 99.1, nullRate: 0.3, duplicateRate: 0.1, schemaViolations: 0, }; const formatBytes = (bytes: number): string => { if (bytes === 0) return "0 B"; const k = 1024; const sizes = ["B", "KB", "MB", "GB", "TB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i]; }; const formatDuration = (start: number, end: number | null): string => { const endTime = end || Date.now(); const diff = endTime - start; const hours = Math.floor(diff / 3600000); const minutes = Math.floor((diff % 3600000) / 60000); const seconds = Math.floor((diff % 60000) / 1000); if (hours > 0) return `${hours}h ${minutes}m`; if (minutes > 0) return `${minutes}m ${seconds}s`; return `${seconds}s`; }; const formatTime = (timestamp: number): string => { return new Date(timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); }; const formatRelativeTime = (timestamp: number): string => { const diff = Date.now() - timestamp; const hours = Math.floor(diff / 3600000); if (hours < 1) return "Just now"; if (hours < 24) return `${hours}h ago`; return `${Math.floor(hours / 24)}d ago`; }; const getStatusColor = (state: string): string => { switch (state) { case "RUNNING": return "#3b82f6"; case "DONE": return "#22c55e"; case "FAILED": return "#ef4444"; case "PENDING": return "#f59e0b"; default: return "#64748b"; } }; export default function App() { const [jobs, setJobs] = useState(MOCK_JOBS); const [selectedJob, setSelectedJob] = useState(null); const [statusFilter, setStatusFilter] = useState("All"); const [searchQuery, setSearchQuery] = useState(""); const [sortColumn, setSortColumn] = useState("creationTime"); const [sortDirection, setSortDirection] = useState<"asc" | "desc">("desc"); const [autoRefresh, setAutoRefresh] = useState(true); const [lastUpdated, setLastUpdated] = useState(new Date()); const healthScore = 94; const jobsCount24h = 156; const throughputTB = 2.4; const qualityScore = 98.2; useEffect(() => { if (!autoRefresh) return; const interval = setInterval(() => { setLastUpdated(new Date()); }, 30000); return () => clearInterval(interval); }, [autoRefresh]); const filteredJobs = jobs.filter(job => { const matchesStatus = statusFilter === "All" || job.state === statusFilter; const matchesSearch = job.job_id.toLowerCase().includes(searchQuery.toLowerCase()) || job.pipeline.toLowerCase().includes(searchQuery.toLowerCase()); return matchesStatus && matchesSearch; }); const sortedJobs = [...filteredJobs].sort((a, b) => { const aVal = a[sortColumn as keyof typeof a]; const bVal = b[sortColumn as keyof typeof b]; if (aVal === null || aVal === undefined) return 1; if (bVal === null || bVal === undefined) return -1; const comparison = aVal < bVal ? -1 : aVal > bVal ? 1 : 0; return sortDirection === "asc" ? comparison : -comparison; }); const handleSort = (column: string) => { if (sortColumn === column) { setSortDirection(sortDirection === "asc" ? "desc" : "asc"); } else { setSortColumn(column); setSortDirection("desc"); } }; const getStatusBadgeClass = (state: string) => { const base = "status-badge inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold uppercase"; switch (state) { case "RUNNING": return `${base} bg-blue-500/15 text-blue-500 border border-blue-500/30`; case "DONE": return `${base} bg-green-500/15 text-green-500 border border-green-500/30`; case "FAILED": return `${base} bg-red-500/15 text-red-500 border border-red-500/30`; case "PENDING": return `${base} bg-amber-500/15 text-amber-500 border border-amber-500/30`; default: return `${base} bg-slate-500/15 text-slate-500 border border-slate-500/30`; } }; return (
{/* Header */}

Pipeline Monitor

Auto-refresh: {autoRefresh ? "ON" : "OFF"}
{/* KPI Row */}
{/* Health Score */}
Health Score
{healthScore}%
Excellent
+2% from yesterday
{/* Jobs 24H */}
Jobs (24h)
{jobsCount24h}
+12 vs previous 24h
{/* Throughput */}
Throughput
{throughputTB} TB/d
+8.5% from average
{/* Data Quality */}
Data Quality
{qualityScore}%
Threshold: 95% ✓
{/* Charts Grid */}
{/* Timeline Chart */}

Pipeline Timeline

Jobs
Failed
{/* Status Distribution */}

Job Distribution

{MOCK_STATUS_DISTRIBUTION.map((entry, index) => ( ))}
{MOCK_STATUS_DISTRIBUTION.map((item) => (
{item.name}
{item.value}
))}
{/* Filter Bar */}
{["All", "RUNNING", "DONE", "FAILED", "PENDING"].map((status) => ( ))}
setSearchQuery(e.target.value)} className="pl-9 pr-4 py-1.5 bg-white/[0.03] border border-white/[0.08] rounded-lg text-sm text-white placeholder-slate-400 focus:outline-none focus:border-blue-500 w-60" />
{/* Jobs Table */}
{sortedJobs.map((job) => ( setSelectedJob(job)} className={`border-b border-white/[0.06] cursor-pointer transition-colors ${ selectedJob?.job_id === job.job_id ? 'bg-white/[0.06]' : 'hover:bg-white/[0.03]' }`} > ))}
handleSort('job_id')}> Job Name {sortColumn === 'job_id' && (sortDirection === 'asc' ? '↑' : '↓')} handleSort('state')}> Status {sortColumn === 'state' && (sortDirection === 'asc' ? '↑' : '↓')} handleSort('startTime')}> Duration {sortColumn === 'startTime' && (sortDirection === 'asc' ? '↑' : '↓')} handleSort('totalBytesProcessed')}> Records {sortColumn === 'totalBytesProcessed' && (sortDirection === 'asc' ? '↑' : '↓')} Quality handleSort('creationTime')}> Started {sortColumn === 'creationTime' && (sortDirection === 'asc' ? '↑' : '↓')}
{job.job_id}
{job.pipeline}
{job.state === "RUNNING" &&
} {job.state}
{job.startTime ? formatDuration(job.startTime, job.endTime) : '-'} {formatBytes(job.totalBytesProcessed)}
{(95 + Math.random() * 5).toFixed(1)}%
{formatTime(job.creationTime)}
{formatRelativeTime(job.creationTime)}
{/* Details Panel */} {selectedJob && (
setSelectedJob(null)}>
e.stopPropagation()} >

{selectedJob.job_id}

{selectedJob.pipeline}
{selectedJob.state === "RUNNING" &&
} {selectedJob.state} {selectedJob.startTime && (
Duration: {formatDuration(selectedJob.startTime, selectedJob.endTime)}
)}
{/* Pipeline Stages */}
Source
Transform
Load
{/* Quality Metrics */}

Data Quality

{MOCK_QUALITY_METRICS.completeness}%
Completeness
{MOCK_QUALITY_METRICS.nullRate}%
Null Rate
{MOCK_QUALITY_METRICS.duplicateRate}%
Duplicates
{/* Error Message */} {selectedJob.errorResult && (
Error
{selectedJob.errorResult.message}
)} {/* Stats */}
Bytes Processed {formatBytes(selectedJob.totalBytesProcessed)}
Compute (Slot-ms) {selectedJob.totalSlotMs.toLocaleString()}
Created {formatTime(selectedJob.creationTime)}
{/* Action Buttons */}
{selectedJob.state === 'FAILED' && ( )} {selectedJob.state === 'RUNNING' && ( )}
)} {/* Footer */}
Last updated: {lastUpdated.toLocaleTimeString()}
Connected to BigQuery
); }