From 38d10b7897bc2a57cea9525f5e7c5357398a5562 Mon Sep 17 00:00:00 2001 From: pqhuy1987 Date: Thu, 7 May 2026 21:03:56 +0700 Subject: [PATCH] =?UTF-8?q?[CLAUDE]=20Docs:=20ch=E1=BB=91t=20Session=2015?= =?UTF-8?q?=20wrap-up=20=E2=80=94=20tooltip=20diagnose=20+=20drastic=20ref?= =?UTF-8?q?actor=20DEFER?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Session 15 (2026-05-07) docs update: STATUS.md: - Last updated Session 15 (1 commit `835cc7f` tooltip + working tree drastic refactor revert) - Recently Done row Session 15 chi tiết (diagnose + plan drastic + attempt 12 file edits + REVERT decision) HANDOFF.md: - TL;DR Session 15 prepend với 2 phần: Diagnose tooltip + Drastic refactor DEFER decision - 4 cảnh báo Session 16+: Drastic refactor pending (8-10h dedicated hoặc fallback Approach Y), Task 2 sample seed pending, schema-diagram defer cron audit, Hard blockers giữ nguyên migration-todos.md: - Phase 9 + Session 15 block với 1 task done (tooltip) + 1 defer (drastic refactor) + memory entry note - Defer Session 16+ list Session log NEW `2026-05-07-2600-tooltip-defer-drastic.md`: - Bối cảnh user UAT báo button silent disabled - Phần 1 — Diagnose tooltip (root cause + fix UX + "trùng ID" KHÔNG phải bug FE) - Phần 2 — Plan drastic refactor flat workflow → DEFER: * User spec mới (Phòng × Cấp × Users[] flat) * Plan 6 chunk + estimate scope realistic ~8-10h * Attempt 12 file working tree edits → REVERT decision * Memory entry capture decision rule - Plan organization sau S15 (defer queue) Memory entry NEW `feedback_drastic_refactor_scope.md`: - Quy tắc: drastic refactor cần dedicated session, scope conservative 2x buffer - Anti-patterns mid-session big refactor + commit broken state - Defer pattern (revert working tree → document → memory entry → surface trade-off cho user) - Cross-ref `feedback_per_chunk_commit.md` discipline 🎉 Session 15 wrap-up. Cumulative since session start (13h17): 16 commit (1 button removal + 6 PE N-stage + 5 Contract N-stage + 1 3-button + 1 Session 14 wrap-up + 1 tooltip + 1 Session 15 wrap-up). Verify: dotnet test 96 pass + working tree clean. Defer Session 16+ priority order: 1. Drastic refactor flat workflow (dedicated session ~8-10h) OR fallback Approach Y (FE flat UI 5 phòng, 1-2h) 2. Task 2 sample data seed N-stage 3. Hard blockers Ops (UAT, SMTP, etc.) Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/HANDOFF.md | 54 +++++- docs/STATUS.md | 3 +- docs/changelog/migration-todos.md | 14 ++ .../2026-05-07-2600-tooltip-defer-drastic.md | 158 ++++++++++++++++++ 4 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/sessions/2026-05-07-2600-tooltip-defer-drastic.md diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md index a8cccfd..de5b950 100644 --- a/docs/HANDOFF.md +++ b/docs/HANDOFF.md @@ -1,6 +1,58 @@ # HANDOFF — Brief 5 phút cho session tiếp theo -**Last updated:** 2026-05-07 (Session 14 — **PE 3-button workflow Duyệt/Trả lại/Từ chối — Domain policy expand + Service tách reject 2 case + FE 3-button + 1 test mới = 96 pass. 1 commit `0d77698`. Task 2 sample seed defer (DesignTime vs Runtime DB gotcha + API exit sớm).**) +**Last updated:** 2026-05-07 (Session 15 — **Tooltip diagnose "Lưu & Gửi Duyệt" silent disabled (commit `835cc7f`). Plan drastic refactor flat workflow user chốt → attempt 12 file edits Domain/Configurations, realize scope ~8-10h vượt session, REVERT clean. State 96 test pass, 20 mig.**) + +## TL;DR Session 15 (07/05 — Tooltip diagnose + drastic refactor DEFER) + +User UAT live screenshot báo button "Lưu & Gửi Duyệt" KHÔNG hoạt động + suy đoán "trùng ID" giữa các phiếu. + +**Diagnose (commit `835cc7f`):** +- Root cause: button silent disabled khi `evaluation.workflow.nextPhases` không có forward phase (chỉ TuChoi/TraLai). Cause khả năng: workflow definition pinned thiếu adjacent step → `policy.NextPhasesFrom(DangSoanThao)` return empty. +- Improvement: tooltip + dialog hiển thị reason rõ ràng: + - `submitDisabledReason` text: "Phiếu đã ở phase X — chỉ Bản nháp/Trả lại mới sửa+gửi" / "Workflow không có phase tiếp theo từ X. Liên hệ admin kiểm tra cấu hình" + - Button title attribute → hover show reason hoặc forward phase label + - Dialog confirm show forward phase explicit ("Sẽ chuyển sang Chờ Purchasing") +- Mirror fe-admin + fe-user. Build pass cả 2. KHÔNG đụng BE — chỉ FE diagnostic UX. +- "Trùng ID" KHÔNG phải bug FE — `PurchaseEvaluationWorkspacePage` URL state đúng, mỗi PE row unique GUID + MaPhieu. Suy đoán user do button silent. + +**Plan drastic refactor → DEFER:** + +User confirm "bỏ phase enum hoàn toàn, dùng ChoDuyet=10 đơn nhất + currentStepIndex tracking" — refactor workflow từ phase-based + InnerStep nested model sang flat WorkflowStep model (mỗi step = Phòng × Cấp + Approvers users). + +Edit working tree 12 files (Domain entities + EF Configurations + DbContext): +- Phase enum +ChoDuyet=10, legacy values 2-6 deprecated +- WorkflowStep +DepartmentId, +PositionLevel +- Drop class WorkflowStepInnerStep + nav (PE + Contract) +- PE/Contract +CurrentWorkflowStepIndex int?, +RejectedAtStepIndex int? +- *DepartmentApproval drop InnerStepId column +- EF Configurations: drop InnerStep config + nav, restore simple unique non-filtered +- DbContext: drop DbSet × 2 + +Reality check scope realistic ~8-10h: +1. Domain + EF + DbContext (~50min) ✓ done in working tree +2. PolicyRegistry rewrite PE+Contract (~45min) +3. App CQRS DTOs rewrite (~45min) +4. Service rewrite PE+Contract (~2-3h) +5. Tests rewrite — drop 12 N-stage tests + update remaining (~1.5h) +6. Migration 21 + LocalDB apply + verify (~30min) +7. FE Designer rewrite (~1.5h) +8. FE PeWorkflowPanel + workflow timeline (~1h) +9. Docs/Skill update (~45min) + +Vượt session boundary + risk session deep ~30 commits → **REVERT working tree** về `835cc7f` clean state. Test 96 pass intact. + +**Decision memorized:** add memory `feedback_drastic_refactor_scope.md` — drastic refactor cần dedicated session, scope estimation conservative (2x buffer), tránh mid-session big refactor. + +## ⚠️ CẢNH BÁO Session 16+ + +1. **Drastic refactor flat workflow chưa làm — DEFER** với plan chi tiết. Khi resume: + - Plan kỹ 6 chunk per-commit + - Buffer 2x estimate (~16h thực tế) + - Tests rewrite biggest risk + - Hoặc fall back Approach Y (FE Designer flat UI giới hạn 5 phòng) ROI 1-2h nếu user OK trade-off +2. **Task 2 sample data seed N-stage** vẫn pending (block trên DesignTime vs Runtime DB gotcha + DbInitializer seed flow) +3. **schema-diagram §17-19 Mig 18-20** vẫn defer cron audit 2026-06-01 +4. **Hard blockers Ops** giữ nguyên 6 task ## TL;DR Session 14 (07/05 — PE 3-button approval workflow) diff --git a/docs/STATUS.md b/docs/STATUS.md index bf2f411..2e5e7dd 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -2,7 +2,7 @@ > **Update rule:** trước khi bắt đầu 1 task → ghi row vào `🔥 In Progress`. Xong → chuyển sang `✅ Recently Done`. -**Last updated:** 2026-05-07 (Session 14 — **PE 3-button workflow approval (Duyệt / Trả lại / Từ chối) — Domain policy expand `(X → TuChoi)` cho mọi phase trung gian + Service tách 2 reject case + FE 3-button rõ ràng + Dialog warning + 1 test mới. 1 commit `0d77698`. Task 2 sample seed in-progress (block on DesignTime vs Runtime DB).**) +**Last updated:** 2026-05-07 (Session 15 — **Diagnose "Lưu & Gửi Duyệt" silent disabled → tooltip reason + dialog warning rõ phase. User feedback bug suy đoán "trùng ID" — không phải bug FE. 1 commit `835cc7f`. Tiếp đó Plan drastic refactor flat workflow user chốt → attempt edit Domain/Configurations 12 files, scope realistic ~8-10h vượt session, REVERT working tree about session sau. 0 test mới. State: 96 test pass.**) ## 📍 Phase hiện tại: **Phase 9 active — UAT** — **57 DB tables, 20 migrations, ~134 API endpoints, 32 FE pages. 96 unit test pass** (54 Domain + 42 Infra). 41 gotcha. 30 demo user. 6 skill. **5 PE display status** (Bản nháp / Đã gửi duyệt / Trả lại / Đã duyệt / Từ chối). **9 PE phase enum** (+TraLai = 98 — orphan, KHÔNG wire). **N-stage workflow** Phòng × PositionLevel (NV/PP/TP) cấu hình động per WorkflowStep cha — **Mig 18+19 (PE) + Mig 20 (Contract)**. Budget defer (cần versioned WF migration trước). **PE 3-button approval** (Duyệt forward / Trả lại smart-reject / Từ chối khoá phiếu). @@ -61,6 +61,7 @@ | Ngày | Ai | Task | Commit | |---|---|---|---| +| 2026-05-07 | Claude | **🎯 SESSION 15 — Tooltip diagnose "Lưu & Gửi Duyệt" + Plan drastic refactor flat workflow → DEFER** — User UAT live screenshot phiếu PE Bản nháp + báo "Lưu & Gửi Duyệt" KHÔNG hoạt động + suy đoán "trùng ID với phiếu khác". Chẩn đoán: button silent disabled khi `evaluation.workflow.nextPhases` không có forward phase (chỉ TuChoi/TraLai). FE chưa có visual feedback → user không biết. Improvement (commit `835cc7f`): compute `forwardPhase` once + add `submitDisabledReason` string giải thích reason (canEditPhase=false / readOnly / !forwardPhase với hint admin kiểm tra cấu hình quy trình) + button title attribute show reason hover hoặc forward phase label khi enabled + Dialog confirm show forward phase explicit "Sẽ chuyển sang Chờ Purchasing". Mirror fe-admin + fe-user. Build pass cả 2. **"Trùng ID" KHÔNG phải bug FE** — `PurchaseEvaluationWorkspacePage` URL state đúng (`+ Thêm mới` clear `id`, save set new), mỗi PE row unique GUID + MaPhieu. **Tiếp theo plan drastic refactor**: User chốt "bỏ phase enum hoàn toàn, dùng ChoDuyet=10 đơn nhất + currentStepIndex tracking" + workflow flat list (Phòng × Cấp × Users[]) thay InnerStep model. Surface 6 chunk plan + start Chunk A: edit Domain entities (Phase enum +ChoDuyet=10, WorkflowStep +DeptId/PositionLevel, drop InnerStep class+nav, PE/Contract +CurrentWorkflowStepIndex/RejectedAtStepIndex, *DeptApproval drop InnerStepId) + EF Configurations (drop InnerStep config + nav, restore simple unique non-filtered) + DbContext drop DbSets — 12 files trong working tree. Realize scope realistic ~8-10h (PolicyRegistry rewrite + 2 Service rewrite + App CQRS + 12 tests rewrite + Designer FE + Migration 21 + Docs) vượt session boundary + risk session context deep ~30 commits. **REVERT working tree** về `835cc7f` clean. Add memory `feedback_drastic_refactor_scope` decision rule: drastic refactor cần dedicated session, ước tính conservative (2x buffer), tránh mid-session big refactor. **Stats unchanged**: 96 test pass, 20 mig, 57 bảng. | `835cc7f` | | 2026-05-07 | Claude | **🎯 SESSION 14 — PE 3-button workflow Duyệt/Trả lại/Từ chối + Task 2 sample seed in-progress** — User chỉ thị thay 2-button approval bằng 3 hành động rõ ràng cho approver: **Duyệt** (forward), **Trả lại** (về DangSoanThao + Drafter sửa, smart reject Mig 16 + clear N-stage rows + Drafter resume jump-back), **Từ chối** (Phase=TuChoi, phiếu khoá vĩnh viễn 17 handler Mig 16 lock edit, Drafter phải tạo phiếu mới). 1 commit (`0d77698`): Domain `PurchaseEvaluationPolicy.cs` NccOnly + NccWithPlan thêm `(X → TuChoi)` transition cho mọi phase trung gian (ChoPurchasing/ChoCCM/ChoDuAn/ChoCEODuyetPA/ChoCEODuyetNCC) với roles của phase. FromDefinition expand: mỗi step (trừ DangSoanThao) thêm (step.Phase → TuChoi) với roles step. Service `PurchaseEvaluationWorkflowService.TransitionAsync` — Reject branch tách 2 case: target=TuChoi giữ nguyên (KHÔNG override + KHÔNG set RejectedFromPhase + KHÔNG clear N-stage); target khác (DangSoanThao) → smart reject (force DangSoanThao + RejectedFromPhase + clear N-stage). FE PeWorkflowPanel (admin + user mirror): render 3 button rõ ràng "✓ Duyệt → X" brand / "← Trả lại (về Drafter sửa)" red / "✗ Hủy / Từ chối" red. Decision logic: target=TuChoi || isSendBack → Reject (2), else Approve (1). Dialog confirm: title rõ + Cancel case warning red "phiếu sẽ bị khoá hoàn toàn" + SendBack case hint amber "Phiếu về DangSoanThao, Drafter sửa rồi trình lại — workflow tự jump tới phase này". Tests: rename `Reject_Sets_RejectedFromPhase_And_Forces_DangSoanThao` → `Reject_To_DangSoanThao_Sets_RejectedFromPhase_TraLai` (target từ TuChoi → DangSoanThao). NEW `Reject_To_TuChoi_Locks_Permanently_No_RejectedFromPhase`. Update `NStage_Reject_Clears_InnerStep_Rows_At_Phase` target → DangSoanThao. **95 → 96 test pass** (+1 Từ chối). **Task 2 sample seed in-progress**: dotnet ef database update applied Mig 9-20 lên LocalDB SolutionErp_Dev (trước đó chỉ Mig 1-8 vì DesignTimeDbContextFactory hardcoded SolutionErp_Design ≠ runtime SolutionErp_Dev — gotcha tooling distinction). API start để DbInitializer auto-seed 30 demo user nhưng exit 255 sớm khi log buffer full → seed dở dang. Defer Task 2 cho session sau (cần guidance: seed manual SQL hoặc manual API run + sample N-stage workflow def + Update PositionLevel cho 30 users existing). | `0d77698` | | 2026-05-07 | Claude | **🎯 SESSION 13 — Mirror N-stage workflow sang Contract (Mig 20, 5 commit per-chunk + skip Chunk E API)** — User chỉ thị mirror N-stage từ PE sang Contract. Budget defer (cần versioned WF migration trước, hardcoded BudgetPolicy hiện tại chưa có WorkflowDefinition). 5 chunk per-commit (build + ef + test pass mỗi chunk): **Chunk A (`951ffa3`)** Domain entity `WorkflowStepInnerStep` (Domain/Contracts/) + nav WorkflowStep.InnerSteps + ALTER ContractDepartmentApproval.InnerStepId Guid? + EF config FK Cascade Step / Restrict Dept+InnerStep + **Migration 20** `AddContractWorkflowInnerStepsAndAlterDeptApprovalUnique` GỘP 1 (CREATE TABLE WorkflowStepInnerSteps + ALTER InnerStepId + DropIndex old + Recreate filtered legacy `WHERE InnerStepId IS NULL` + new filtered N-stage `WHERE InnerStepId IS NOT NULL` + 3 IX + 3 FK). **Chunk B (`04cf2a0`)** Application CQRS DTO — `WorkflowStepInnerStepDto` + extend `WorkflowStepDto` + GetWorkflowAdminOverview Include InnerSteps + DeptNames map + `CreateWorkflowStepInnerStepInput` + `CreateWorkflowStepInput` extend (default null backward compat) + Validator child rules + Handler atomic batch insert. **Chunk C (`e247b67`)** ContractWorkflowService refactor mirror PE — load definition InnerSteps eager, reject branch clear N-stage rows tại fromPhase, dept approval block split hasInnerSteps→N-stage logic / else→legacy 2-stage. N-stage flow giống PE: yêu cầu actor có DeptId+PositionLevel, match firstPending Order asc + (exact level OR canBypass + level≥), exact upsert 1 row InnerStepId, bypass batch upsert NV+PP+TP cùng dept ≤ actor (audit IsBypassed cho cấp dưới), recheck stillPending → BLOCK + log "duyệt cấp X (còn Y pending)". **Chunk D (`7c0772a`)** Tests 6 N-stage Contract mirror PE pattern + helper SeedWorkflowDefinitionAsync 2 step adjacent (DangGopY + DangDamPhan) + SeedContractAsync với Project + Supplier seed + FakeChangelogService + FakeContractCodeGenerator stubs. Bug fix: legacy fallback test ban đầu fail (Standard policy DangGopY → DangDamPhan chỉ cho [Drafter, DeptManager], không Procurement) → switched phase pair sang DangKiemTraCCM → DangTrinhKy + role CostControl khớp. Total 89 → **95 test pass**. **Chunk E SKIP** — WorkflowsController auto-bind `[FromBody] CreateWorkflowDefinitionCommand` record qua JSON, no code change cần. **Chunk F (current)** FE-Admin types/users.ts đã có PositionLevel const từ Session 12 reuse. WorkflowsPage Designer extend mirror PeWorkflowsPage Chunk F: InnerStepDto + EditInnerStep types + copyFromDefinition include + departmentsList query + sub-section "Cấp duyệt nhỏ trong phòng" drag-list { Phòng × Cấp + required } + button "+ Thêm cấp duyệt" emerald + payload include Order asc. Empty state hint fallback 2-cấp legacy. KHÔNG đụng fe-user (admin-only). Docs/Skill update. **Backward compat 100%**: workflow Contract no InnerSteps → fallback legacy 2-stage Mig 16. Data legacy InnerStepId=null vẫn enforce unique cũ qua filtered index. Defer Budget mirror cho session sau (cần migration `AddBudgetVersionedWorkflow` trước). | `951ffa3` (A) · `04cf2a0` (B) · `e247b67` (C) · `7c0772a` (D) · (current F) | | 2026-05-07 | Claude | **🎯 SESSION 12 — N-stage workflow approval Phòng × PositionLevel cấu hình động (PE-only first, 6 commit per-chunk + Mig 18+19)** — User yêu cầu mở rộng từ 2-stage Mig 16 (NV.Review/TPB.Confirm) sang N-stage cấu hình động: mỗi WorkflowStep cha (= 1 phase) có thể cấu hình chuỗi InnerSteps con theo Department × PositionLevel với Order sequential. Spec defaults chốt 6 câu (PositionLevel int 1=NV/2=PP/3=TP, sequential pure, bypass cùng dept TP skip NV+PP, smart reject reset N-stage rows về DangSoanThao, PE-only first, designer 1 sub-section InnerSteps). 6 chunk per-commit (build + ef + test pass mỗi chunk per `feedback_per_chunk_commit.md`): **Chunk A (`13ab533`)** Domain enum `PositionLevel` (NV/PP/TP) + entity `PurchaseEvaluationWorkflowStepInnerStep` + ALTER User.PositionLevel int? + ALTER PEDeptApprovals.InnerStepId Guid? + EF config + **Migration 18** `AddPeWorkflowInnerStepsAndPositionLevel` (1 CREATE TABLE + 2 ALTER + 3 index + FK Cascade Step / Restrict Dept/InnerStep). 3-file rule. **Chunk B (`0e56bd0`)** Application CQRS DTO — `PeWorkflowStepInnerStepDto` + extend `PeWorkflowStepDto` + `CreatePeWorkflowStepInnerStepInput` (default null backward compat existing PeWorkflowAdminTests) + Validator child rules + Handler atomic batch insert + UserDto +PositionLevel field + `SetUserPositionLevelCommand` mirror SetBypassReview. **Chunk C (`0c62e24`)** Service N-stage logic — **Migration 19** `AlterPeDeptApprovalsUniqueFilteredForInnerSteps` (filtered unique: legacy `WHERE InnerStepId IS NULL` + N-stage `WHERE InnerStepId IS NOT NULL`) cho phép multi-row cùng dept khác inner step. PurchaseEvaluationWorkflowService refactor: load definition InnerSteps eager + reject branch clear N-stage rows + dept block split hasInnerSteps→N-stage logic / else→legacy 2-stage. N-stage flow: yêu cầu actor có DeptId+PositionLevel, match firstPending (Order asc IsRequired) same dept + (exact level OR canBypass + level≥), exact match upsert 1 row InnerStepId, bypass batch upsert NV+PP+TP cùng dept ≤ actor level (audit IsBypassed cho cấp dưới skip), recheck stillPending → BLOCK + log "duyệt cấp X (còn Y pending)" / all done → fall through phase transition. Backward compat: workflow no InnerSteps fallback legacy + InnerStepId=null filter unique cũ vẫn enforce. **Chunk D (`3d76c6b`)** Tests N-stage 6 test mới (NV first blocks / 3-level sequential pass / TP bypass skips / wrong dept throws 403 / reject clears rows / legacy fallback no inner) + IdentityFixture extend `+positionLevel` arg + helper SeedWorkflowDefinitionAsync 2 step adjacent (ChoPurchasing+ChoCCM) cho FromDefinition build transition policy guard pass. Total 83→**89 test pass**. **Chunk E (`83ffabd`)** API `PATCH /users/{id}/position-level` mirror SetBypassReview pattern + body `{positionLevel:int?}` Authorize Users.Update. **Chunk F (current)** FE-Admin types/users.ts +positionLevel field + PositionLevel const + Label/Short maps. PeWorkflowsPage Designer extend: InnerStepDto type + EditInnerStep type + copyFromDefinition include + departmentsList query + sub-section "Cấp duyệt nhỏ trong phòng" per step card với drag-drop list { Phòng × Cấp + required checkbox } + button "+ Thêm cấp duyệt" (xanh emerald) + payload include innerSteps Order asc. UsersPage column "Cấp" badge NV/PP/TP emerald + action button cycle null→1→2→3→null call positionLevelMut PATCH. KHÔNG đụng fe-user (admin-only feature). Docs/Skill update. PE-only first. Backward compat 100%: workflow no InnerSteps + data legacy 2-stage rows không phá. | `13ab533` (A) · `0e56bd0` (B) · `0c62e24` (C) · `3d76c6b` (D) · `83ffabd` (E) · (current F) | diff --git a/docs/changelog/migration-todos.md b/docs/changelog/migration-todos.md index 8a229aa..a121564 100644 --- a/docs/changelog/migration-todos.md +++ b/docs/changelog/migration-todos.md @@ -157,6 +157,20 @@ Session log: `2026-04-28-chot-session-4-budget.md`. ## 📝 Phase 9 — UAT + Ops + carry over (Session 6+ active) +### ✅ Session 15 done (2026-05-07) — Tooltip diagnose "Lưu & Gửi Duyệt" + drastic refactor flat workflow DEFER (1 commit) + +User UAT live báo button "Lưu & Gửi Duyệt" KHÔNG hoạt động + suy đoán "trùng ID". Diagnose: silent disabled khi `nextPhases` không có forward phase. Add tooltip + dialog warning. "Trùng ID" KHÔNG phải bug FE. + +- [x] **Tooltip diagnose** (commit `835cc7f`) — fe-admin + fe-user PeDetailTabs: compute `forwardPhase` once + `submitDisabledReason` reason string + button title attribute hover + dialog confirm show forward phase label explicit. Build pass × 2. KHÔNG đụng BE. +- [⏸] **Drastic refactor flat workflow** — User chốt "bỏ phase enum hoàn toàn, dùng ChoDuyet=10 đơn nhất + currentStepIndex tracking". Attempt edit working tree 12 file Domain/Configurations/DbContext, realize scope realistic ~8-10h (PolicyRegistry + Service + App CQRS + 12 tests + FE Designer + Migration 21 + Docs) vượt session. REVERT working tree về `835cc7f` clean. **Defer Session 16+** dedicated session. + +**Decision memorized:** add memory `feedback_drastic_refactor_scope.md` — drastic refactor cần dedicated session với context fresh, scope estimation conservative (2x buffer), tránh mid-session big refactor (risk session context deep + breaking states giữa chunk). + +**Defer Session 16+:** +- [ ] Drastic refactor flat workflow (Mig 21, ~8-10h, dedicated session) — flat WorkflowStep với DepartmentId+PositionLevel, drop InnerStep, PE/Contract CurrentWorkflowStepIndex tracking, Phase enum simplify ChoDuyet=10, Service rewrite, Designer FE rewrite. +- [ ] Hoặc fallback Approach Y — FE Designer flat UI giới hạn 5 phòng (auto-assign Phase behind scenes), ROI 1-2h, KHÔNG drastic. +- [ ] Task 2 sample data seed N-stage (block trên DesignTime vs Runtime DB) + ### ✅ Session 14 done (2026-05-07) — PE 3-button workflow Duyệt/Trả lại/Từ chối (1 commit) User chỉ thị thay 2-button approval (Duyệt + Reject mơ hồ) bằng 3 hành động rõ: diff --git a/docs/changelog/sessions/2026-05-07-2600-tooltip-defer-drastic.md b/docs/changelog/sessions/2026-05-07-2600-tooltip-defer-drastic.md new file mode 100644 index 0000000..c93aba0 --- /dev/null +++ b/docs/changelog/sessions/2026-05-07-2600-tooltip-defer-drastic.md @@ -0,0 +1,158 @@ +# Session 2026-05-07 (S15) — Tooltip diagnose "Lưu & Gửi Duyệt" + drastic refactor DEFER + +**Dev:** Claude +**Duration:** ~1h +**Base commit:** `7c83ac8` (sau Session 14 wrap-up docs) +**Final commit:** `835cc7f` (+ working tree refactor revert) +**Total commits:** 1 + +## Bối cảnh + +User UAT live screenshot phiếu PE Bản nháp "huy test 1" (PE/2026/A/004) trên `eoffice.solutions.com.vn/purchase-evaluations/workspace?type=1&id=...`. Báo button "Lưu & Gửi Duyệt" KHÔNG hoạt động + suy đoán "Hình nó đang bị trùng ID với thằng khác? Mỗi lần tạo mới Phiếu Duyệt NCC là 1 phiếu độc lập nhé". + +## Phần 1 — Diagnose tooltip (commit `835cc7f`) + +### Root cause analysis + +`PeDetailTabs.tsx` line 220: `disabled={!canSubmitForApproval || submitForApproval.isPending}`. Khi `canSubmitForApproval=false` button visually clickable nhưng không fire onClick → user không biết tại sao silent. + +`canSubmitForApproval = mode === 'workspace' && canEditPhase && !readOnly && evaluation.workflow.nextPhases.some(p => p !== TuChoi && p !== TraLai)`. + +Hypothesis: phiếu pin `WorkflowDefinitionId` của 1 version cấu hình thiếu adjacent step → `policy.NextPhasesFrom(DangSoanThao)` empty (legacy data hoặc admin chưa setup workflow). + +### Fix UX (PeDetailTabs.tsx, fe-admin + fe-user mirror) + +```javascript +const forwardPhase = evaluation.workflow.nextPhases.find(p => + p !== TuChoi && p !== TraLai) +const canSubmitForApproval = mode === 'workspace' && canEditPhase && !readOnly && forwardPhase != null + +const submitDisabledReason = !canEditPhase + ? `Phiếu đã ở phase X — chỉ Bản nháp / Trả lại mới sửa + gửi được.` + : readOnly + ? 'Chế độ chỉ đọc.' + : !forwardPhase + ? `Workflow không có phase tiếp theo từ X. Liên hệ admin kiểm tra cấu hình quy trình.` + : null +``` + +Button: +- `title={submitDisabledReason ?? "Gửi phiếu sang \"\""}` — hover tooltip show reason hoặc forward phase +- Dialog confirm thay text generic "Gửi phiếu vào quy trình duyệt?" → explicit "Sẽ chuyển sang \"Chờ Purchasing\". Sau khi gửi sẽ KHÔNG sửa được nữa (trừ khi approver Trả lại)." + +Mirror fe-admin + fe-user. KHÔNG đụng BE. + +Build pass cả 2 app. + +### "Trùng ID" KHÔNG phải bug FE + +`PurchaseEvaluationWorkspacePage.tsx` URL state đúng: +- `+ Thêm mới` → `setParams({ mode: 'new', id: null })` +- POST tạo phiếu → BE gen new GUID + MaPhieu mới (atomic SERIALIZABLE qua `PurchaseEvaluationCodeGenerator`) +- Save → URL set `id=` thay thế + +Mỗi PE row unique GUID + MaPhieu (UNIQUE filtered). Không có path share ID. User suy đoán có thể do button silent disabled → tưởng load lại record cũ. + +## Phần 2 — Plan drastic refactor flat workflow → DEFER + +User chốt drastic refactor: "bỏ phase enum hoàn toàn, dùng ChoDuyet=10 đơn nhất + currentStepIndex tracking". + +### Spec mới (theo user) + +Workflow = list flat (Phòng × Cấp × Users[]). Ví dụ Quy trình A: +- Phòng A (2 cấp): cấp 1 NV A, cấp 2 NV B +- Phòng B (3 cấp): cấp 1 NV C, cấp 2 [NV D 1, D 2, D 3], cấp 3 NV E +- Phòng C (1 cấp): NV C + +Rules: +- Phòng 1 cấp → 1 user duyệt = pass phòng đó +- Phòng N cấp → tuần tự cấp 1 → 2 → ... → N +- Cùng cấp + cùng phòng = OR (1 user duyệt = pass cấp) +- Hết tất cả phòng → DaDuyet +- PE pin Quy trình ID, không thay đổi giữa chừng + +### Plan refactor 6 chunk (theo `feedback_per_chunk_commit.md`) + +| Chunk | Scope | Estimate | +|---|---|---| +| A | Domain enum + entity changes + Migration 21 | 50min | +| B | App CQRS + Policy registry rewrite | 45min | +| C | PE Service rewrite TransitionAsync flat | 2-3h | +| D | Contract Service rewrite + Tests update (drop 12 N-stage tests) | 1.5h | +| E | FE Designer flat UI (PeWorkflowsPage + WorkflowsPage) | 1.5h | +| F | FE PeWorkflowPanel + Docs | 1h | + +**Tổng realistic:** ~8-10h focused. Vượt session boundary + risk session deep ~30 commits. + +### Attempt → REVERT + +Edit working tree 12 file (Chunk A partial): +- `PurchaseEvaluationPhase.cs`: + ChoDuyet=10 enum value +- `ContractPhase.cs`: + ChoDuyet=10 +- `PurchaseEvaluation.cs`: + CurrentWorkflowStepIndex, RejectedAtStepIndex +- `Contract.cs`: + same 2 fields +- `WorkflowDefinition.cs` (Contract): drop class WorkflowStepInnerStep + nav, WorkflowStep + DepartmentId, PositionLevel +- `PurchaseEvaluationWorkflowDefinition.cs`: same pattern +- `ContractDepartmentApproval.cs`: drop InnerStepId +- `PurchaseEvaluationDepartmentApproval.cs`: drop InnerStepId +- `WorkflowDefinitionConfiguration.cs`: drop InnerStep config + add DeptId/PositionLevel cấu hình + FK Restrict +- `PurchaseEvaluationConfiguration.cs`: same +- `DepartmentApprovalsConfiguration.cs`: drop InnerStepId FK + filtered indexes, restore simple unique non-filtered +- `ApplicationDbContext.cs`: drop DbSet<*WorkflowStepInnerStep> × 2 + +Realize codebase chưa compile (Service + App + Tests dùng `WorkflowStepInnerStep` đã drop). Need rewrite ALL dependent code trong cùng Chunk A → blow scope vượt session. + +**Decision REVERT** working tree về `835cc7f` clean. Tests 96 pass intact. + +### Memory entry mới + +`feedback_drastic_refactor_scope.md` — decision rule: drastic refactor cần dedicated session với context fresh, scope estimation conservative (2x buffer), tránh mid-session big refactor (risk session context deep + breaking states giữa chunk + tests rewrite biggest risk). + +## Verify + +- ✅ `git restore` 12 files reverted +- ✅ `dotnet test` 96 pass (54 + 42) — state intact +- ✅ working tree clean (chỉ 2 untracked .zip backup files) +- ✅ commit `835cc7f` (tooltip) pushed gitea OK + +## Stats cumulative (sau Session 15) + +| | Trước S15 | Sau S15 | Diff | +|---|---:|---:|---:| +| BE LOC | ~15800 | ~15800 | 0 (FE-only commit + revert) | +| Migrations | 20 | 20 | 0 | +| DB tables | 57 | 57 | 0 | +| FE pages | 32 | 32 | 0 | +| Tests | 96 | 96 | 0 | +| Docs | ~58 | ~59 | +1 (session log này) | +| Memory entries | 11 | **12** | +1 (drastic refactor scope) | +| Commits S15 | — | **+1** | `835cc7f` | + +## Plan organization sau Session 15 + +``` +Plan cha: Phase 9 active — UAT +├── Plan con A-S14: Tất cả ✅ DONE (xem session logs trước) +├── Plan con S15: Tooltip diagnose + drastic refactor DEFER +│ ├── ✅ FE PE button "Lưu & Gửi Duyệt" tooltip + dialog reason rõ +│ └── ⏸ Drastic refactor flat workflow — DEFER session sau (~8-10h) +└── Plan con Defer S16+: + ├── Drastic refactor flat workflow (Mig 21, ~8-10h, dedicated session) + │ OR fallback Approach Y (FE flat UI giới hạn 5 phòng, 1-2h) + ├── Task 2 sample data seed N-stage (block DesignTime vs Runtime DB) + ├── Budget N-stage (cần migration `AddBudgetVersionedWorkflow`) + ├── schema-diagram §17-19 Mig 18-20 (defer cron audit 2026-06-01) + └── Hard blockers Ops (UAT, SMTP, Rotate creds, SQL backup, Remove huypham.vn, win-acme) +``` + +## Handoff + +UAT iteration mode. Phiếu PE Bản nháp giờ có tooltip rõ reason khi không gửi được. User test hover → biết admin cần kiểm tra cấu hình workflow definition. + +Drastic refactor pending dedicated session. Khi resume: +1. Fresh session start với context clean +2. Plan kỹ 6 chunk per-commit +3. Buffer 2x estimate (~16h thực tế nếu phát sinh) +4. Test rewrite biggest risk — pattern reusable nhưng nội dung phải mới hoàn toàn + +**Cron audit kế:** 2026-06-01 (~25 ngày).