Repository navigation
Commit 1e96009
feat(studio): the generic item page's Save takes effect at once; an AI draft gets the designers' notice and discard (#37026)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBTuMGhLAZx29zwDrayDGZZF)_
Fixes #36902
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:管理员在 Studio
的通用详情页(钩子、选项集、视图等)改完点「保存」,改动立刻生效;不再有自动保存开关,也不用再点一次「发布」。
- 为什么做:Studio 重构专题里「通用详情保存即生效」这一项,让通用详情和各个设计器的保存方式一致。
- 出错会怎样:发布被拒时,页面上方写明原因,什么都不生效,页面上的修改保留可以再存;AI
留下的草稿保留并有提示,可以一键放弃;本改动可以直接撤回。
- 要你做什么:无
## What changes
Studio's generic item page (`ResourceEditPage`, every type without its
own designer: hook, picklist, view, page, app, doc…) now saves the way
the designers do (#36511, epic decisions 1, 12, 14).
1. **Save = draft + this one item's publish.** Save writes the draft
(`PUT /meta/:type/:name?mode=draft`, If-Match / If-None-Match pin and
conflict dialog unchanged), then publishes that one item (`POST
/meta/:type/:name/publish`) at the same `?package=` and bundle `member`.
The publish is pinned to the published version the page loaded, through
the existing `DraftSaveGuard.publish` (#36601), so a Save over a row
another editor published since opens the same conflict dialog (reload,
overwrite, keep editing). The auto-save switch, its 1.5 s debounce and
the `metadata-admin:autosave` browser setting are gone; the header's
Publish and discard-draft buttons are gone.
2. **Create publishes after its first save** (If-None-Match `*`, then
the publish).
3. **AI draft** (`draftChanges[].by` is `copilot` or `mcp`): the page
shows the AI's version under the designers' `StudioAiDraftNotice`; a
person's Save makes it live together with their edits; "Discard the AI's
changes" drops that one item's draft at its package and member, and asks
first (in the page's own dialog, objectui#13333) when the page holds
unsaved edits.
4. **A person's pending draft** from before this change is marked "This
item has unpublished changes" with its own Publish (pinned) and Discard
for that one item.
5. **Leave guard**: ×, ‹ ›, the side menu, in-app links, reload and
close ask first when the page holds unsaved edits; browser Back is not
intercepted (decision 12). The seam was already in place
(`chrome/unsavedEdits.ts`); this PR pins it on this page.
6. **A refused publish** shows its reason above the editor in the
designers' words (`publishRefusal`, server text under Details). Nothing
goes live; the draft the Save wrote is taken back when no draft was
pending before, and the edits stay on the page, unsaved. A draft that
was pending before (the AI's or a person's) is kept.
7. **`@object-ui/data-objectstack`: `MetadataClient.layered()` now
forwards `overlayVersion`.** The client rebuilt its answer field by
field and dropped it, so a publish pin read off `layered()` was always
`null`. This is why the Save's publish could not be pinned; it also made
the object page's #36601 publish pin a no-op on a server that serves the
field. Fixed in place (bounded fix: same defect class as the card's pin,
mechanical, the file had no other claim, no new gate surface) and pinned
in `metadata-client.layeredDraft-29793.test.ts`. **Clause-② yes
(widening):** the published package's exported `MetadataLayered` type
gains the optional member `overlayVersion?: string | null` (claim
amendment on #36902, 7137741670; L1-b (3) S1, 7137721696).
New shared piece: `detailSaveAtOnce.ts` (`publishDetailSave`,
`isAiDraft`). The designers' `publishSavedItem` (`studioSaveBar.tsx`)
names no bundle member, so this page carries its own instead of changing
that file. `StudioDesignSurface.tsx`, `DraftConflictDialog.tsx` and
`studioSaveBar.tsx` are unchanged (reused as they are).
### How this relates to #36726 and #36350
- **#36726** (open PR #36958 pins the designers' publish): no shared
files, either PR can land first. This card pins the generic page's own
publish with the same #36601 `DraftSaveGuard` API, used as it is on
main. The `overlayVersion` client fix (item 7) is what makes a pin read
off `layered()` effective at all, the object page's included. One
sequencing item: #36958 adds rule 9 to the guard (a reload over a draft
that was pending before the Save keeps the conflict's pin until the
author re-confirms), answered by a `beforeReload` that returns `'kept'`.
On main that callback is typed to resolve to nothing (a void promise)
and refuses that answer (tsc TS2345, measured), so it cannot be written
here without editing `DraftConflictDialog.tsx`, which this card must not
touch. Today this page is at parity with main's guard. Whichever PR
lands second adds the one-line `beforeReload` for the `hadDraft` case in
`publishDetailSave`.
- **#36350** (view-draft publish takes a draft-version precondition):
left to #36350. That is a change to the publish door (server /
protocol), outside this card's boundary (Metadata-protocol: none). This
page's publish is pinned on the published version, not on the draft
version, so the window #36350 describes (another writer's draft write
between this Save's draft save and its publish, then published by this
Save) is still open for views until #36350 lands. When it does, the
Save's publish can send the draft version it just received; the call
site is `publishDetailSave`.
### Read first (by risk)
1. `ResourceEditPage.tsx` `doSave`: the draft save → `publishDetailSave`
→ refresh sequence, and the refused branch (take-back only when
`hadDraft` is false).
2. `detailSaveAtOnce.ts`: the take-back on a refused or conflicted
publish.
3. `metadata-client.ts` `layered()`: the two `overlayVersion` forwards.
### Two-minute check
Open Studio → All metadata → any view, change its label, press Save.
Expected: one `PUT …?mode=draft` and one `POST …/publish` in the network
panel, the Unsaved chip clears, no "unpublished changes" line, and `GET
/api/v1/meta/view/NAME` already serves the new label.
## Tests
### Acceptance run (the card's 验收 scenario, real browser, self-built
stack)
Backend `examples/app-showcase` (`objectstack dev --seed-admin --fresh`)
and the console dev server, both built from this branch, on per-agent
ports. The items are my own, authored into the showcase's customization
package (`com.example.showcase.custom`): a hook, a shared option set
(picklist) and two views. The backend ran with
`OS_METADATA_WRITABLE=picklist`: the picklist type is not
runtime-creatable by default (`NOT_CREATABLE`, its registry entry), so
the option-set leg needs that operator setting. Each leg edits the label
and presses Save once; the network log is the page's own requests.
| Item | Before Save | Writes after Save | Live read after Save |
|---|---|---|---|
| hook `s36902_stamp_title` | chip `unsaved`, no request in 2.5 s | `PUT
…?mode=draft&package=…custom` then `POST …/publish?package=…custom`
(200) | new label served; no unpublished-changes line |
| picklist `s36902_priority` | same | same pair (200) | same |
| view `showcase_task.s36902_triage` | same | same pair (200) | same |
<details><summary>Screenshots: hook, option set, view (unsaved, then
saved and live)</summary>






