You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 93d8921
Browse filesBrowse the repository at this point in the historyBrowse files
fix(app-shell): a menu reordered in design mode is saved in the order the sidebar draws it (#36622)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi92ncfFpPUpTD8314otX5oaG)_Fixes#36591
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
管理员在运行界面的设计模式里调整菜单顺序(上移、下移、移到分组、在前后加一项、添加菜单项、拖动)并保存后,侧栏现在按设计模式里显示的顺序排列;以前在
AI 搭建、菜单项带排序号的应用里,保存成功却毫无变化,再进设计模式看到的顺序也和侧栏相反。
- 属于「运行界面的设计模式」专题,替用 AI 搭建应用、要在应用里直接调菜单的管理员解决「改了不生效、也不报错」的问题。
-
出错时,带排序号的应用保存菜单后侧栏顺序会和设计模式不一致;只影响菜单顺序,不丢菜单项,可以在设计模式里再调一次保存,或撤回本次合并恢复旧行为。
- 无。
## What changes
The sidebar sorts each level of an app's `navigation` by `order`
(`byNavOrder` in `@object-ui/layout`: lower first, an absent `order` as
0, ties in array order). Design mode listed and saved the array as
authored, so in an app whose entries carry `order` a move was saved and
published and changed nothing on screen.
Route taken (the claim's Route, the card's first option): **rewrite
`order` on save, never drop it.**
- **Display** — design mode seeds its menu with every level put in the
sidebar's order (`inShownOrder` in `designModeMenuModel.ts`, which sorts
each level through `inMenuOrder`, the app-shell statement of the
sidebar's rule; no new comparator). The menu reads the same in and out
of the mode.
- **Save** — `saveAppMenu` puts the stored menu in that same shown order
before the edits are replayed on it (`rebaseMenuEdits`), then rewrites
`order` on the result (`withOrderRewritten`): each level in which
**any** entry carries `order` has **every** entry numbered `0, 1, …` in
the order design mode showed; group entries and each group's children
are numbered per level. A level where no entry carries `order` is saved
by array order and gains no key (HotCRM-shaped apps are unchanged).
- **Why `0..n-1`**: it is the smallest rule that makes `byNavOrder` draw
exactly the array order (no ties are possible inside a renumbered
level), it covers the mixed level the card names, and it is idempotent:
a second save of the same menu writes the same numbers. Dropping `order`
was rejected because it deletes authored keys from AI-built apps.
- **Why the stored menu is sorted first**: the edits are replayed by
place ("after the entry before it"), and the stored array of an
`order`-carrying app is not in shown order. Without the sort an entry
added at the end of `[X(2), Y(1), Z(0)]` lands after `X` in the array
and is numbered between `X` and `Y`. A stored entry the reader was never
shown (pruned) keeps its shown place among the rest.
- `rebaseMenuEdits` and `order`: the editor never writes `order`, so the
served and edited copies of an entry always agree on it and it is never
a patch key; the stored value travels with the entry and is then
rewritten. Nothing is treated as a conflict and nothing is dropped.
Pinned by "a move up is written as `order`; a rename beside it writes
its label, and `order` is never read as an edit".
### Why #36363's tests did not catch it
Every fixture in the three #36363 test files authored its menu **without
`order`** (HotCRM-shaped), where array order is the sidebar order. The
save pins read the written navigation's **array positions**
(`navigation[1].children.map((c) => c.id)`), and nothing drew the saved
menu through the sidebar's renderer. Its acceptance line
"上移并保存:顺序变了;刷新后还在" was therefore true of every fixture and false of the
AI-built app the coordinator saved. The new pins draw what the save
wrote through the real `NavigationRenderer` and compare it with what
design mode showed, over menus that carry `order`.
## Tests
Read first (by risk):
1. `ui/packages/app-shell/src/layout/designModeMenuSave.ts` — the two
lines around `rebaseMenuEdits`: the sort before the replay and the
rewrite after the payload.
2. `ui/packages/app-shell/src/layout/designModeMenuModel.ts` —
`inShownOrder` and `withOrderRewritten`.
3. `ui/packages/app-shell/src/layout/DesignModeMenu.tsx` — the `served`
seed.
New pins, each a top-level `describe` in the existing shared harness of
its subject (no new test files):
- `DesignModeMenu-36363.test.tsx` · "the design-mode menu in the sidebar
order (objectstack#36591)" — real `DesignModeMenu` + mode save, the
sidebar read from a rendered `NavigationRenderer` (no sort written in
the test): ordered app reads the same in design mode and in the sidebar;
Move up on Contacts then Save → sidebar reads Contacts, Customers, …,
and the saved app re-opens design mode in that order; Add an item after
+ Move to group → the sidebar places both where design mode showed them;
CONTROL: an app with no `order` saves a move by array order and gains no
`order` key; a mixed level reads as design mode after one save.
- `designModeMenuSave-36363.test.ts` · "the save writes the order the
editor showed as `order` (objectstack#36591)" — added at the end, move
up with a rename beside it, a pruned entry, and the no-`order` control.
- `designModeMenuModel-36363.test.ts` · "a level in the sidebar order,
and that order written back as `order` (objectstack#36591)".
<details><summary>Runs (head f4425f4)</summary>
- `pnpm --dir ui exec vitest run --maxWorkers=2
packages/app-shell/src/layout/` → `Test Files 155 passed (155)`, `Tests
1247 passed (1247)`; lock `VERDICT command-exit 0`.
- The three touched files alone → `Test Files 3 passed (3)`, `Tests 75
passed (75)`.
- `pnpm --filter @object-ui/app-shell type-check` (both `tsconfig.json`
and `tsconfig.test.json`) → lock `VERDICT command-exit 0`, after
rebuilding the dependency closure the `origin/main` merge moved (a first
run against the pre-merge `dist` reported `RecordDetailView.tsx` TS2322
from main's merged change; gone after the rebuild).
</details>
<details><summary>Ablation — the order rewrite removed</summary>
`node scripts/ablation-replace.mjs --file
ui/packages/app-shell/src/layout/designModeMenuSave.ts --anchor 'const
nextNav = withOrderRewritten(navPayloadOf(rebased as unknown[]) as
Menu);' --replacement 'const nextNav = navPayloadOf(rebased as
unknown[]) as Menu; void withOrderRewritten;'` over the three files:
- `ok mutation landed: anchor 1 -> 0, blob b319aa8 -> fd40d9929ee0`
- `Test Files 2 failed | 1 passed (3)`, `Tests 6 failed | 69 passed
(75)` — red: the three `order` save pins, and in the render harness Move
up, Add after + Move to group, and the mixed level. The two CONTROL pins
(no `order`) and the display pin stay green, as they should.
- `ok restored: blob == HEAD (b319aa8) and git diff HEAD is empty`.
</details>
## Acceptance notes
- **Renumbering rewrites authored values.** Saving a menu whose level
carries `order` writes consecutive numbers on every entry of that level
(an authored `10, 20, 30` becomes `0, 1, 2`), even when the save only
renamed an entry. The order drawn is unchanged; the values are not
preserved.
- **Another package's entries (`navigationContributions`) keep their own
`order`.** They are not in the stored menu, so they are not renumbered.
One that carries no `order` keeps its place (it sorts as 0 right after
the app's first entry, as design mode now shows it); one that carries
its own `order` can sit in a different place relative to the renumbered
entries than design mode showed. No live app was found with such a
contribution; noted, not filed.
- **Two save rules for one key.** Studio's nav canvas (`AppNavCanvas`
`moveItem`) writes `order` on the moved entry only; design mode now
renumbers the level. Both draw the order their editor showed; they
differ in how many keys a save writes. Observation only.
- **Browser check: NOT MEASURED**, reason: the worktree has no built
runtime or Console (`packages/console/dist` absent), and a full build
plus a seeded backend on this shared 4-core box was not taken on for
this card; the sidebar half is measured instead by rendering the real
`NavigationRenderer` over the written navigation.
- **Overlap**: `node scripts/pm/overlap-check.mjs` exits 1 against
#36606 (shares `DesignModeMenu.tsx`, `designModeMenuSave.ts`, conflicts
in `DesignModeMenu-36363.test.tsx`); the seat sequenced this card first
and #36606 rebases on it.
## Verification
Two minutes: `pnpm --dir ui exec vitest run
packages/app-shell/src/layout/__tests__/DesignModeMenu-36363.test.tsx -t
"sidebar order"` — expect 5 passed, among them "「Move up」 on Contacts,
saved: the sidebar reads Contacts, Customers, …".
Local gates: `node scripts/pm/dispatch-gates.mjs --commands` derived 38
commands for this diff; all 38 ran with exit 0 and `--ran` reconciles
"38 run, 0 NOT-MEASURED". The `ui/scripts` vitest family was run with
`--maxWorkers=2` added (dispatch order). Families CI runs are read from
this PR's check-runs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm
<!-- signed: repo:objectstack#2 · os-steve ·
session_01ADHkmRB34k9WUWeGpRnVNm -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
fix(app-shell): a menu reordered in design mode is saved in the order the sidebar draws it, in apps whose menu entries carry `order`
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
The sidebar sorts each level of an app's `navigation` by `order` (lower first, an absent `order` as 0, ties in array order), but design mode listed and saved the array as authored. In an app whose entries carry `order` — AI-built apps write one on every entry — 「Move up」, 「Move down」, 「Move to group」, a drag and an added item were saved and published without error and changed nothing on screen; re-entering design mode then listed the menu in an order the sidebar did not show.
11
+
12
+
Design mode now lists each level in the sidebar's order, and the save writes that order back: every level in which any entry carries `order` has each of its entries, groups and group children alike, renumbered `0`, `1`, … in the order design mode showed. A level in which no entry carries `order` is saved by array order as before and gains no `order` key, so apps authored by array order (HotCRM's) are unchanged. Saving a menu with `order` therefore rewrites its `order` values to consecutive numbers; the order they draw is the one design mode showed.
0 commit comments