import { html } from 'htm/preact'; import { useState, useEffect } from 'preact/hooks'; import { LevelCard } from './LevelCard.js'; import { StatCard } from './StatCard.js'; import { CompactionStats } from './CompactionStats.js'; const styles = { container: { display: 'flex', flexDirection: 'column', gap: '12px' }, statsGrid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: '8px' } }; function formatBytes(bytes) { if (bytes === 0) return '0 B'; const k = 1024; const sizes = ['B', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]; } function formatNumber(num) { return num.toLocaleString('zh-CN'); } export function ManifestView({ tableName }) { const [manifest, setManifest] = useState(null); const [loading, setLoading] = useState(true); const [expandedLevels, setExpandedLevels] = useState(new Set()); useEffect(() => { fetchManifest(); const interval = setInterval(fetchManifest, 5000); // 每5秒刷新 return () => clearInterval(interval); }, [tableName]); const fetchManifest = async () => { try { const response = await fetch(`/api/tables/${tableName}/manifest`); if (response.ok) { const data = await response.json(); setManifest(data); } } catch (error) { console.error('Failed to fetch manifest:', error); } finally { setLoading(false); } }; const toggleLevel = (levelNum) => { const newExpanded = new Set(expandedLevels); if (newExpanded.has(levelNum)) { newExpanded.delete(levelNum); } else { newExpanded.add(levelNum); } setExpandedLevels(newExpanded); }; if (loading) { return html`
加载中...
无法加载 Manifest 数据