docs: OpenSpec change add-page-drafts-and-templates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
8e56e9844e
commit
da39c9bd84
6 files changed
+187
No files matched your search
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-03
|
||||
@@ -0,0 +1,45 @@
|
||||
## Context
|
||||
|
||||
Design: `docs/superpowers/specs/2026-12-03-page-builder-design.md`, change 2. A page is one `cms_page` row (slug, title, meta description, status, hide header, blocks JSON), saved whole by `CmsPageService.save` after `CmsBlockValidator`; mobile-api scopes every call to the caller's company; the portal editor saves through `/api/pages`.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:** draft and live separation for published pages; Publish changes and Discard changes; starter templates; Duplicate.
|
||||
|
||||
**Non-Goals:** version history; scheduled publishing; templates saved by staff; drafts for pages that were never published (they have no visitors, so they save directly as today).
|
||||
|
||||
## Decisions
|
||||
|
||||
1. **One nullable JSON column `draft`** on `cms_page`, holding `{slug, title, metaDescription, hideHeader, blocks}`. Status and company stay on the row.
|
||||
2. **Save rules** (`/counter/cmsPage/save`, unchanged request):
|
||||
- New page, or a stored page whose status is DRAFT: writes the row as today (including going straight to PUBLISHED).
|
||||
- Stored page PUBLISHED, request status PUBLISHED: validates exactly as today and writes the content into `draft`. The live columns do not change.
|
||||
- Stored page PUBLISHED, request status DRAFT (unpublish): writes the row from the request and clears `draft`; with no visitors the split no longer matters.
|
||||
- Slug uniqueness is checked against the other pages' live slugs, as today.
|
||||
3. **Publish** (`/counter/cmsPage/publish`, body: id and user): when a draft exists, validates it again (an event may have ended, an image may be gone) and checks its slug again, copies it into the live columns, clears it. With no draft it returns the page unchanged. A refusal comes back like a save refusal, so the editor shows it at its field.
|
||||
4. **Discard** (`/counter/cmsPage/discard`, body: id): clears `draft`.
|
||||
5. **Reads.** `findById` returns the live fields plus `draft` (or null). `search` rows carry `hasDraft`. `findPublished` reads only the live columns, so visitors never see a draft.
|
||||
6. **mobile-api** adds `POST /api/admin/pages/{id}/publish` and `/discard`, each loading the page through the caller's scope first (another company's page is "not found"), relaying refusals like save.
|
||||
7. **Portal editor.** It edits the draft when there is one, else the live content. On a published page:
|
||||
- **Save** stores the draft; a banner then says visitors still see the published version, with **Publish changes** and **Discard changes** (Discard asks first);
|
||||
- **Publish changes** saves the current edits, then publishes.
|
||||
- Status radio Draft plus Save unpublishes, as today.
|
||||
- "View page" opens the live page; Preview shows the draft.
|
||||
8. **Pages list** shows an "Unpublished changes" badge next to the status for rows with `hasDraft`.
|
||||
9. **Templates** are block lists in portal code (`app/lib/pageTemplates.ts`), English placeholder text, no images, the FORM block with no event and link name `signup`, buttons linking to `#signup`.
|
||||
- **Event sign-up:** HERO (Dark), TRUST, FEATURES, STEPS (Muted), FAQ, FORM (Muted).
|
||||
- **Service showcase:** HERO (Dark), TRUST, FEATURES, STEPS, FAQ, CTA (Accent), FORM (Muted).
|
||||
- `/pages/new` first shows a picker (Blank and the two templates, each with a one-line description); choosing one opens the editor filled with its blocks. A test runs every template through the same rules the server applies, apart from the event and images that staff fill in.
|
||||
10. **Duplicate** (list row action and editor button) opens `/pages/new?from=<id>`. The editor loads that page (its draft if any), clears the id, sets status Draft, title "<title> (copy)" and slug "<slug>-copy", same company. Nothing is stored until Save. No new API.
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- Two staff editing one published page overwrite each other's draft (last save wins), as today for live pages. Accepted.
|
||||
- A draft's slug can collide with a page published after the draft was saved → Publish checks again and refuses on `slug`.
|
||||
- Rollback drops unpublished drafts → noted in `99-rollback.sql`; publish or note drafts first.
|
||||
|
||||
## Migration Plan
|
||||
|
||||
1. Run `sql/01-page-draft.sql` (DDL) before the new services-counter starts.
|
||||
2. Deploy services-counter, mobile-api, the portal; run `sql/02-draft-template-labels.sql`.
|
||||
Rollback: previous images, then `sql/99-rollback.sql`.
|
||||
@@ -0,0 +1,29 @@
|
||||
## Why
|
||||
|
||||
Marketing staff will edit pages that are already live and that printed QR codes point to. Today every Save on a published page changes it for visitors at once, so half-finished edits go live. Staff also start each event page from a blank form, though most event pages share one shape. This is change 2 of the page builder: `docs/superpowers/specs/2026-12-03-page-builder-design.md`.
|
||||
|
||||
## What Changes
|
||||
|
||||
- Published pages keep a separate draft. Saving a published page stores the draft; visitors keep seeing the published version until staff press **Publish changes**. **Discard changes** drops the draft. Unpublishing and pages never published work as today.
|
||||
- The staff preview and the editor show the draft when there is one. The pages list marks pages with unpublished changes.
|
||||
- **New page** first offers a starting point: Blank, **Event sign-up** or **Service showcase** (starter templates built from the section types).
|
||||
- **Duplicate** copies a page into a new draft of the same company.
|
||||
- New labels in English and Chinese.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `landing-pages`: draft and live content, starter templates, duplicate.
|
||||
|
||||
## Impact
|
||||
|
||||
- DDL: `cms_page.draft` (nullable JSON) in `sql/01-page-draft.sql`; mirror in `local/seed/`.
|
||||
- services-counter: save writes the draft for a published page; new publish and discard endpoints; `findById` returns the draft; list rows carry `hasDraft`; `findPublished` unchanged.
|
||||
- mobile-api: publish and discard admin endpoints, scoped like save.
|
||||
- Portal: BFF routes, editor buttons and banner, list badge, preview, template picker, duplicate, labels.
|
||||
- Rollback: `sql/99-rollback.sql` drops the column, which loses unpublished drafts; the previous release saves published pages directly again.
|
||||
@@ -0,0 +1,83 @@
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: The Pages List
|
||||
|
||||
`/pages` SHALL list the pages in scope with their title, public address, status, an "Unpublished changes" mark when a published page has a draft, and last update, with a search by title or slug and an Add page action. Each row SHALL open its editor and offer Duplicate. Pages SHALL appear in the sidebar for users with `BO_PAGES`.
|
||||
|
||||
#### Scenario: Draft in the list
|
||||
|
||||
- **GIVEN** INS page `launch` is a draft
|
||||
- **WHEN** INS staff open `/pages`
|
||||
- **THEN** its row shows status Draft and address `/p/INS/launch`
|
||||
|
||||
#### Scenario: Unpublished changes in the list
|
||||
|
||||
- **GIVEN** INS page `hotel` is published and has a saved draft
|
||||
- **WHEN** INS staff open `/pages`
|
||||
- **THEN** its row shows status Published and "Unpublished changes"
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Published Pages Keep A Separate Draft
|
||||
|
||||
Saving a published page with status Published SHALL store the content as the page's draft, checked by the same rules as any save, and SHALL NOT change what visitors see. Saving a published page with status Draft SHALL unpublish it, write the content to the page and drop any draft. A page that is not published SHALL save directly, as before. The staff preview and the editor SHALL show the draft when there is one.
|
||||
|
||||
#### Scenario: Editing a live page does not change it for visitors
|
||||
|
||||
- **GIVEN** INS page `hotel` is published with heading "Hotel day"
|
||||
- **WHEN** staff change the heading to "Hotel week" and save
|
||||
- **THEN** visitors still see "Hotel day"
|
||||
- **AND** the editor and the staff preview show "Hotel week"
|
||||
|
||||
#### Scenario: Unpublishing drops the draft
|
||||
|
||||
- **GIVEN** a published page with a draft
|
||||
- **WHEN** staff choose status Draft and save
|
||||
- **THEN** the page is a draft with the saved content and no separate draft
|
||||
|
||||
### Requirement: Publish And Discard Changes
|
||||
|
||||
Publishing a page's changes SHALL check its draft again by the same rules, including a unique slug, then make it the page's content and drop the draft. A refusal SHALL show at its field and change nothing. Discarding changes SHALL ask first, then drop the draft so the editor shows the published content again. Both SHALL be limited to pages in the caller's company scope.
|
||||
|
||||
#### Scenario: Publish changes
|
||||
|
||||
- **GIVEN** published page `hotel` has a draft with heading "Hotel week"
|
||||
- **WHEN** staff press Publish changes
|
||||
- **THEN** visitors see "Hotel week" and the page has no draft
|
||||
|
||||
#### Scenario: Publish refused for a taken slug
|
||||
|
||||
- **GIVEN** a draft with slug `launch` and another page published with slug `launch` since
|
||||
- **WHEN** staff press Publish changes
|
||||
- **THEN** the publish is refused on field `slug` and visitors still see the old content
|
||||
|
||||
#### Scenario: Discard changes
|
||||
|
||||
- **GIVEN** published page `hotel` has a draft
|
||||
- **WHEN** staff press Discard changes and confirm
|
||||
- **THEN** the draft is gone and the editor shows the published content
|
||||
|
||||
#### Scenario: Another company's page
|
||||
|
||||
- **WHEN** CV staff ask to publish INS page `hotel`
|
||||
- **THEN** the request is answered "not found" and nothing changes
|
||||
|
||||
### Requirement: Starter Templates
|
||||
|
||||
New page SHALL first offer Blank, Event sign-up and Service showcase. A template SHALL fill the editor with its sections, placeholder text, a sign-up form with link name `signup` and no event, and buttons linking to `#signup`; nothing is stored until staff save. Every template's sections SHALL pass the server's block rules once an event is chosen.
|
||||
|
||||
#### Scenario: Start from the event template
|
||||
|
||||
- **WHEN** staff choose New page, then Event sign-up
|
||||
- **THEN** the editor shows a hero, trust strip, feature cards, steps, FAQ and a sign-up form, filled with placeholder text
|
||||
- **AND** saving it without choosing the form's event is refused on that event field
|
||||
|
||||
### Requirement: Duplicate A Page
|
||||
|
||||
Duplicate SHALL open the editor with a copy of the page's current content (its draft when there is one), as a new unsaved draft page of the same company titled "<title> (copy)" with slug "<slug>-copy". Nothing SHALL be stored until staff save.
|
||||
|
||||
#### Scenario: Duplicate last event's page
|
||||
|
||||
- **GIVEN** INS page `hotel` titled "Hotel day"
|
||||
- **WHEN** staff press Duplicate on it and save
|
||||
- **THEN** a new draft INS page `hotel-copy` titled "Hotel day (copy)" exists with the same sections
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Co-Lite change add-page-drafts-and-templates: a published page's unpublished draft.
|
||||
-- Run before the new services-counter starts. DDL: needs a user that may alter tables.
|
||||
USE `service-counter`;
|
||||
ALTER TABLE `cms_page`
|
||||
ADD COLUMN `draft` json NULL COMMENT 'Unpublished changes of a published page: slug, title, metaDescription, hideHeader, blocks' AFTER `blocks`;
|
||||
@@ -0,0 +1,23 @@
|
||||
# Tasks: add-page-drafts-and-templates
|
||||
|
||||
Design: `design.md` and `docs/superpowers/specs/2026-12-03-page-builder-design.md` (change 2). Every task is TDD. Work is serial in the main session, with a self-review per task.
|
||||
|
||||
## 1. Data and services
|
||||
|
||||
- [ ] 1.1 SQL: `sql/01-page-draft.sql`, `sql/99-rollback.sql`; mirror 01 into `local/seed/`; apply locally.
|
||||
- [ ] 1.2 services-counter: `draft` on the entity and DTO, `hasDraft` on list rows; save rules for published pages; publish (re-validate, slug check) and discard endpoints; `findPublished` unchanged.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
||||
- [ ] 1.3 mobile-api: `POST /api/admin/pages/{id}/publish` and `/discard`, scoped, refusals relayed like save.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-mobile-api -am verify`
|
||||
|
||||
## 2. Portal
|
||||
|
||||
- [ ] 2.1 BFF routes for publish and discard; services; the editor loads the draft, the published-page banner with Publish changes and Discard changes (confirm); preview shows the draft; list badge.
|
||||
- [ ] 2.2 Templates (`pageTemplates.ts`, with a rules test) and the start picker on New page; Duplicate in the list and editor.
|
||||
- [ ] 2.3 Labels in `defaultMessages.ts` and `zh_CN.seed.json`, `npm run i18n:sql`, `sql/02-draft-template-labels.sql`; rollback lines.
|
||||
- Verify (2.1 to 2.3): `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint`
|
||||
|
||||
## 3. Release
|
||||
|
||||
- [ ] 3.1 `docs/deployment.md`: SQL rows (01 before services-counter starts), the draft behaviour for staff.
|
||||
- [ ] 3.2 Live check (Playwright), on disposable pages: edit a published page and save (the visitor still sees the old version, preview shows the new); Publish changes; Discard changes; New page from each template (refused without an event, then saved); Duplicate; 1280 and 360 px.
|
||||
Reference in new issue
Block a user