Files
knowledge-governance/web/src/SnapshotHistory.tsx
T
姚章浩 e34306b2db
build / build (push) Failing after 18s
fix(ui): 已释放窗口不再渲染 held 文案,版本页不再把 500 说成未接线
发布管理:maintenanceSummary 只看 job.state === 'failed' 就给 held 处置文案;
窗口已 released 的旧作业(libsync-internal-1793399248431728863)因此自相矛盾。
改为仅 held 时给 recoveryError,已释放时给 releasedFailure(如实记录失败,不提供强制成功)。

版本记录:LoadVersionHistorySyncState 把可空的 finished_at 扫进 time.Time;
部署重启触发的同步在"进行中"时该列为 NULL,扫描失败使整页 500
(nginx access log:GET /api/v1/version-history?limit=30 → 500,74 字节错误体)。
改为指针接值再判空。前端同时区分"未配置/加载失败"并显示服务端 code。

RED/GREEN:新增 Go 集成用例(NULL finished_at)、两条前端用例;
make verify 16/16 通过(local 档案)。
2026-11-01 19:34:31 +08:00

108 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { CatalogNodePage, CatalogSnapshot } from './sourceCatalog'
import './sourceCatalogBrowser.css'
const stamp = (value: string) => new Date(value).toLocaleString('zh-CN', { hour12: false })
const shortHash = (value: string) => `${value.slice(0, 12)}…${value.slice(-8)}`
interface Props {
snapshots: CatalogSnapshot[]
active: CatalogSnapshot | null
page: CatalogNodePage | null
loading: boolean
error: string | null
onClose: () => void
onOpenSnapshot: (snapshot: CatalogSnapshot) => void
onOpenFolder: (snapshot: CatalogSnapshot, nodeID: string) => void
}
export function SnapshotHistoryView({
snapshots,
active,
page,
loading,
error,
onClose,
onOpenSnapshot,
onOpenFolder,
}: Props) {
return (
<section className="snapshot-history" aria-label="历史快照">
<header>
<h2>历史快照</h2>
<p>只读查看不可变快照;切换查看不会改变当前生效版本。</p>
<button type="button" onClick={onClose}>
返回当前目录
</button>
</header>
{error ? (
<div className="error-banner" role="alert">
{error}
</div>
) : null}
<ul className="snapshot-history-list">
{snapshots.map((snapshot) => (
<li key={snapshot.snapshot_id}>
<div>
<strong>{stamp(snapshot.observed_at)}</strong>
{snapshot.is_head ? <span className="scope-badge internal">当前</span> : null}
<small>
{snapshot.node_count} 个节点 · {snapshot.file_count} 份文件 · 入库 {stamp(snapshot.created_at)}
</small>
</div>
<button type="button" onClick={() => onOpenSnapshot(snapshot)}>
{active?.snapshot_id === snapshot.snapshot_id ? '刷新该快照' : '查看该快照'}
</button>
</li>
))}
</ul>
{loading ? <div className="empty-state">正在读取历史快照目录…</div> : null}
{active && page ? (
<div className="snapshot-history-table">
<div className="catalog-pathbar">
<span>{active.source_name}</span>
<span>只读历史快照</span>
</div>
<table className="catalog-table">
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>大小</th>
<th>更新时间</th>
<th>内容Hash</th>
</tr>
</thead>
<tbody>
{page.items.map((node) => (
<tr key={node.node_id}>
<td>
{node.node_type === 'folder' ? (
<button type="button" className="catalog-name" onClick={() => onOpenFolder(active, node.node_id)}>
📁 {node.name}
</button>
) : (
<>📄 {node.name}</>
)}
</td>
<td>{node.node_type === 'folder' ? '文件夹' : '文件'}</td>
<td>{typeof node.size_bytes === 'number' ? `${node.size_bytes} B` : '—'}</td>
<td>{node.modified_at ? stamp(node.modified_at) : '—'}</td>
<td>{node.content_sha256 ? shortHash(node.content_sha256) : '内容Hash未获取'}</td>
</tr>
))}
</tbody>
</table>
{page.total > page.limit ? (
<p className="pagination">
<span>
共 {page.total} 项 · 每页 {page.limit} 项
</span>
</p>
) : null}
</div>
) : null}
{!loading && active && !page && !error ? <div className="empty-state">该快照暂无可见内容。</div> : null}
</section>
)
}