Phase 9: version message (FR-13)

- ใส่คำอธิบายแบบ commit message ได้ทุก flow ที่สร้าง version (Save & Version / Start Versioning / generate จากเว็บ) + แสดงใน version history ทุกหน้า
- backend: DocumentVersion.Message (varchar 2048) + migration AddVersionMessage + BadRequest ตรวจความยาวก่อนแตะ MinIO (กัน 500 + orphan object)
- add-in: ConfirmVersionDialog เพิ่ม textarea (Start Versioning ใช้ dialog ด้วย) + แสดง message ใน VersionHistoryPanel
- web: ฟอร์มสร้างเอกสาร + หน้า detail แสดง message (desktop truncate + tooltip, mobile เต็มบรรทัด)
- sync เอกสารทั้งหมด: spec v5 (FR-13/AC-16) + plan Phase 9 + acceptance-review 1–16 + README + CLAUDE.md + web/README
- tests: backend 52 / addin 50 / web 36 — เขียวทั้งชุด

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Suphonchai Phoonsawat 2026-08-20 22:05:49 +07:00
parent b47667f918
commit 7b20f12ede
28 changed files with 928 additions and 141 deletions

View file

@ -87,6 +87,7 @@ const App: React.FC = () => {
const [saving, setSaving] = React.useState(false);
const [progressMessage, setProgressMessage] = React.useState<string | null>(null);
const [confirmOpen, setConfirmOpen] = React.useState(false);
const [startConfirmOpen, setStartConfirmOpen] = React.useState(false);
const [flowError, setFlowError] = React.useState<string | null>(null);
const [flowSuccess, setFlowSuccess] = React.useState<string | null>(null);
@ -209,13 +210,13 @@ const App: React.FC = () => {
setPhase("signed-out");
};
/** Start Versioning — stamp รอบแรก + upload v1 (FR-1/AC-5) */
const handleStartVersioning = async () => {
/** Start Versioning — stamp รอบแรก + upload v1 (FR-1/AC-5) · message คือ commit message จาก dialog (FR-13) */
const handleStartVersioning = async (message: string) => {
setStarting(true);
setFlowError(null);
setFlowSuccess(null);
try {
const result = await startVersioning(setProgressMessage);
const result = await startVersioning(message, setProgressMessage);
setDocumentId(result.documentId);
setPhase("tracking");
setFlowSuccess(`เริ่มติดตามเอกสารนี้แล้ว — สร้างเป็น version 1`);
@ -230,8 +231,9 @@ const App: React.FC = () => {
}
};
/** Save & Version (FR-2) — ตามลำดับ spec: confirm → stamp → XML → save → file+fields → upload */
const handleSaveAndVersion = async () => {
/** Save & Version (FR-2) — ตามลำดับ spec: confirm → stamp → XML → save → file+fields → upload
* message คือ commit message จาก dialog (FR-13) */
const handleSaveAndVersion = async (message: string) => {
if (!documentId) {
return;
}
@ -240,7 +242,7 @@ const App: React.FC = () => {
setFlowSuccess(null);
try {
const latestVersionNumber = versions[0]?.versionNumber ?? 0;
const result = await saveAndVersion(documentId, latestVersionNumber, setProgressMessage);
const result = await saveAndVersion(documentId, latestVersionNumber, message, setProgressMessage);
setFlowSuccess(`สร้าง version ${result.versionNumber} เรียบร้อย`);
await refreshHistory(documentId);
} catch (error) {
@ -349,7 +351,7 @@ const App: React.FC = () => {
appearance="primary"
icon={<DocumentArrowUp24Regular />}
disabled={starting}
onClick={() => void handleStartVersioning()}
onClick={() => setStartConfirmOpen(true)}
>
{starting ? "กำลังเริ่มติดตาม…" : "Start Versioning This Document"}
</Button>
@ -422,9 +424,20 @@ const App: React.FC = () => {
<ConfirmVersionDialog
open={confirmOpen}
busy={saving}
onConfirm={() => void handleSaveAndVersion()}
onConfirm={(message) => void handleSaveAndVersion(message)}
onDismiss={() => setConfirmOpen(false)}
/>
{/* FR-13 — Start Versioning ใช้ dialog เดียวกัน: ยืนยัน + พิมพ์ commit message ของ v1 ก่อนเริ่ม track */}
<ConfirmVersionDialog
open={startConfirmOpen}
busy={starting}
title="เริ่มติดตามเอกสารนี้?"
description="ระบบจะ stamp metadata ลงไฟล์และบันทึกไฟล์ปัจจุบันเป็น version 1 ของเอกสารนี้"
confirmLabel="เริ่มติดตาม (version 1)"
onConfirm={(message) => void handleStartVersioning(message)}
onDismiss={() => setStartConfirmOpen(false)}
/>
</div>
);
};

View file

@ -7,31 +7,68 @@ import {
DialogContent,
DialogSurface,
DialogTitle,
Field,
Spinner,
Textarea,
} from "@fluentui/react-components";
interface ConfirmVersionDialogProps {
open: boolean;
/** กำลังอยู่ระหว่าง flow หลังกดยืนยันแล้ว — ปุ่นทั้งสอง disable + แสดง spinner */
/** กำลังอยู่ระหว่าง flow หลังกดยืนยันแล้ว — ปุ่มทั้งสอง disable + แสดง spinner */
busy: boolean;
onConfirm: () => void;
/** ปรับข้อความตอน reuse กับ flow อื่น (FR-13 — Start Versioning ใช้ dialog ตัวเดียวกัน) */
title?: string;
description?: React.ReactNode;
confirmLabel?: string;
/** ได้รับ commit message ที่ผู้ใช้พิมพ์ (FR-13) — ว่างได้ */
onConfirm: (message: string) => void;
onDismiss: () => void;
}
/** FR-2 ขั้นตอนที่ 1 — dialog ยืนยัน "สร้าง version ใหม่ของเอกสารนี้หรือไม่?" */
const DEFAULT_TITLE = "สร้าง version ใหม่?";
const DEFAULT_DESCRIPTION = "ระบบจะบันทึกไฟล์ปัจจุบันและอัปโหลดเป็น version ถัดไปของเอกสารนี้";
const DEFAULT_CONFIRM_LABEL = "สร้าง version";
/** FR-2 ขั้นตอนที่ 1 — dialog ยืนยัน "สร้าง version ใหม่ของเอกสารนี้หรือไม่?" พร้อมช่องคำอธิบาย version
* แบบ commit message ทางเลือก (FR-13) — ใช้ร่วมกับทั้ง Save & Version และ Start Versioning */
export const ConfirmVersionDialog: React.FC<ConfirmVersionDialogProps> = ({
open,
busy,
title,
description,
confirmLabel,
onConfirm,
onDismiss,
}) => {
const [message, setMessage] = React.useState("");
// component ถูก mount ค้างไว้ตลอด (App render ไว้นอก phase branch) — ต้องเคลียร์ค่าตอนปิด
// ไม่ใช่ตอน unmount ไม่งั้นข้อความรอบก่อนหลุดมารอบถัดไป
React.useEffect(() => {
if (!open) {
setMessage("");
}
}, [open]);
return (
<Dialog open={open} onOpenChange={(_event, data) => !data.open && !busy && onDismiss()} modalType="alert">
<DialogSurface>
<DialogBody>
<DialogTitle>สร้าง version ใหม่?</DialogTitle>
<DialogTitle>{title ?? DEFAULT_TITLE}</DialogTitle>
<DialogContent>
ระบบจะบันทึกไฟล์ปัจจุบันและอัปโหลดเป็น version ถัดไปของเอกสารนี้
{description ?? DEFAULT_DESCRIPTION}
<Field label="คำอธิบาย version (ไม่บังคับ)" style={{ marginTop: 12 }}>
<Textarea
value={message}
onChange={(_event, data) => setMessage(data.value)}
placeholder="เช่น แก้ไขข้อ 3 สัญญาจ้าง"
maxLength={2048}
resize="vertical"
rows={3}
disabled={busy}
textarea={{ "aria-label": "คำอธิบาย version" }}
/>
</Field>
{busy ? (
<div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 12 }}>
<Spinner size="tiny" /> กำลังดำเนินการ…
@ -42,8 +79,8 @@ export const ConfirmVersionDialog: React.FC<ConfirmVersionDialogProps> = ({
<Button appearance="secondary" disabled={busy} onClick={onDismiss}>
ยกเลิก
</Button>
<Button appearance="primary" disabled={busy} onClick={onConfirm}>
สร้าง version
<Button appearance="primary" disabled={busy} onClick={() => onConfirm(message)}>
{confirmLabel ?? DEFAULT_CONFIRM_LABEL}
</Button>
</DialogActions>
</DialogBody>

View file

@ -55,6 +55,12 @@ const useStyles = makeStyles({
color: tokens.colorNeutralForeground3,
fontSize: tokens.fontSizeBase200,
},
messageRow: {
color: tokens.colorNeutralForeground2,
fontSize: tokens.fontSizeBase200,
whiteSpace: "pre-wrap",
overflowWrap: "anywhere",
},
});
function formatTimestamp(iso: string): string {
@ -109,6 +115,9 @@ export const VersionHistoryPanel: React.FC<VersionHistoryPanelProps> = ({
</Badge>
<span className={styles.metaRow}>{formatTimestamp(version.createdAt)}</span>
<span className={styles.metaRow}>โดย {version.createdByUserId}</span>
{version.message ? (
<span className={styles.messageRow}>{version.message}</span>
) : null}
</div>
<Button
icon={<ArrowDownload24Regular />}