Files
postgenerator/.planning/phases/02-prompt-control-output-review/02-02-SUMMARY.md
Michele 14588eaa94 docs(02-02): complete per-item regeneration + summary counter plan
Tasks completed: 2/2
- PostCard regen button with inline form, topic override, badge
- OutputReview summary counter with regenerated/edited tracking

SUMMARY: .planning/phases/02-prompt-control-output-review/02-02-SUMMARY.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 21:53:43 +01:00

98 lines
5.1 KiB
Markdown

---
phase: 02-prompt-control-output-review
plan: 02
subsystem: output-review
tags: [react, postcard, regeneration, summary-counter, inline-form]
dependency_graph:
requires:
- 02-01 (Prompt CRUD + Prompt Editor UI)
- 01-04 (PostCard, OutputReview, SlideViewer, localResults pattern)
provides:
- Per-item regeneration with topic/notes override on PostCard
- Visual badge for regenerated posts (amber RefreshCw icon)
- Summary counter in OutputReview header (generati/rigenerati/modificati)
affects:
- Future phases that enhance OutputReview or PostCard
tech_stack:
added: []
patterns:
- Inline popover form for regen (no modal overlay)
- regeneratedSlots Set for tracking regen state across session
- JSON.stringify comparison for manual edit detection vs original jobData
key_files:
created: []
modified:
- frontend/src/components/PostCard.tsx
- frontend/src/pages/OutputReview.tsx
decisions:
- id: tono-as-notes-override
decision: "Regen notes passed via tono field in GenerateRequest instead of adding a new backend field"
reason: "The tono field is injected into the prompt as context — reusing it for user notes is pragmatic and avoids backend changes for a frontend-only enhancement."
date: 2026-03-08
- id: json-stringify-edit-detection
decision: "Manual edit detection uses JSON.stringify comparison between localResults and jobData.results"
reason: "With only 13 posts, the performance cost is negligible. Avoids tracking a separate dirty flag per post."
date: 2026-03-08
metrics:
duration: ~4 min
completed: 2026-03-08
---
# Phase 02 Plan 02: Per-item Regeneration + Summary Counter Summary
**PostCard con bottone Rigenera inline, form popover per topic/note override, badge rigenerato amber, e summary counter real-time in OutputReview con tracking rigenerati/modificati.**
## What Was Done
### Task 1: PostCard — bottone Rigenera con popover inline, topic override, badge rigenerato
Modified `frontend/src/components/PostCard.tsx`:
- **New prop `isRegenerated`** — When true, shows an amber `RefreshCw` icon badge next to the slot number, visually distinguishing regenerated posts from originals.
- **`handleRegen` function** — Calls `POST /api/generate/single` with optional topic override (via `slot.topic`) and notes override (via `tono` field). On success, calls `onRegenerated` callback and resets the form.
- **Regen button in card header** — Small `RefreshCw` icon button positioned before the expand/collapse chevron. Uses `e.stopPropagation()` to not interfere with expand toggle.
- **Inline popover form** — Appears below the header (above SlideViewer) when Regen button is clicked. Contains:
- Optional "Topic alternativo" text input
- Optional "Note aggiuntive" text input
- "Rigenera" button (amber, with spinner during loading)
- "Annulla" button to close and reset form
- Error message display if generation fails
- **Header refactored** — Changed from a single `<button>` to a `<div>` with separate click zones: the content area expands/collapses, the regen button opens the form, and the chevron also expands/collapses.
### Task 2: OutputReview — summary counter con tracking rigenerati/modificati
Modified `frontend/src/pages/OutputReview.tsx`:
- **`regeneratedSlots` state** — `Set<number>` tracking slot indices of regenerated posts. Updated in `handleRegenerated`.
- **`regeneratedCount`** — Derived from `regeneratedSlots.size`.
- **`manuallyEditedCount`** — Counts posts whose `post` field differs from `jobData.results` (original server data) via `JSON.stringify` comparison, minus regenerated posts to avoid double-counting.
- **Summary counter in header** — Shows: `N post | X generati | Y falliti | Z rigenerati | W modificati | job: ID`. Regenerated and modified counts only appear when > 0. Uses amber color for regenerated (with RefreshCw icon) and blue for manually edited.
- **`isRegenerated` prop passed to PostCard** — Each PostCard receives `regeneratedSlots.has(result.slot_index)`.
- **Updated info box** — Now mentions the regen feature with an inline RefreshCw icon.
## Deviations from Plan
None - plan executed exactly as written.
## Verification
- [x] PostCard success shows a Regen button (RefreshCw icon) in the header
- [x] Click on Regen opens inline form with topic and notes fields (both optional)
- [x] Regeneration calls POST /api/generate/single with topic/tono override and updates the card
- [x] Regenerated posts show an amber RefreshCw badge next to the slot number
- [x] Summary counter in OutputReview header shows counts for generati/falliti/rigenerati/modificati
- [x] Summary counter updates in real-time after regeneration or edit
- [x] CSV download contains latest versions (localResults updated by both regen and edit)
- [x] TypeScript compiles without errors (npx tsc --noEmit)
## Next Phase Readiness
Phase 02 is now COMPLETE. Both plans (02-01 Prompt CRUD + Prompt Editor, 02-02 Per-item Regeneration + Summary Counter) are done. The system is ready for:
- `vps-lab-deploy` to test end-to-end on VPS
- Phase 03 (Canva-ready CSV polish + advanced export)