Skip to content

Commit ab91323

Browse files
feat(studio): a dashboard list's New opens the app's design mode on its dashboards (#37368)
Fixes #36907 Clause-②: no Metadata-protocol: none ## 维护者速读 - 管理员在 Studio 的仪表盘列表点「新建」,会直接打开对应应用,「设计布局」已开、「添加菜单项」停在仪表盘一栏;建好的仪表盘挂在菜单上并进入编辑,点 × 回到 Studio 列表;手机宽度不出现「新建」,包里没有可打开的应用时也不出现,并写明原因。 - 属于「Studio 重构」专题,落实你定的「新建跳到设计模式加菜单」,让新仪表盘不会游离在所有菜单之外。 - 出错时管理员在 Studio 里可能新建不了仪表盘,或进不了设计模式;已有仪表盘、报表和菜单不受影响,纯前端改动,可直接撤回。 - 无 ## What changes The Studio dashboard list's New now uses design mode's existing 「Add menu item → New dashboard…」 flow (#36364), the maintainer's 「新建跳到设计模式加菜单」 (dashboard half). The report half (decision 13) is unchanged. **The arrival (`layout/designModeArrival.ts`, `layout/useDesignModeArrival.ts`).** A second navigation-state arrival, `designModeAddDashboard`, sits beside `designModeNewDashboard` and carries the Studio list it came from. `ConsoleLayout` reads it once per history entry through `useDesignModeArrival`. It first replaces the entry without the arrival, so a reload or Back enters nothing. Then it asks the mode to `enterOpening({ column: 'dashboard', studioReturn })`. - ⛔ No URL enters design mode. The arrival rides navigation state only; the landing address carries no `?studio=` and no mode. - `enterOpening` is `enter` plus a one-shot "opening" held in the mode store. Where `enter` refuses (an editor holds the mode out, PR #36848), nothing is held and the mode's own `designMode.editorOpen` toast says why. On a phone the arrival is cleared and nothing more happens. - The held-out count moved from state to a ref. An editor that opens in the same commit the arrival lands in is then still judged (pinned; ablation A5c below). `enter()` keeps its zero-argument contract: a click event is never an opening. **`DesignModeMenu`** takes the opening once (`useDesignModeOpening`). It opens the picker on 「Dashboards」 for an entry at the end of the top level, as that level's 「Add menu item」 would. A dashboard created from that picker navigates with `withStudioReturn(href, studioReturn)`, so the dashboard page's existing × goes back to the Studio list (`?studio=`). Closing that picker drops the return, and later adds are plain. **Studio (`StudioAreaAppOpen.tsx`, `studioAppEdit.ts`, `StudioMetadataArea.tsx`).** `StudioAreaAppTarget` gains `{ kind: 'new-dashboard' }`. `AreaCreate` sends `dashboard/new` through it, under the same condition the report leg uses (`!readOnly || pairCreate`). It replaces the Studio address with `/apps/SEGMENT` (`appHomePath`) and the arrival. - The app comes from decision 6 via `studioAppCreateSegment`. - The `.custom` pair leg from #37348 applies: a pair with no app of its own reads its base's apps. That reading is factored into `readStudioTargetApps`, which the item leg now shares too. - With no app, or on a phone, the fallback is the area's own create, as for a report. **The list (`ResourceListPage.tsx`).** `useStudioDashboardNew` gates the area's dashboard 新建 by the same reads. It never shows at phone width, and it is not drawn while the apps are being read. With no target app the header shows no 新建 and shows a `role="note"` reason instead (`engine.list.dashboardNewNoApp`); the empty state says the same. **Riders from seat 4's L1 on PR #37348.** - N1: the `StudioAreaAppOpen-36906` test header now says a pair row opens in the base's app. - N2: this changeset carries a note on the #37237 entry: rule 1's menu leg (the remembered app counts when its menu opens the item) applies on the pair leg too. Additive en and zh keys: `engine.list.dashboardNewNoApp` and `engine.list.dashboardNewWiderScreen` (the phone empty state, from the L1 S1 round) in the `studio` namespace (it is en/zh only). No server, spec or route change. ## Read first 1. `ui/packages/app-shell/src/layout/useDesignModeArrival.ts`: the consume-then-enter order. Risk: it navigates (replace) in the same commit `AppRootLanding`'s redirect may navigate. Child effects run first, so the landing redirect re-applies on the next render; see Acceptance notes. 2. `ui/packages/app-shell/src/layout/designMode.tsx`: `enterWith` / `enterOpening` / `takeOpening`, and `heldOut` moving to a ref. 3. `ui/packages/app-shell/src/views/studio-design/StudioAreaAppOpen.tsx`: the `new-dashboard` leg and `useStudioDashboardNew`. ## Tests Pins, each with an ablation that turned it red (and restored hash-verified through `scripts/ablation-replace.mjs`). Every file below imports the subject from source, so no build or dist preflight applies: | Pin | File (new top-level describe) | Ablation → red | |:--|:--|:--| | Studio 新建 lands in the target app, design mode open, dashboard column open | `StudioAreaAppOpen-36906` (`dashboard list's New…`), `DesignModeMenu-36363` (`the arrival…`) | A6 `AreaCreate` dashboard branch off → 5 red; A1 `enterOpening` call removed → 6 red; A2 picker kind `null` → 2 red | | A created dashboard is in the menu and opens for editing, × back to the list | `DesignModeMenu-36363` | A3 `withStudioReturn` dropped → 1 red | | CONTROL: the report 新建 is unchanged | existing 36906 report-New tests and pair report-New control; list control `CONTROL — the report list` | (control: green under every ablation) | | No 新建 at phone width | `ResourceListPage.pairCreate-36897` (`dashboard list's 「新建」…`) | A8 phone read as false → 1 red | | No 新建 without a target app, reason shown | same | A9 gate ignores `no-app` → 3 red; A10 reason not drawn → 2 red | | A refused `enter()` does nothing | `DesignModeMenu-36363` | A5 hold ignored → 2 red; A5c render-time snapshot of the hold → the same-commit pin red, the prior-editor pin green | | The pair leg | `StudioAreaAppOpen-36906`, `ResourceListPage.pairCreate-36897` | A7 pair leg off (Studio) → 2 red; A7b (list) → 1 red | | The arrival is consumed (reload / Back enter nothing) | `DesignModeMenu-36363` | A4 replace removed → 4 red | Moved by this change, and re-pinned rather than deleted: - 36906's "a dashboard New is not this card" half is now the new describe. - 36906's "a dashboard made by the area's create … Back lands on the list" runs at phone width, the one place the area's own dashboard create is still reached from a list. <details><summary>Local runs on the final head 6fbbdd9 (rebased on d5ae7a4)</summary> - `cd ui && npx vitest run --maxWorkers=2` over the 4 pinned files (`DesignModeMenu-36363`, `designMode-36362`, `StudioAreaAppOpen-36906`, `ResourceListPage.pairCreate-36897`) gave `Test Files 4 passed (4) · Tests 114 passed (114)` before the L1 S1 round. At the final head `cc7bb340`, with the S1 and N2 pins added, the seat's L1 run over the same files gives 119/119 passed. - `pnpm --filter @object-ui/app-shell type-check` (both `tsconfig.json` and `tsconfig.test.json`) gives lock `VERDICT command-exit 0`. - The 156 app-shell/i18n test files that name a touched surface (ResourceListPage, designMode, DesignModeMenu, StudioAreaAppOpen, StudioMetadataArea, ConsoleLayout, studioAppEdit) were run on the pre-rebase head `b0fc2e64`, giving `Test Files 156 passed (156) · Tests 1743 passed (1743)`. The rebase brought in one commit, #37347, which touches none of this PR's files. The full app-shell suite (2,431 files) is left to CI's `Test UI` (a declared narrowing). - Gates derived by `node scripts/pm/dispatch-gates.mjs --commands`: all 38 commands exit 0, run on `b0fc2e64`. - Pre-push gates on `6fbbdd9b`: `pnpm check:test-source-alias` exit 0, `pnpm --dir ui check:i18n-keys` exit 0, `node scripts/pm/overlap-check.mjs` gives `VERDICT clean exit 0`. It reports one open PR, #37362, that shares the studio en/zh namespace files and merges cleanly. - In-flight branches, by `git merge-tree`: - `claude/issue-37139-studio-package-menu` merges clean. - `claude/issue-36909-studio-pillar-dead-code` merges clean. It shares `StudioMetadataArea.tsx` with this PR, in different hunks. </details> <details><summary>Ablations (each through scripts/ablation-replace.mjs, restored, git diff HEAD empty)</summary> - A1: drop the `enterOpening` call in `useDesignModeArrival` → `DesignModeMenu-36363`: 6 failed | 50 passed. - A2: `setPickerKind(null)` → 2 failed. - A3: navigate without `withStudioReturn` → 1 failed. - A4: drop the consuming `navigate(..., { replace: true })` → 4 failed. - A5: `if (false)` in place of the held-out check → 2 failed. - A5b: a held-out getter that always reads 0 → 2 failed. - A5c: judge the hold at render time (`heldOutAtRender`) → only "the same refusal when the editor opens in the very commit the arrival lands in" fails among this card's pins. The prior-editor pin stays green. - A6: `AreaCreate`'s dashboard branch never taken → `StudioAreaAppOpen-36906`: 5 failed | 22 passed. - A7: pair leg off in `readNewDashboardSegment` → 2 failed. A7b (list) → `ResourceListPage.pairCreate-36897`: 1 failed. - A8: `useStudioDashboardNew` reads no phone → 1 failed. - A9: `canCreate` ignores `dashboardNew` → 3 failed. - A10: reason note not drawn → 2 failed. </details> ## Acceptance notes - **Double replace at the app root.** `useDesignModeArrival` replaces the history entry it read, in the same commit `AppRootLanding` may redirect to the app's landing. Child effects run first, so the landing redirect re-applies on the next render. In the browser, the showcase landed on its first page (`/page/showcase_capability_map`) with the mode on and `history.state.usr === null`. A self-built app whose menu holds only links stays on `/apps/ID`, with the same result. - **An app whose menu is split into `areas`** keeps its plain menu under design mode, because `UnifiedSidebar` draws the editor only when `areas.length === 0`. That predates this PR. There the arrival enters the mode but no picker opens. No example app uses `areas`. See the report's open question. - **The arrival does not repeat the 「Design layout」 door's own gate** (`useStudioEntryGate` and the customization wall). The Studio list's 新建 is already gated by `canCreate` (`walled`, `pairCreate`), and the server judges every write again. - **The held-out count moved from state to a ref** (`designMode.tsx`). Nothing rendered from it; `enter` is the only reader. The existing 36692 pins pass unchanged. - **The pair leg is applied to the dashboard New only.** A pair's report New still falls back to the area's own create, pinned as CONTROL per the dispatch's "report 新建 unchanged". Whether it should gain the leg is in the report's open questions. - While the package's apps are being read, the list draws no 新建, so a no-app package never flashes one. ## Verification - Browser walk on the showcase stack: `pnpm dev -- --fresh -p 38461` (seeded admin), and the Console from `ui/` sources via `pnpm --filter @object-ui/console dev` on :5180 pointed at it. Driven with Playwright from a scratch script, not committed. - **Showcase** (`com.example.showcase`, a read-only code package; the HotCRM shape): Studio › dashboard list › 新建 lands on `/apps/com.example.showcase/page/showcase_capability_map` with the Design layout bar and the 「Add menu item」 picker on Dashboards (「New dashboard…」 first). The history entry's state was cleared. - Create lands on `/apps/com.example.showcase/dashboard/walk_showcase?studio=/studio/com.example.showcase/metadata/dashboard?package=com.example.showcase` in its edit state, with the × drawn. The entry is in the menu, and the dashboard was saved to `com.example.showcase.custom`. - A reload of that page shows no design bar. × returns to the Studio list. - **Self-built** (`com.walk.selfbuilt`, created through `POST /api/v1/packages` with one app `walk_app`): 新建 lands on `/apps/com.walk.selfbuilt` with the bar and picker. Create opens `/apps/com.walk.selfbuilt/dashboard/walk_selfbuilt?studio=…`, and the dashboard was saved to `com.walk.selfbuilt`. × returns to the list. - **No app** (`com.walk.noapp`): no 新建, and the note reads "A new dashboard is made in an app's design mode, so that it hangs in a menu. This package has no app to make it in." - **Phone** (390 px): no 新建 and no note. - Two-minute check: in Studio, open any package's Dashboards list and press 新建. Expect the app with the purple Design layout bar and the 「Add menu item」 dialog already on Dashboards. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYoLfUxK6MRhuSp7nAt)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent db46566 commit ab91323

15 files changed

Lines changed: 966 additions & 91 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(studio): New on a Studio dashboard list opens the app's design mode, ready to add a dashboard to its menu
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Studio redesign (epic #36890): a new dashboard is made where it hangs in an app's menu, never outside every menu.
12+
13+
- **New on a Studio dashboard list** opens the package's app with Design layout already on and the 「Add menu item」 picker open on its Dashboards, 「New dashboard…」 first. The app is picked the same way as for opening a dashboard: the app you came from when it is one of the package's, otherwise the package's first app. For an installed app, what you save there goes to its customization package, as before. For a customization package (`<base>.custom`) that has no app of its own, the base package's app opens.
14+
- **After Create** the dashboard is in the menu where the picker put it, at the end of the menu's top level, and opens for editing, as a dashboard made in Design layout always has. Its × goes back to the Studio list you left. Closing the picker instead leaves you in Design layout, with nothing added.
15+
- **When there is no New.** On a phone-width window the dashboard list offers no New: Design layout is never on there. An empty list there says a dashboard is made in an app's design mode on a wider screen. A package with no app to open offers no New either, and the list says why. While the package's apps are still being read, an empty list shows no hint yet. It never says a writable package is read-only.
16+
- **Nothing enters Design layout by itself.** The way in is a one-time instruction carried by the click, never the address: a reload, a shared link or Back does not turn it on. If a dashboard's or a report's own editor is open at that moment, Design layout refuses with the usual message and nothing else happens.
17+
- **The report list is unchanged:** its New still opens the app's New report page.
18+
- **A note on an earlier entry,** customization packages' dashboards and reports opening in their base package's app: the app you came from also counts when it is not one of the base's apps, as long as its menu opens that dashboard or report. That is the same rule as for every package.
19+
- New Studio strings `engine.list.dashboardNewNoApp` and `engine.list.dashboardNewWiderScreen`, in English and Chinese.

‎ui/packages/app-shell/src/layout/ConsoleLayout.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { useHomePath } from '../hooks/useHomePath.js';
3939
import { AppHeader } from './AppHeader.js';
4040
import { DesignModeProvider, useDesignModeController } from './designMode.js';
4141
import { DesignModeBar } from './DesignModeBar.js';
42+
import { useDesignModeArrival } from './useDesignModeArrival.js';
4243
import { useResponsiveSidebar } from '../hooks/useResponsiveSidebar.js';
4344
import { usePhoneNavDrawerHistory } from './usePhoneNavDrawerHistory.js';
4445
import { usePhoneViewport } from '../hooks/usePhoneViewport.js';
@@ -234,6 +235,10 @@ export function ConsoleLayout({
234235
// objectstack#36362 — the app's design mode, held here so it stays on from
235236
// page to page of the app; never on a phone, which has no 「Design layout」.
236237
const designMode = useDesignModeController({ appName: activeAppName, appBasePath, enabled: !phone });
238+
// objectstack#36907 — a Studio dashboard list's 「New」 arrives with the
239+
// mode asked to enter and the 「Add menu item」 picker on its dashboards;
240+
// read once and cleared, so Back or a reload enters nothing.
241+
useDesignModeArrival(designMode, !phone);
237242
// objectstack#30043 — the page in view, handed to the dock as its
238243
// `context.surface` (cloud#1610's shape): the object of a list, the object
239244
// and record id of a record page, the dashboard, report or page. Read off the

‎ui/packages/app-shell/src/layout/DesignModeMenu.tsx‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
* maintainer's ruling to keep report editing its own entry, as Twenty does):
5454
* a new report is made from the reports index, then linked here.
5555
*
56+
* The mode may arrive asking this menu to open first (objectstack#36907, a
57+
* Studio dashboard list's 「New」, `useDesignModeOpening`): the picker then
58+
* opens at once, on its 「Dashboards」, for an entry at the end of the top
59+
* level, as that level's 「Add menu item」 would. A dashboard created from it
60+
* opens with the Studio list it came from (`?studio=`), so its × goes back
61+
* there; closing the picker drops that, and later adds are plain.
62+
*
5663
* Every edit is staged with the mode (`useDesignModeChange`), under one key
5764
* for the app's menu: the mode's 「Save」 writes it (`saveAppMenu`), its
5865
* 「Cancel」 drops it. The menu drawn is the staged one, so it survives a page
@@ -144,7 +151,7 @@ import {
144151
fetchListedPackageManifests,
145152
listedCustomizationPairOf,
146153
} from '../views/studio-design/packages-io.js';
147-
import { useDesignModeChange } from './designMode.js';
154+
import { useDesignModeChange, useDesignModeOpening } from './designMode.js';
148155
import {
149156
MENU_TARGET_KINDS,
150157
canMoveBy,
@@ -181,6 +188,7 @@ import {
181188
} from './designModeMenuSave.js';
182189
import { freeItemName, isNewMenuItemKind, saveAppMenuWithNewItem, type NewMenuItemKind } from './designModeMenuCreate.js';
183190
import { dashboardEditArrival } from './designModeArrival.js';
191+
import { withStudioReturn } from '../views/studio-design/studioAddress.js';
184192

185193
/**
186194
* The group label's icon-mode hiding, as the sidebar's own labels declare it
@@ -452,10 +460,32 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
452460
const startAdd = (at: AddAt) => {
453461
setAddAt({ parentId: at.parentId, index: Math.min(at.index, ownEndOf(menu, at.parentId)) });
454462
};
463+
464+
// objectstack#36907 — what the mode arrived asking to open: the picker on
465+
// its 「Dashboards」, at the end of the top level, taken once. `arrivedFrom`
466+
// is the Studio list it came from, kept while that picker is open.
467+
const arrivalOpening = useDesignModeOpening();
468+
const [pickerKind, setPickerKind] = React.useState<MenuTargetKind | null>(null);
469+
const [arrivedFrom, setArrivedFrom] = React.useState<string | null>(null);
470+
const takeArrival = arrivalOpening.take;
471+
React.useEffect(() => {
472+
if (!arrivalOpening.opening) return;
473+
const taken = takeArrival();
474+
if (!taken) return;
475+
startAdd({ parentId: null, index: menu.length });
476+
setPickerKind(taken.column);
477+
setArrivedFrom(taken.studioReturn);
478+
// eslint-disable-next-line react-hooks/exhaustive-deps -- answered once per opening
479+
}, [arrivalOpening.opening, takeArrival]);
480+
const closePicker = () => {
481+
setAddAt(null);
482+
setPickerKind(null);
483+
setArrivedFrom(null);
484+
};
455485
const pick = (entry: MenuEntry) => {
456486
if (!addAt) return;
457487
update(insertEntry(menu, addAt.parentId, addAt.index, entry));
458-
setAddAt(null);
488+
closePicker();
459489
};
460490

461491
// objectstack#36364 — a new dashboard, in the held place: created, put in
@@ -498,8 +528,9 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
498528
),
499529
);
500530
if (!saved) return false;
501-
setAddAt(null);
502-
navigate(resolveHref(entry as unknown as NavigationItem, basePath).href, { state: dashboardEditArrival(name) });
531+
const href = resolveHref(entry as unknown as NavigationItem, basePath).href;
532+
closePicker();
533+
navigate(arrivedFrom ? withStudioReturn(href, arrivedFrom) : href, { state: dashboardEditArrival(name) });
503534
return true;
504535
};
505536

@@ -622,7 +653,8 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
622653
<MenuItemPicker
623654
packageId={packageId}
624655
inMenu={menuTargets(menu)}
625-
onClose={() => setAddAt(null)}
656+
initialKind={pickerKind}
657+
onClose={closePicker}
626658
onPick={(kind, name, link) => pick(entryFor(kind, name, newEntryId([...menu, ...(storedMenu ?? [])]), link))}
627659
onCreate={createItem}
628660
language={language}
@@ -915,13 +947,16 @@ function useTargetRows(packageId: string, language: string): { rows: TargetRow[]
915947
function MenuItemPicker({
916948
packageId,
917949
inMenu,
950+
initialKind = null,
918951
onClose,
919952
onPick,
920953
onCreate,
921954
language,
922955
}: {
923956
packageId: string;
924957
inMenu: ReadonlySet<string>;
958+
/** The kind the picker opens on (objectstack#36907); `null`: the list of kinds. */
959+
initialKind?: MenuTargetKind | null;
925960
onClose: () => void;
926961
onPick: (kind: MenuTargetKind, name: string, link?: { label: string; url: string }) => void;
927962
/** Create a new `kind` named `label`; `taken` is every name of that kind the picker lists. */
@@ -930,7 +965,7 @@ function MenuItemPicker({
930965
}) {
931966
const { t } = useObjectTranslation();
932967
const { rows, loading } = useTargetRows(packageId, language);
933-
const [kind, setKind] = React.useState<MenuTargetKind | null>(null);
968+
const [kind, setKind] = React.useState<MenuTargetKind | null>(initialKind);
934969
const [query, setQuery] = React.useState('');
935970
const [link, setLink] = React.useState({ label: '', url: '' });
936971
/** The kind being named for creation (objectstack#36364), `null` while picking. */

0 commit comments

Comments
 (0)