</details>
**AI draft.** Written through the real MCP door, not faked: an OAuth
client (dynamic registration, PKCE, consent, `metadata:write`) called
`save_metadata_draft` on `showcase_task.s36902_ai`; the draft read then
carried `draftChanges: [{path: ["label"], by: "mcp", …}]`.
- The page shows the AI's version under the notice (4). An edit then
"Discard the AI's changes" asks in the page's own dialog (5); confirming
sends one `DELETE …?state=draft&package=…custom`, the draft read answers
404 and the live version is back (6).
- A second MCP draft, then an edit and Save: `PUT` draft + `POST
…/publish` (200), the draft read answers 404, the live label is the AI's
change plus the person's edit (7).
- Leave guard: with an unsaved edit, × asked "You have unsaved changes.
Leave this page anyway?", and Cancel stayed on the item.
<details><summary>Screenshots: AI draft notice, discard, save</summary>




</details>
Images: orphan branch `claude/issue-36902-screenshots` at `566b916`.
### Live e2e
`LIVE_APP_URL=… LIVE_API_URL=… pnpm exec playwright test -c
playwright.live.config.ts e2e/live/studio-detail-save-at-once.spec.ts
e2e/live/studio-editor.spec.ts`: 3 passed (the new spec: no auto-save in
2.5 s, × asks, Save sends exactly `PUT` + `POST …/publish`, the live
page has the added block, the draft read is 404, browser Back is not
intercepted; `studio-editor.spec.ts`'s Add-block round trip now reads
the published item after Save).
### Unit
At head `09693db5c`, under the shared verify lock, one run: every test
file under `metadata-admin/` plus every other ui test file that mentions
publish, draft, auto-save or the detail page (338 files), then
`type-check` (which compiles the test files too) of
`@object-ui/data-objectstack`, `@object-ui/i18n` and
`@object-ui/app-shell`.
<details><summary>Readings</summary>
```text
Test Files 338 passed (338)
Tests 2918 passed (2918)
packages/data-objectstack type-check: Done
packages/i18n type-check: Done
packages/app-shell type-check: Done
os-verify-lock: VERDICT command-exit 0
```
New: `ResourceEditPage.saveAtOnce-36902.test.tsx` (19 cases over the
real `MetadataClient` and an in-memory server that honours If-Match /
If-None-Match on the draft door and on the publish door: items 1–6, the
leave guard on ×, ‹ ›, links, beforeunload, Back unguarded, create
publishes, refused create). `metadata-client.layeredDraft-29793.test.ts`
gains the `overlayVersion` forward on both answer shapes (served value,
served null, absent).
</details>
## Acceptance notes
- 'Changes 1' in shots 1–3 is the AI draft of `showcase_task.s36902_ai`,
written through MCP before the save leg for shots 4–7; it clears in shot
6 once that draft is discarded (not the hook: its Save sent `PUT
?mode=draft` then `POST /publish` 200).
- Existing detail-page suites that waited out the auto-save or clicked
the header's Publish / Discard draft now press Save and read the Save's
own publish, or use the unpublished-changes line's buttons (14 files).
Their doubles gained a publish that drains the draft, as the real door
does; assertions that only held because a draft stayed pending after
Save were rewritten to the live result. `layersUnsaved-11799`'s SAVE
case now expects one `/layers` re-read: a Save publishes, so the item
has a layer afterwards.
- Leftover `localStorage.setItem('metadata-admin:autosave', '0')` lines
in suites this PR does not otherwise touch are now no-ops; left as they
are to keep the diff to the card.
- The platform checklist step that says the ResourceEditPage draft
auto-saves and is then published
(`docs/qa/platform-checklist/areas/studio-authoring.json`, the page
Add-block item) is now stale. carrier: #36910 (the epic's
checklist-and-docs card).
- The designers' own auto-save (Data / Automations / Access pillars) is
unchanged: out of this card.
## Verification
<details><summary>Local gates (derived for this diff) and
reconciliation</summary>
- `node scripts/pm/dispatch-gates.mjs --commands`: 39 families. All 39
run locally: 38 exit 0 (`check:*` and the node scripts, re-run after the
last code commit), and `pnpm --dir ui exec vitest run scripts/` under
the lock at `c8a49c900` (the one later commit changes only a live e2e
spec): `Test Files 172 passed | 2 skipped (174)`, VERDICT command-exit
0.
- `node scripts/pm/dispatch-gates.mjs --ran FILE` (each line with its
exit code): `39 derived famil(ies) accounted for — 39 run, 0
NOT-MEASURED (a DERIVED zero)`.
- `node scripts/check-test-source-alias.mjs`: OK, 34 changed test files
judged (the touched suites now load `@objectstack/lint` at collection,
as the gate asks).
- `node scripts/pm/overlap-check.mjs` before every push: `VERDICT clean
exit 0` (shares only the i18n catalogues and `metadata-client.ts` with
#36983, #36985, #36784; each merges cleanly).
- The rest of the farm (lint, the CI test shards, `test:repo`) is CI's;
its check-runs are read on the PR.
</details>
Changed lines: 1,650 over 24 files (1,317 added, 333 removed), one PR.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufziBCAytAzzCu3iPBFR -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0e3187e commit 1e96009
24 files changed
Lines changed: 1317 additions & 333 deletions
File tree
- .changeset
- ui
- e2e/live
- packages
- app-shell/src/views/metadata-admin
- data-objectstack/src
- i18n/src/namespaces/studio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
95 | 93 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
186 | 194 | | |
187 | 195 | | |
188 | 196 | | |
| |||
196 | 204 | | |
197 | 205 | | |
198 | 206 | | |
199 | | - | |
| 207 | + | |
200 | 208 | | |
201 | 209 | | |
202 | 210 | | |
203 | 211 | | |
204 | 212 | | |
205 | 213 | | |
206 | 214 | | |
| 215 | + | |
207 | 216 | | |
208 | 217 | | |
209 | 218 | | |
210 | 219 | | |
211 | 220 | | |
212 | 221 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 222 | + | |
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
| |||
233 | 235 | | |
234 | 236 | | |
235 | 237 | | |
| 238 | + | |
236 | 239 | | |
237 | 240 | | |
238 | 241 | | |
| |||
401 | 404 | | |
402 | 405 | | |
403 | 406 | | |
404 | | - | |
| 407 | + | |
405 | 408 | | |
406 | 409 | | |
407 | 410 | | |
408 | 411 | | |
409 | 412 | | |
| 413 | + | |
410 | 414 | | |
411 | 415 | | |
412 | 416 | | |
413 | 417 | | |
414 | | - | |
| 418 | + | |
| 419 | + | |
415 | 420 | | |
416 | 421 | | |
417 | 422 | | |
418 | 423 | | |
419 | 424 | | |
420 | 425 | | |
421 | 426 | | |
| 427 | + | |
422 | 428 | | |
423 | 429 | | |
424 | | - | |
| 430 | + | |
| 431 | + | |
425 | 432 | | |
426 | 433 | | |
427 | 434 | | |
| |||
431 | 438 | | |
432 | 439 | | |
433 | 440 | | |
| 441 | + | |
434 | 442 | | |
435 | 443 | | |
436 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | | - | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
211 | | - | |
| 213 | + | |
212 | 214 | | |
213 | 215 | | |
214 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
169 | | - | |
170 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
0 commit comments