import * as React from "react"; import { Badge, Button, MessageBar, MessageBarBody, Spinner, Text, makeStyles, tokens, } from "@fluentui/react-components"; import { ArrowDownload24Regular, DocumentPdf24Regular, History24Regular, } from "@fluentui/react-icons"; import { VersionRecord } from "../../models/versionRecord"; interface VersionHistoryPanelProps { versions: VersionRecord[]; loading: boolean; error: string | null; /** versionId ของ version ที่กำลังดาวน์โหลดอยู่ (แสดง spinner ที่ปุ่ม) */ downloadingVersionId: string | null; downloadingPdfVersionId: string | null; onDownloadPdf: (version: VersionRecord) => void; onDownload: (version: VersionRecord) => void; onRetry: () => void; } const useStyles = makeStyles({ root: { display: "flex", flexDirection: "column", gap: tokens.spacingVerticalS, }, header: { display: "flex", alignItems: "center", gap: tokens.spacingHorizontalXS, marginTop: tokens.spacingVerticalL, marginBottom: tokens.spacingVerticalXXS, }, item: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: tokens.spacingHorizontalS, padding: `${tokens.spacingVerticalXS} ${tokens.spacingHorizontalS}`, borderRadius: tokens.borderRadiusMedium, ":hover": { backgroundColor: tokens.colorNeutralBackground1Hover, }, }, actions: { display: "flex", flexDirection: "column", flexShrink: 0 }, itemInfo: { display: "flex", flexDirection: "column", minWidth: 0, }, metaRow: { color: tokens.colorNeutralForeground3, fontSize: tokens.fontSizeBase200, }, messageRow: { color: tokens.colorNeutralForeground2, fontSize: tokens.fontSizeBase200, whiteSpace: "pre-wrap", overflowWrap: "anywhere", }, }); function formatTimestamp(iso: string): string { const date = new Date(iso); return Number.isNaN(date.getTime()) ? iso : date.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" }); } /** FR-4 — แสดง version history (เลข version / เวลา / ผู้สร้าง) + ปุ่มดาวน์โหลด version นั้น */ export const VersionHistoryPanel: React.FC = ({ versions, loading, error, downloadingVersionId, downloadingPdfVersionId, onDownloadPdf, onDownload, onRetry, }) => { const styles = useStyles(); return (
Version history
{loading ? : null} {error ? ( {error}{" "} ) : null} {!loading && !error && versions.length === 0 ? ( ยังไม่มี version ในระบบ ) : null} {versions.map((version) => (
v{version.versionNumber} {formatTimestamp(version.createdAt)} โดย {version.createdByUserId} {version.message ? {version.message} : null}
{version.hasPdf ? ( ) : null}
))}
); }; export default VersionHistoryPanel;