Repository navigation
Commit 2052c89
fix(app-shell): an unset metadata-form switch shows its declared default (#38459)
Fixes #38420
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:管理员在 Studio
打开元数据表单(知识源、智能体、技能、应用、邮件模板、对象能力、仪表盘页眉等)时,未填写且默认开启的开关,编辑与只读两种模式下都显示为「开」,与实际运行一致。
- 为什么做:修复 Studio 知识源表单把默认开启的「可被 AI 智能体搜索」「随记录变更同步」显示成关闭、与帮助文字和实际行为相反的缺陷。
- 出错会怎样:只影响开关的显示,不写入任何值;未改动的条目保存后仍不存这个键,出问题时撤回本次改动即可恢复原显示。
- 要你做什么:无
## What changes
The metadata-form Switch in `SchemaForm` drew every unset boolean as
`!!value`, so a key whose served schema says `default: true` read OFF
while the runtime treats it as on. It now draws the value in effect: an
unset key (the shared `isUnsetFieldValue` definition) draws the schema's
declared `default`, a stored boolean draws itself. This is the flow node
inspector's existing "show, do not write" boolean rule applied to the
generic form: nothing is written until the author toggles, so an
untouched item still saves without the key and keeps following the
default (the ruling's display-only constraint).
The default is read off the served JSON Schema, which already carries
it: `aiExposed` and `refresh.onRecordChange` are
`z.boolean().default(true).optional()`, and `z.toJSONSchema` emits
`default: true` for both. The form declares no default of its own and
needs none, so `packages/spec` is untouched.
Every boolean row a registered metadata form declares whose derived
schema defaults to `true` shares this one Switch; the new test
enumerates them from `METADATA_FORM_REGISTRY` and the registered type
schemas rather than listing them. At the head of this PR the walk finds
rows on nine forms: knowledge source (`aiExposed`,
`refresh.onRecordChange`), skill, agent, app and email template
(`active`), object (`enable.searchable`, `enable.apiEnabled`,
`enable.feeds`, `enable.activities`, `enable.clone`), field
(`sortable`), report (`drilldown`, `dateRange.allowCustomRange`) and
dashboard (`header.showTitle`, `header.showDescription`,
`dateRange.allowCustomRange`). That list is a reading taken once; the
test is the instrument that re-derives it.
Read first, by risk:
1. `ui/packages/app-shell/src/views/metadata-admin/SchemaForm.tsx`, the
boolean branch of `FieldControl` (the `declaredDefault` line and the
`checked` expression): the only behaviour change.
2.
`ui/packages/app-shell/src/views/metadata-admin/SchemaForm.declaredBooleanDefault-38420.test.tsx`,
the `defaultTrueRows` walker: what "every default-true switch" means
here (top-level rows and `composite` sub-rows).
Two-minute check: `pnpm --dir ui exec vitest run
packages/app-shell/src/views/metadata-admin/SchemaForm.declaredBooleanDefault-38420.test.tsx`,
expect 6 passed.
## Tests
New `SchemaForm.declaredBooleanDefault-38420.test.tsx`, all against the
real spec (the served form and
`z.toJSONSchema(getMetadataTypeSchema(type))`, as the `/meta/types` row
carries them):
- knowledge-source form, edit and read-only: both unset switches report
`aria-checked="true"`;
- explicit `false` reports `"false"`, explicit `true` reports `"true"`;
- an untouched form calls `onChange` zero times; the first click writes
`aiExposed: false` and adds no `refresh` key;
- every enumerated default-true row renders ON when unset, with a floor
(`knowledge_source.aiExposed`,
`knowledge_source.refresh.onRecordChange`, `skill.active`) so the walk
cannot pass by finding nothing;
- CONTROL: a boolean with no declared default, unset, reports `"false"`.
Ablation (fix reverted on disk by `scripts/ablation-replace.mjs`,
`checked={!!value}`; app-shell is a vitest source alias, so no build
sits between): 4 failed, 2 passed, exactly the four unset cases red and
the explicit-value and control cases green; restore verified blob equal
to HEAD and `git diff HEAD` empty.
<details><summary>Readings</summary>
- Final head 03896dd, the new file plus the neighbouring suites
(`SchemaForm.optionalEnumUnset-29733`,
`SchemaForm.requiredMarker-10367`, `SchemaForm.widgetLabelling`,
`ResourceEditPage.formBoundObject-37309`): `Test Files 5 passed (5)`,
`Tests 104 passed (104)`.
- Ablated: `Tests 4 failed | 2 passed (6)`; `ablation-replace: ok
restored: blob == HEAD (3095ad6) and git diff HEAD is empty`.
- `pnpm --dir ui exec vitest run scripts/` (derived family): `Test Files
1 failed | 171 passed | 2 skipped (174)`; the one failure was
`js-comment-mask-returns-interpolation-9424.test.ts` timing out at
15000ms on a contended box (unrelated to this diff); rerun alone: `Tests
8 passed (8)`.
</details>
## Acceptance notes
- Local `type-check` of `@object-ui/app-shell` was not measured: it
needs every `@object-ui/*` dist built (the run reported `Cannot find
module '@object-ui/components'` and its siblings before reaching any
check of this diff). NOT MEASURED locally, reason: closure not built;
`Type Check UI` in CI carries it. The change types against `JsonSchema`,
which that file declares as a string-keyed record of any value.
- Not verified in a running Studio; the component test drives the real
served form and derived schema through `SchemaForm`.
- The walker covers top-level rows and `composite` sub-rows. Boolean
columns inside repeaters (an object's `fields` rows, for one) render
through the same `FieldControl` Switch, so they take the fix, but the
pin does not enumerate them.
- `dynamic-config`'s schema-driven boolean (`DynamicConfigWidget` in
`widgets.tsx`) has the same `Boolean(cur)` shape, but nothing in the
tree populates `WidgetContext.dynamicSchemas`, so it has no reachable
default-true input today. Noted, not changed.
- The dispatch's file surface named `ui/.changeset/*.md`; `ui/AGENTS.md`
says new changesets go to the root `.changeset/` and none are added
under `ui/.changeset/`, so the changeset is
`.changeset/38420-unset-switch-shows-default.md`.
## Verification
Local derived gate list (`node scripts/pm/dispatch-gates.mjs --commands
--repo objectstack-ai/objectstack`): 38 families, run at 862c74b, all
exit 0 except two. `check:test-source-alias` was red on the new test (it
reached `@objectstack/lint` and `@object-ui/plugin-detail` through
dynamic imports with no module-top import); 03896dd adds the two
imports, and the gate is green there. `vitest run scripts/` had one
timeout, which passed when rerun alone. On 03896dd, the families that
read the changed test file were rerun, all exit 0:
`check:test-source-alias`, `check:undeclared-dep-imports`,
`check:cross-package-test-inputs`, `check:nul-bytes`,
`check:gitlink-declared`, and ui `check:new-line-citations` (0 new
citations). `--ran` reconciliation: `38 derived famil(ies) accounted for
— 38 run, 0 NOT-MEASURED (a DERIVED zero)`. Every family CI runs is read
from this PR's check-runs.
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4d13AraSmVmgVtCvkWk)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f459c86 commit 2052c89
3 files changed
Lines changed: 205 additions & 1 deletion
File tree
- .changeset
- ui/packages/app-shell/src/views/metadata-admin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 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 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2612 | 2612 | | |
2613 | 2613 | | |
2614 | 2614 | | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
2615 | 2621 | | |
| 2622 | + | |
2616 | 2623 | | |
2617 | 2624 | | |
2618 | 2625 | | |
2619 | 2626 | | |
2620 | 2627 | | |
2621 | | - | |
| 2628 | + | |
2622 | 2629 | | |
2623 | 2630 | | |
2624 | 2631 | | |
| |||
0 commit comments