Repository navigation
Commit e68d23b
feat(console): the console reads and edits forms as form items (#38484)
Part of #37087
Clause-②: yes
Metadata-protocol: none
Skills-docs: none — no metadata an author writes changes; the console
reads and writes the `form` type card ② added.
## 维护者速读
- 用户能看到什么变化:Setup 的公开表单页看起来不变,只是改读改写表单类型;在 Studio 里打开一个表单(地址
`…/metadata/form/表单名`)就是表单设计器,能改字段、必填、分组、标题、地址和提交后的提示,存草稿再发布;控制台自己的表单页改读表单类型。表单类型暂不进
Studio 菜单(下一张 PR)。
- 为什么做:ADR-0159 把表单独立成 `form` 元数据,控制台要改读改写它,后面才能退役开发者页的公开表单页。
- 出错会怎样:最坏是某个表单在 Setup 里开关失败、或在 Studio
里存不上;设计器没有开关,保存和发布都按当时存着的开关写回,所以不会把 Setup 关掉的表单重新打开;匿名打开和提交不经这张 PR
的代码;可整体撤回。
- 要你做什么:契约审核(L2)未完成,先不用批;审核通过后席位会附审核记录请你批。
## What changes
ADR-0159 D9 for the console, card ③ PR 1 of 2 (the seat's claim
7248756424, amendment 7248849494). Every console surface here reads and
writes the `form` type; the server's projection (ADR-0159 D5, completed
by #38453) serves an old-shape form there too.
1. **Setup → Configuration → Public forms**
(`ui/packages/app-shell/src/views/setup/`): the list read is `GET
/meta/form`; the row reader takes the `form` item itself (no `viewKind`
filter, no `config` hop). The two layered reads, the save paths, the
reset and the override save name `form`. A switch saves
`authorableForm(effective)` with `sharing.enabled` set: the read's `_`
keys and the old shape's `data` are left out, since `FormSchema` refuses
`data`. The shipped-off judgement reads the app's own document from the
`form` layered read's `code` with the spec's `formExplicitlyWithdraws`
(ADR-0159 D6 rule 6). A row whose app document cannot be read (`code:
null`) is shown as status unknown and offers no switch.
2. **The #36784 designer becomes the `form` editor**
(`studio-design/publicForm/`): `publicFormDesign.ts` reads and writes
the top-level body. `PublicFormsDesigner.tsx` now holds
`FormItemEditor`, which edits one form, and `FormItemPage`, registered
as the `form` type's `EditPage` and `CreatePage`. It has no switch:
`storedNow` reads `sharing.enabled` and `sharing.allowAnonymous` again
at every save and publish, and a draft whose sharing differs is saved
again before it is published. A form an installed app ships is saved as
a declared override in the app's `.custom` pair. A form with no public
link (one an action opens) is edited without an address. The new-name
and address checks read the effective `form` list plus `form` drafts.
The designer's own list and the Form-tab switch from #36784 are not
carried over.
3. **List columns and registration** (`formListColumns.tsx`; the `form`
resource is registered in `services/builtinComponents.tsx` beside the
other lazy editor pages, so `metadata-admin/registry.ts` stays free of
side effects): name (shows `title` when there is no `label`), label,
object, public address and status. `/meta/types` serves no list layout
for `form`, so these are the client's own `listColumns`. `form` stays
out of Studio's menu.
4. **`FormPage`** (`ui/apps/console/src/components/FormPage.tsx`): the
internal route reads `GET /api/v1/meta/form/NAME`. The anonymous route
is unchanged.
5. **Strings**: new `engine.studio.publicForms.*` and
`engine.list.col.publicAddress` / `publicState` keys in
`./namespaces/studio` (en, zh). This PR removes no key.
Outside the claimed file surface (reported to the seat):
-
`ui/packages/app-shell/src/views/studio-design/StudioMetadataArea.tsx`:
one branch, so that a `form` item in a package's Studio area opens
`FormItemPage` with the area's `customization`, `publishNonce` and
`onDraftSaved`. Only the area's surface holds a read-only base's
customization. Without it, an installed app's form could not be saved as
its override.
- `ui/packages/app-shell/src/services/builtinComponents.tsx`: the `form`
resource's registration (`listColumns`, lazy `EditPage` / `CreatePage`).
The claim named `metadata-admin/registry.ts`, but a registration there
makes that module side-effectful and `check-side-effects-array` refuses
it; every other editor page registers here.
- `ui/packages/app-shell/src/views/runtime-metadata-persistence.ts`:
`RuntimeArtifactType` gains `'form'`, and a `form` save invalidates the
view caches the way a `view` save does, because Setup's switch goes
through `saveAndPublishInPackage('form', …)`.
Read first (by risk):
1. `studio-design/publicForm/PublicFormsDesigner.tsx`, `storedNow`,
`save` and `publish`: the no-switch rule.
2. `setup/publicForms.ts`, `switchPublicForm` / `authorableForm` /
`markShippedOff`: the body a switch writes over an old-shape form.
3. `studio-design/publicForm/publicFormDesign.ts`, `publicFormItemOf`:
what is kept, and what is dropped (`data`, `viewKind`, `config`, `_`
keys).
## Tests
- `publicFormDesign.test.ts` (29): the top-level body both ways; a new
form passes `FormSchema.safeParse`; an old-shape projected item is
written back without `data` or `_formDefinedIn`; sharing is written as
read (off stays off, an unchanged address keeps the stored `publicLink`,
a changed one becomes `/forms/SLUG`); a form with no public link;
`isPublicFormItem`.
- `PublicFormsDesigner.test.tsx` (14, the #36784 tests re-pointed to the
`form` shape): create, taken address and name, delete, the no-switch
rule at save and at publish, the publish re-save of a draft whose
sharing differs, reads that fail, a form with no public link, an
old-shape save without `data`. Every write is asserted as type `form`
with a body `FormSchema` accepts.
- `setup/publicForms.test.ts`, `PublicFormsSetupPage.test.tsx`: the list
read and both layered reads are `form`; the shipped-off judgement from
the `form` layered `code`; a row whose app document cannot be read is
status unknown with no switch; a switch over an old-shape row writes no
`data`.
- `FormPage.*` (about 30 files): the internal route reads
`/meta/form/NAME`; the fixtures moved to the top-level body.
- `PublicFormsDesigner.test.tsx` (+2, head `48a01c7ff7`, L2 S2): "shows
the server's address refusal its own check missed (409
FORM_ADDRESS_TAKEN) as the address clash, at save and at publish" and
"CONTROL: shows any other 409 as a pending draft". Ablation (the
`FORM_ADDRESS_TAKEN` branch deleted): 1 failed, 15 passed, the failure
is the address case (received the pending-draft sentence), the CONTROL
stayed green; restored to the HEAD blob.
- `FormPage.recordObject.test.tsx` (+1, L2 S3): "Log Time on a task:
/meta/form/NAME is read, the form renders the record, and the submit
writes it". The real `ActionRunner` runs `{type:'form',
target:'showcase_task.edit'}` with record 42; FormPage reads exactly one
`/api/v1/meta/form/showcase_task.edit` and no `/meta/view`, renders the
record and PATCHes `/data/showcase_task/42`.
## Acceptance notes
- Setup's address-clash refusal (`409 FORM_ADDRESS_TAKEN`) still shows
one sentence that does not name the form holding the address: naming it
needs a new key in all 11 locale files, outside this surface. Carrier:
PR 2 of #37087, under claim amendment 7251711074 (card item 1, "shows
the refusal with both names"; L2 S1, L1 R2).
- A form an action opens: checked live on head `48a01c7ff7` and pinned
by a test (see Verification, L2 S3).
- This PR removes no translation key, so the removed-key probe is owed
by PR 2.
## Remaining `formViews` / `viewKind: 'form'` hits under `ui/`
Docblocks only in `FormPage.tsx`, `recordFormNavigation.ts`,
`SchemaForm.tsx`, `clientValidation.ts`, `registry.ts`,
`view-item-normalize.ts`, `freeze-schema.ts` and `imported-defaults.ts`;
the view editor's own form arm (`anchors.ts`, `ViewPreview.tsx`,
`view-item-normalize.ts`), which still edits a `view`;
`MetadataProvider.tsx`, kept on purpose for packages that still ship
forms in `views:`; and the developer `PublicFormsPage`, which PR 2
retires.
## Verification
- Tests on head 83c51d8: app-shell `ConditionWidget.conditionScope`,
`studio-design/publicForm`, `StudioMetadataArea.*`, `views/setup` and
`runtime-metadata-persistence.*`: 35 files, 458 passed. An earlier run
of all of `views/metadata-admin`, `views/studio-design` and
`views/setup` was red only on the conditionScope exhaustiveness check,
while `form` was registered in `registry.ts`; moving the registration
fixed it (the targeted run above). Also `packages/i18n` plus the
console's `src/components` and the two form-page tests in
`src/__tests__`: 173 files, 2618 passed, 13 skipped.
- Type checks: `@object-ui/console` `type-check` exit 0 (after building
its dependencies).
- Gates: `dispatch-gates --commands` derived 28 families, each run and
recorded; `--ran` reconciles 28 derived, 28 run, 0 NOT-MEASURED. `pnpm
--dir ui exec vitest run scripts/` was killed by memory (SIGKILL, exit
1) while a build ran beside it; run again alone it exits 0, recorded as
an extra line.
- Dogfood (`examples/app-showcase`, `objectstack dev`, console dev
server, signed in as the seeded admin):
- Setup lists both showcase forms as `form` items, both on. Switching
Contact off makes `GET /forms/contact-us` and its submit answer 404;
switching it on again answers 200.
- Studio opens the old-shape `showcase_inquiry.contact` at
`/studio/com.example.showcase/metadata/form/showcase_inquiry.contact`.
Removing `message` is refused (the object requires it). Adding `source`
as required, removing `company` and retitling, then save and publish:
the anonymous form serves the new title and fields, a submit without
`source` answers `400 VALIDATION_FAILED`, with it `201`.
- Off in Setup, then edited and published in Studio: the form stays off
(404) and Setup still shows it off. Switched on again, it serves the
newest title.
- New form: the title Contact us is refused because its address is taken
(confirm disabled); Demo signup is created in the app's `.custom` pair,
published, and opens and accepts a submit (`201`).
- Studio's `form` list shows the label/title, name, object, address and
status columns.
- Screenshots: `/mnt/project-files/card-37087/pr1-dogfood/` (seat 3's
project files).
- Patch round, head `48a01c7ff7` (L2 S2 and S3; the designer's 409
mapping, two tests, one changeset sentence):
`PublicFormsDesigner.test.tsx`, `publicFormDesign.test.ts` and
`FormPage.recordObject.test.tsx` 3 files, 55 passed;
`@object-ui/app-shell` and `@object-ui/console` `type-check` exit 0;
`pnpm --dir ui exec vitest run scripts/` 172 passed, 2 skipped. The
server's refusal (`formAddressClashRefusal`,
`packages/metadata-protocol/src/protocol-form-writes.ts`) carries status
409 and code `FORM_ADDRESS_TAKEN` and names the holder only in its
prose, so the editor maps the code to the shipped `addressTaken` key (no
structured holder for `addressTakenBy`; no key added).
- Live check of a form an action opens (head `48a01c7ff7`,
`examples/app-showcase`): on task "Build homepage", the header action
Log Time (`showcase_log_time`, type `form`, target `showcase_task.form`)
navigates to
`/apps/com.example.showcase/forms/showcase_task.form?recordId=…&recordObject=showcase_task`;
`GET /api/v1/meta/form/showcase_task.form` answers 200 and no
`/meta/view/NAME` is read; the form renders prefilled; Submit sends
`PATCH /api/v1/data/showcase_task/…` 200 and the record reads the new
title. Screenshots and the network log:
`/mnt/project-files/card-37087/pr1-dogfood/s3-*.png`, `s3-network.json`;
the live 409 envelope: `s2-envelope-probe.txt` (project files of the
seat 5 project).
- Dogfood battery (`pnpm --filter @objectstack/dogfood test` under
os-verify-lock, closure built as CI does, no shard, no path): head
`d5581291b6` · VERDICT exit 0 · Test Files 495 passed, 3 skipped (498) ·
Tests 4183 passed, 68 skipped (4251) · failures: none. The head moved
since by the patch round's four `ui/` files and the changeset only; none
is in the dogfood closure.
## Ablation of the no-switch rule (L1-b R1, card Done-when "ablate:
build the designer's save from the base's body")
Measured at head `d5581291b6`, in a throwaway detached worktree, through
`scripts/ablation-replace.mjs` (HEAD-blob restore with hash check), from
the `ui/` root under os-verify-lock: `pnpm exec vitest run
--maxWorkers=2 --reporter=verbose
packages/app-shell/src/views/studio-design/publicForm/PublicFormsDesigner.test.tsx
packages/app-shell/src/views/studio-design/publicForm/publicFormDesign.test.ts`.
- Ablation (one line, `PublicFormsDesigner.tsx`, the single point where
both `save` and `publish` read the sharing through `storedNow`): the
sharing is taken from the body as it was opened, `form.base.sharing`,
before the effective, draft and code layers.
- Baseline: 2 files passed, 43/43 tests (14 + 29).
- Ablated: 2 failed, 41 passed. Red:
- "has no switch: saves and publishes the form's sharing as it is stored
at that time, not as it was when the form was opened"
(`PublicFormsDesigner.test.tsx:376`, `expected true to be false` on
`sharing.enabled`; the save leg);
- "publishes an installed app's form with the switch as stored at the
app, after it was switched off" (`PublicFormsDesigner.test.tsx:425`, the
publish-time re-save carrying the switched-off sharing never happened;
the publish leg).
- `publicFormDesign.test.ts` stayed 29/29, as expected
(`publicFormItemOf` writes whatever sharing it is handed).
- Restored: blob `0e7cb3887b` equals HEAD, `git diff HEAD` empty, 43/43
green again.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L9qibxQiu6MyZ2ngLJtA5Y
<!-- signed: repo:objectstack#5 · os-project-manager ·
session_01FEkQ5nBh856nLqWBYMy29u -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9e5be7b commit e68d23b
51 files changed
Lines changed: 3100 additions & 461 deletions
File tree
- .changeset
- ui
- apps/console/src
- __tests__
- components
- packages
- app-shell/src
- services
- views
- setup
- studio-design
- publicForm
- i18n/src/namespaces/studio
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
66 | 65 | | |
67 | | - | |
| 66 | + | |
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
| |||
89 | 88 | | |
90 | 89 | | |
91 | 90 | | |
92 | | - | |
| 91 | + | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
150 | 149 | | |
151 | | - | |
| 150 | + | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
| |||
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
166 | | - | |
| 165 | + | |
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
| 79 | + | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | 84 | | |
86 | | - | |
| 85 | + | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
| |||
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
137 | | - | |
| 136 | + | |
138 | 137 | | |
139 | 138 | | |
140 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | 59 | | |
61 | | - | |
| 60 | + | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | | - | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | | - | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
| |||
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | | - | |
| 74 | + | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
51 | | - | |
| 49 | + | |
| 50 | + | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
| 54 | + | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
43 | 38 | | |
44 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
| |||
65 | 63 | | |
66 | 64 | | |
67 | 65 | | |
68 | | - | |
| 66 | + | |
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
| |||
127 | 125 | | |
128 | 126 | | |
129 | 127 | | |
130 | | - | |
| 128 | + | |
131 | 129 | | |
132 | 130 | | |
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
136 | 134 | | |
137 | | - | |
| 135 | + | |
138 | 136 | | |
139 | 137 | | |
140 | 138 | | |
| |||
191 | 189 | | |
192 | 190 | | |
193 | 191 | | |
194 | | - | |
| 192 | + | |
195 | 193 | | |
196 | 194 | | |
197 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | 104 | | |
106 | | - | |
| 105 | + | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
| |||
136 | 135 | | |
137 | 136 | | |
138 | 137 | | |
139 | | - | |
| 138 | + | |
140 | 139 | | |
141 | 140 | | |
142 | 141 | | |
| |||
0 commit comments