Skip to content

Commit ff04943

Browse files
feat(studio): open Studio's dashboards and reports in the app's edit state; × returns to the list (#37226)
Fixes #36906 Clause-②: no Metadata-protocol: none ## 维护者速读 - 管理员在 Studio 的仪表盘、报表列表里点一项会直接进入应用里的编辑状态(仪表盘进编辑态、报表打开构建器),页头的 × 回到刚才的 Studio 列表(刷新后也在),报表列表的「新建」进入应用的新建报表页。 - 属于 Studio 重构专题:Studio 是某个应用的开发界面,这一步打通了 Studio 和应用之间的往返编辑。 - 从 Studio 报表列表新建的报表改由应用的新建报表页保存,和以前一样存进该包(已安装的应用存进它的定制包),只有保存那一刻定制包恰好用不了时才存到包外并提示列表里看不到它;出错会影响打开到哪里和新报表存在哪里,可以直接撤回,已存的报表留在原处,只有草稿的仪表盘和报表、以及已安装应用定制包里的仪表盘和报表暂时仍打开 Studio 原来的详情页。 - 无。 ## What changes Epic #36890, decisions 3, 6, 13 and 15. - **Studio opens a dashboard or a report in its app.** A plain open of a dashboard or a report in Studio's list no longer shows the generic item page. It opens the item's page in an app, using the arrival state the design mode already uses: the dashboard opens in its edit state, the report opens its builder. The Studio address is replaced, not stacked, so browser Back from the app lands on the list. - **Which app (decision 6).** It is the app the author came from, when that app is one of the package's published apps, or when its menu opens the item. Otherwise it is the package's first published app. With no app, the item keeps the generic item page (decision 3). The same happens on the cross-package leg, and whenever the address asks the item page for one of its own tools (a tab, the draft review, a selection), so History and the draft door's review links still land there. The rule is shared with Studio's back link (`studioBackTarget`), so the two cannot disagree. It lives in a new pure module, `studioAppEdit.ts`, and the area's step is `StudioAreaAppOpen.tsx`. - **× back to Studio (decision 15).** The app address carries `?studio=` with the Studio list it came from, filters and sort included. It is built and read only through `studioAddress.ts` (`withStudioReturn`, `readStudioReturn`) and registered as a reserved console param. The value is read as untrusted: only a Studio address on this origin is followed. While the param is present, the dashboard page and the report page draw a × that returns to that list, after a reload too. The report builder's own × does the same. Leaving unsaved edits asks first. - **Report New (decision 13).** Studio's report list New opens `/apps/APP/reports/new` in the app picked the same way. Its × goes back to the list, and the saved report's page keeps the way back. With no app, the area creates as before. Dashboard New is #36907's, untouched. - **Where that new report is saved.** Opened from Studio, the new-report page saves the report into the app's package, the way a new view made in an app is saved (`resolveRuntimeCreatePackage`): the package when it is writable, else its `.custom` pair through the ensure door; when neither can be had, naming no package, as views fall back, and then an info notice says the report was saved outside the app's package, so the Studio list does not show it (`report.builder.savedOutsideApp`, the counterpart of a view's `onSavedOutsideApp` notice). The draft, the publish and the discard of a refused publish all name that package (`saveAndPublishInPackage`), so on every other leg the report is in the list × returns to. The console warning `resolveRuntimeCreatePackage` prints on that fallback now names the type it saves (it said "the view" for a report too): the function takes the type as its second argument. On a read-only base whose pair door is closed (walled, or a kernel package), report New no longer opens the app page: it goes back to the list, as every create there does. - **An item with no published version keeps the generic item page.** Before handing over, `StudioAreaAppOpen` reads the item once, as the app reads it (published, no draft preview, `?package=` the open package). No published version (a draft only: an AI draft, a create whose publish was refused), or a failed read, keeps Studio's generic item page, which is the page that opens the draft. Only then are the package's apps read. - **A dashboard made in Studio lands in its app, and Back skips the create page.** The area's own create publishes and lands on the item, which the gate forwards to the app. In a package's area, for a dashboard or a report, that landing now replaces the create page's history entry (`studioCreateLandsInApp`, read by `ResourceEditPage`), so Back from the app lands on the list. Every other type, and Setup, land as before. - **The report builder's × and the new-report page's × ask over unsaved edits outside Studio too.** Both handlers already received `dirty` for the Studio leg; the ask now runs before either leg. - **No dashboard edit on a phone.** `useDashboardEditOffered` now also requires a window at least `sm` (640 px) wide, the width from which the edit state's side panel is drawn. Before, only the button's CSS hid it. A landing that asks for the edit state on a narrower window is cleared and opens nothing, so neither Studio nor the design mode can put a phone into the edit state. - New `studioReturn` strings, and `report.builder.savedOutsideApp`, in every bundled locale (additive only; no released key removed). zh-Hant is regenerated from zh-Hans by its generator. ## Why The maintainer asked that dashboards and reports listed in Studio open straight into the front end's design page (epic #36890). The epic's decisions fix which app, the fallback, the report New target and the address-borne way back. ## Tests - New `studioAppEdit.test.ts`: decision 6, rule by rule; the new-report variant; agreement with the back link; the app addresses. - `studioAddress.test.ts`, new top-level describe: the `?studio=` builder and reader, the refusals both ways (another origin, protocol-relative, `/studiox`, a backslash, `javascript:`), and the reserved-param registry. - New `StudioAreaAppOpen-36906.test.tsx`, through the real `StudioMetadataArea` routes: the app picked, the arrival carried, the return address (list context kept, item-only params dropped), the replace, and every open that keeps the item page (a tab, the review, no app, the cross-package leg, other types). Also report New, and its fallback. - `DashboardView.inPageEdit-36372.test.tsx`, new describe: landing from Studio, × target, × after a reload, the dirty prompt, the phone landing (cleared, no edit, no Edit button), and an off-Studio value drawing no ×. - `ReportView.designModeExclusion-36692.test.tsx`, new describe: landing in the builder, the builder × to Studio, its dirty prompt, the page × beside Edit, and the card's check: reached with the design mode already on, no builder and no Edit, while × still goes back. - `ReportNewPage-36692.test.tsx`, new describe: × to Studio, and Save keeping `?studio=`. This round: Save from Studio names `packageId: P` on the draft and the publish; on a read-only base it names the pair (`P.custom`, asked of the ensure door); CONTROL: a refusing ensure door falls back to the package-less save. × over an edit asks; declining stays with nothing sent; agreeing goes back to the Studio list (and the clean × asks nothing). Outside Studio: Save names no package and asks no package door, and × over an edit asks. - `StudioAreaAppOpen-36906.test.tsx`, previous round: a draft-only dashboard row keeps the item page and reads no app; so does a draft-only report and a failed read; `studioCreateLandsInApp` rule by rule. Its "dashboard create → Save lands on the app's dashboard and Back lands on the list" case drives the area's routes over a create STUB (`CreateStub` reimplements the landing), so it pins the gate's forward and Back over a replaced entry, not `ResourceEditPage`'s call site; that is pinned in the new file below. A read-only base (`readOnly`, `customization` handed in): its dashboard row opens in the base's app; a pair-row address (`/studio/BASE.custom/metadata/dashboard/X?package=BASE.custom`) keeps the generic page (the starting point of #37237); report New opens the base app's new-report page; with the pair door walled, or no customization, report New goes back to the list. - `ReportView.designModeExclusion-36692.test.tsx`, previous round: outside Studio, a clean builder × closes without asking; over an edit it asks, declining keeps the builder, agreeing closes it. - New `ResourceEditPage.createLandingReplace-36906.test.tsx` (this round), the REAL `MetadataResourceEditPage` over a real `MetadataClient` and an in-memory server: under a `MetadataAreaHost` with a `packageId`, a dashboard create's Save lands on the item with a REPLACE (`useNavigationType`); CONTROLs: a `view` create in the same area, and a dashboard create with no area host (Setup), land with a PUSH. Each case also pins the save's `?package=` (the area's package, or none). - `ReportNewPage-36692.test.tsx`, this round: the refusing-door CONTROL now also asserts the info notice (once, the `report.builder.savedOutsideApp` key) and that the console warning names the report; the package, pair and outside-Studio cases assert no notice. The clock is gone from the save cases: the Han romanizer `handleSave` awaits is paid once in a `beforeAll` (a cold dynamic import, paid at collection), and every save case waits on the address it asserts (`waitFor`) instead of two `setTimeout(0)` ticks, so a late save can no longer land in the next case. - Ablation (one, on the behaviour change the tests pin): with the phone gate removed from `useDashboardEditOffered`, the phone pin fails 1/1. Restored, its blob equals HEAD's and `git diff HEAD` is empty. - This round's ablations, each through `scripts/ablation-replace.mjs` (anchor 1 to 0, restore proven blob == HEAD and `git diff HEAD` empty), are listed under Verification. ## Acceptance notes - **Read first, by risk (rework 2):** the notice line after the save in `ReportNewPage.tsx` (fires only when Studio opened the page, the app has a package, and none could be had), and the new real-page pin `ResourceEditPage.createLandingReplace-36906.test.tsx`. - **Read first, by risk (rework 1):** the save hunk of `ReportNewPage.tsx` (where a report made from Studio is written: the package, its pair, or none), the published-version read at the top of `StudioAreaAppOpen.tsx`'s effect, and the `replace` on the create landing in `ResourceEditPage.tsx` (shared by every type; it reads `studioCreateLandsInApp`, true only for a dashboard or report in a package's area). - **Read first, by risk (first round):** `StudioAreaAppOpen.tsx` (async app pick and replace; the fallback), the `useDashboardEditOffered` and arrival hunks in `DashboardInPageEditor.tsx` and `DashboardView.tsx` (the phone gate now also governs the design mode's landing), and the `?studio=` reader in `studioAddress.ts` (an address-bar value followed by a navigate). - `StudioMetadataArea.tsx` is kept narrow: one import, the item open wrapped in `StudioAreaAppGate`, and the create split. Open PRs #37089, #37168 and #37169 edit the same file in other hunks. `overlap-check` merges cleanly with all three at this head. Whichever lands later merges main. - **Callers of the persistence path.** `runtime-metadata-persistence.ts` changes in one place this round: `resolveRuntimeCreatePackage(appPackageId, type, doors?)` takes the type it resolves for, only so its fallback warning names it; its answer is unchanged, and its two internal callers pass the type they save (`view`). The new-report page now also calls two of its existing exports: `resolveRuntimeCreatePackage` (other callers: `createRuntimeMetadata` and `saveAndPublishRuntimeMetadata` themselves, for views only) and `saveAndPublishInPackage` (other callers: `saveInPlace`, the in-page dashboard and report Save, and `setup/publicForms.ts`). `saveAndPublishRuntimeMetadata`'s other callers (`objectViewViewSharing.ts`, `objectViewViewCrud.tsx`, `setup/publicForms.ts`) and `createRuntimeMetadata`'s (`objectViewViewCrud.tsx`, `ObjectDataPage.tsx`) are untouched. - **Outside Studio, a new report is saved where it was before.** The new-report page reached from the app's own reports index still saves naming no package, and asks no package door (pinned). Only the page opened from Studio's report list resolves a package. - **Draft-only check (M2): one read, not the list row's mark.** The read covers every way into the item address: a list click, a typed or shared address, and the area's create landing on the item. The list row's draft mark would cover the click only. The read is asked as the app asks it, so the two cannot disagree. - **A pending Studio draft over a published version.** The item has a published version, so it opens in the app, which shows the published version. A dashboard's edit state then refuses to open, with the existing toast 「This dashboard has unpublished changes in Studio. Publish or discard them there, then edit it here.」, so the page stays a viewer. A report's page shows the published version, and its builder opens on the pending draft's content (the report's Edit reads the stored draft layer first, `authoredBuffer`); the builder's Save is then refused with 「This report has unpublished changes. Publish or discard them above, then save.」, and nothing is written over the draft (the first-write pin). Either way the draft stays Studio's to publish or discard. Read from the code at this head, not walked. - Reload (seat ruling: keep as shipped): after a reload, × back to the Studio list survives, but the editor does not reopen. A reloaded or shared address never opens an editor by itself; that is the arrival modules' rule. - Card item 5 (a dashboard saved on an installed app lands in `.custom`) is pinned at unit level by the existing case "an installed package saves into its customization pair". It is NOT MEASURED live on HotCRM: no HotCRM checkout is in this session. That leg carries to #36910. - Follow-up card filed: #37237. In this PR, a `.custom` pair's dashboards and reports keep the generic item page (decision 6, rule 3); #37237 resolves them through the base package's apps. ## Verification Two-minute check: open Studio for a writable package with a published app, go to Reports, press New, pick a data source and a measure, name it, and Save. Expected: the report's page in the app, with a 「Back to Studio」 ×; click it, and the new report is in the Studio list. Rework 2's readings are at head `298361bd` (this branch with `origin/main` `057cedfa` merged in) unless a line names another head. The previous rounds' readings below keep their own heads (`08107d2f`, `727300e5`). <details><summary>Live walk-through, this round (per-agent stack; CRM example plus one writable package)</summary> The stack is a fresh `examples/app-crm` backend (`pnpm dev:crm -- --fresh`) with the Console served by Vite from this branch's `ui/` source, driven by Playwright as the seeded admin, at `727300e5`. In this stack the CRM package is a read-only code package, so it walks the read-only base leg. A second package, created writable through `POST /api/v1/packages` with one published app, walks the writable leg. Writable package (11 PASS, 0 FAIL): - A dashboard staged as a draft only (`PUT ?mode=draft`), opened at its Studio row address, stays on Studio's generic item page. - Studio's dashboard New, then Save: lands on `/apps/PKG/dashboard/NAME` with the way back to the dashboard list. The app page shows the just-published dashboard in its edit state (no 「not found」). Browser Back from there lands on the dashboard list, not on the create page. - Studio's report New opens the app's new-report page. After picking a data source and a measure and saving, it lands on the report's page with the way back. `GET /api/v1/meta/report/NAME?package=PKG` answers 200 with `packageId: PKG`. × returns to the report list, and the new report is in it. - No page errors. Read-only CRM package: - Report New, then Save: the server holds the new report in `com.example.crm.custom` (a read at `?package=com.example.crm` answers 409 naming that pair as the holder). × returns to the CRM report list, and the new report is in it. - Dashboard New there is the area's own create in the pair (unchanged). Its Save lands on the pair's item page, which keeps the generic page (no app of its own; #37237). Back lands on the list. - No page errors. HotCRM: NOT MEASURED, carried to #36910. </details> <details><summary>Tests, rework 2 (head `298361bd` unless named)</summary> - The six pin files (`ReportNewPage-36692`, `ReportView.designModeExclusion-36692`, `StudioAreaAppOpen-36906`, `studioAppEdit`, `studioAddress`, `DashboardView.inPageEdit-36372`) plus the new `ResourceEditPage.createLandingReplace-36906`, default workers, 3 runs on this merged tree: each run lock VERDICT command-exit 0, Test Files 7 passed (7), Tests 95 passed (95). The six alone, 3 runs at `35c94a71` (merged with `origin/main` `ede9b91f`): each 6 passed (6), 92 passed (92). - The seat's S3 red (2 failed of 92 on the merged tree) did NOT reproduce on this box: the six at the merge commit `ad67a645`, before the fix, ran 92 of 92 green once. So the clock is shown another way: with `loadHanRomanizer` slowed by 100 ms (a mutation through `scripts/ablation-replace.mjs`, restored blob == HEAD), the previous round's test file fails its two clock-bound save cases (plus its refusing-door CONTROL, which also lacks the new `toast.info` mock), while this round's file passes 13 of 13. - At `35c94a71`, the wider set: every `ResourceEditPage*`, `runtime-metadata-persistence*`, `Report*` and `DashboardView*` test, `urlParams.test.ts`, `views/studio-design/`, `views/studio-detail/` and `packages/i18n/`. Lock VERDICT command-exit 0, Test Files 505 passed (505), Tests 4838 passed, 13 skipped. - `pnpm --filter @object-ui/app-shell run type-check`, both tsc programs, at `35c94a71`: lock VERDICT command-exit 0, 0 `error TS`. (The final merge brings no app-shell or i18n file.) - eslint on this round's changed ui files: 0 errors; the 15 warnings are existing ones (`no-explicit-any`, `only-export-components`). - Ablations this round, each through `scripts/ablation-replace.mjs` under the lock (anchor 1 to 0, restore proven by blob == HEAD and `git diff HEAD` empty): 8. The call site, `replace: studioCreateLandsInApp(areaHost?.packageId, type),` to `replace: false,` in `ResourceEditPage.tsx`: the new dashboard REPLACE case fails (1 failed, 2 passed of 3); both CONTROLs stay green. 9. The notice line removed from `ReportNewPage.tsx`: the refusing-door CONTROL fails (1 failed, 12 passed of 13). </details> <details><summary>Tests, previous rounds</summary> - At `08107d2f`, the seven touched test files (`ReportNewPage-36692`, `ReportView.designModeExclusion-36692`, `StudioAreaAppOpen-36906`, `studioAppEdit`, `studioAddress`, `DashboardView.inPageEdit-36372`, `urlParams`): lock VERDICT command-exit 0, 7 files, 99 tests passed. - At `727300e5`, the wider set: every `DashboardView*` and `Report*` test, every `ResourceEditPage*` test, every `runtime-metadata-persistence*` test, `views/studio-design/`, `views/studio-detail/`, `src/__tests__/`, `src/preview/`, `urlParams.test.ts` and `packages/i18n/`. Lock VERDICT command-exit 0, 585 of 585 files, 5,662 passed, 13 skipped. - `pnpm --filter @object-ui/app-shell run type-check`, both programs, at `08107d2f`: exit 0, 0 `error TS`. - eslint on the nine changed ui files: 0 errors. The warnings are existing ones. - Ablations, each through `scripts/ablation-replace.mjs` under the lock (anchor 1 to 0; restore proven by blob == HEAD and `git diff HEAD` empty). ui tests resolve `src` directly, so no `dist` leg applies: 1. New-report page, the ask removed: the two "x over unsaved edits" pins fail (2 of 13). 2. New-report page, `dirty &&` dropped (asks on a clean x): the two clean-x pins fail (2 of 13). 3. New-report page, the package resolve replaced by `null`: the package pin, the pair pin and the refusing-door CONTROL fail (3 of 13). The CONTROL fails because no door is asked at all. 4. Report builder, the ask removed: the Studio dirty pin and the new outside-Studio pin fail (2 of 8). 5. `StudioAreaAppOpen`, the no-published-version fallback disabled: the two draft-only pins fail (2 of 16). 6. `studioCreateLandsInApp` forced to `false`: the create-then-Back pin and the rule pin fail (2 of 16). Corrected in rework 2: this reaches the pure rule and the create stub's own copy of the landing in `StudioAreaAppOpen-36906`, not `ResourceEditPage`'s call site (the seat's call-site ablation left that file green, 16 of 16). Ablation 8 above reaches the call site. 7. Report New on a read-only base, the pair-door condition removed: the closed-door pin fails (1 of 16). </details> <details><summary>Local gates, rework 2 (`dispatch-gates.mjs --commands`, 73 families)</summary> - At `298361bd`: all 74 derived families exit 0, each recorded as `cmd :: exit N` and reconciled with `--ran`: "74 derived famil(ies) accounted for — 74 run, 0 NOT-MEASURED". The ui `scripts/` family ran under the lock with `--maxWorkers=1`: Test Files 172 passed, 2 skipped. (The same 72 non-ui families also ran at `35c94a71`, all exit 0 after `check:skill-examples` first refused with exit 3 because `@objectstack/client-react` was not built in this worktree, then exit 0 once built.) - Also at `298361bd`: `check:test-source-alias` exit 0, ui `check:i18n-keys` exit 0 (every call-site key resolves against the en pack), `check:nul-bytes` exit 0, `check-platform-checklist --changed-from origin/main` exit 0 (0 anchored files), and `overlap-check` VERDICT clean exit 0 (`origin/main` `057cedfa`, #37249, #37210, #37169, #37166). The same alias and overlap checks also ran clean before the push. - CI runs the full farm on this PR. </details> <details><summary>Local gates, previous round (`dispatch-gates.mjs --commands`, 73 families at that head)</summary> - At `08107d2f`: all 73 derived families exit 0, each recorded as `cmd :: exit N` and reconciled with `--ran`: "73 derived famil(ies) accounted for — 73 run, 0 NOT-MEASURED". Two needed a second run: `check:skill-examples` first exited 3 (it refused, measuring nothing, because `packages/client`'s source was newer than its build after a local history rebuild), then 0 after rebuilding `client`; the ui `scripts/` family ran under the lock with `--maxWorkers=1`: 172 files passed, 2 skipped. - `check:test-source-alias` first exited 1 at `727300e5`: the new-report page now imports the draft bar's package rule, which reaches `@objectstack/lint`. The test file pays that load at collection (`import '@objectstack/lint'`, the gate's prescription); exit 0 since, and at `08107d2f`. - Also at `08107d2f`: `overlap-check` VERDICT clean (main, #37249, #37210, #37169, #37168, #37166), `@objectstack/spec check:generated` exit 0 after the merge, and `check-platform-checklist --changed-from origin/main` exit 0 (no anchored file changed). - CI runs the full farm on this PR. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the changed files locally; the repo-wide run is CI's.) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmSqW1KzbiTWCnSN1K)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYkkwuF6UuFtu85Yd5H --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5cf9941 commit ff04943

36 files changed

Lines changed: 1853 additions & 61 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(app-shell): a dashboard or a report opened from a Studio list opens in its app's edit state, and × goes back to the list
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Studio redesign (epic #36890), decisions 3, 6, 13 and 15.
12+
13+
- **Opening a dashboard or a report from a Studio list** opens its page in an app, with the dashboard's edit state or the report's builder already open, as the page's own Edit opens them. The app is the one the author came from, when that app is one of the package's published apps or its menu opens the item; otherwise it is the package's first published app. The item keeps opening Studio's own item page when the package has no published app, on the list of every package, when the item has no published version yet (a draft only), or when the link asks for one of the item page's tabs or its draft review.
14+
- **× back to Studio.** The page's address remembers the Studio list it was opened from, so the dashboard page and the report page draw a × that goes back to that list with its filters and sort, after a reload too. The report builder's own × does the same. Leaving unsaved edits asks first.
15+
- **New report from Studio's report list** opens the app's New report page. The report is saved in the package the list shows, or, for an installed app, in its customization package, so it appears in the list × goes back to. Where the installed app's customization package cannot be used, New goes back to the list, as before. If that package becomes unusable between opening the page and saving, the report is saved outside any package, and a notice says the Studio list does not show it. Closing the page goes back to the Studio list, and the saved report's page keeps the way back. With no app to open, the list creates as before.
16+
- **A dashboard made in Studio** opens in its app once saved, and the browser's Back from there goes to the list, not to an empty New page.
17+
- **The report builder's ×, and the New report page's ×,** now ask before dropping unsaved edits everywhere, not only when Studio opened them.
18+
- **No dashboard edit on a phone.** The dashboard edit state is no longer offered in a phone-width window (narrower than 640 px). A link that asks for it, from Studio or the design mode, is ignored there and the page stays a viewer. The Edit button was already hidden at that width.
19+
- New console strings under `studioReturn`, and `report.builder.savedOutsideApp`, in every bundled locale.

‎content/docs/frontend/plugins/plugin-dashboard.mdx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,24 @@ The console's dashboard page uses both in its in-page edit state: an admin
172172
who may design the dashboard's package opens it with **Edit**, changes it with
173173
Studio's own dashboard panels at the right, and **Save** publishes that one
174174
dashboard (into the package, or into the app's customization package for an
175-
installed app), so everyone sees it at once.
175+
installed app), so everyone sees it at once. The edit state needs its side
176+
panel, so it is not offered on a window narrower than Tailwind's `sm`
177+
breakpoint (640 px).
178+
179+
A dashboard opened from Studio's dashboard list lands on this page with the
180+
edit state already open, in the app the author came from when it is one of
181+
the package's apps (or its menu opens the dashboard), else in the package's
182+
first published app. The page's address then carries `?studio=` with the
183+
Studio list, and the header draws a **×** that goes back to it, after a
184+
reload too. A report opened from Studio's report list lands the same way,
185+
with its builder open, and the report list's **New** opens the app's
186+
`reports/new` page, which saves the new report in the package (or, for an
187+
installed app, in its customization package), so it is in the list the
188+
**×** goes back to. If neither package can be used when the report is
189+
saved, it is saved outside any package, and a notice says the Studio list
190+
does not show it. A package with no published app, and a dashboard or a
191+
report that has no published version yet (a draft only), keep Studio's
192+
generic item page.
176193

177194
## TypeScript Support
178195

‎ui/packages/app-shell/src/layout/designModeArrival.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* The landing of a dashboard the design mode just created (objectstack#36364):
55
* the design mode navigates to the new dashboard with this in the navigation
66
* state, and the dashboard's page opens its edit state on arrival
7-
* (objectstack#36372), as its Edit button does.
7+
* (objectstack#36372), as its Edit button does. A dashboard opened from a
8+
* Studio list lands the same way (objectstack#36906, `StudioAreaAppOpen`).
89
*
910
* Navigation state, not a URL parameter: it is a one-time instruction, not a
1011
* place anyone links to, so a shared or reloaded address never opens the edit

‎ui/packages/app-shell/src/urlParams.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
10+
import { STUDIO_RETURN_PARAM } from './views/studio-design/studioAddress.js';
1011

1112
/**
1213
* urlParams — the single registry of RESERVED console URL query params
@@ -61,6 +62,9 @@ import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
6162
* | `from` | Ancestor breadcrumb trail for a record route, | push (with |
6263
* | | so drilling record→related-record keeps a | the drill-in) |
6364
* | | clickable path back (`Account → #p → Invoice`).| |
65+
* | `studio` | The Studio list an app page was opened from | with the |
66+
* | | (objectstack#36906): the page draws × back to | Studio open |
67+
* | | it. Defined by `studioAddress.ts`. | |
6468
*
6569
* Push-vs-replace rule of thumb: an overlay the user OPENED (form, drawer)
6670
* pushes one entry so browser Back closes it; passive state that tracks an
@@ -71,9 +75,10 @@ import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
7175
* `package`, …) belong to their page's own contract and are NOT reserved
7276
* here — but they must not collide with the names above.
7377
*
74-
* One reserved param is DEFINED ELSEWHERE and only re-exported here:
75-
* `runAction` (see {@link NAV_RUN_ACTION_PARAM}). It is the wire encoding of a
76-
* spec-declared nav slot, written by `@object-ui/layout`'s `resolveHref`, which
78+
* Two reserved params are DEFINED ELSEWHERE and only re-exported here.
79+
* `studio` ({@link STUDIO_RETURN_PARAM}) belongs to Studio's one address
80+
* builder, `studioAddress.ts`. `runAction` (see {@link NAV_RUN_ACTION_PARAM})
81+
* is the wire encoding of a spec-declared nav slot, written by `@object-ui/layout`'s `resolveHref`, which
7782
* sits below this package — so the constant lives there and this registry
7883
* references it rather than restating it. Restating would give the console's
7984
* hottest collision check a second spelling to drift from, which is the exact
@@ -190,6 +195,14 @@ export const RECORD_TRAIL_PARAM = 'from';
190195
*/
191196
export { NAV_RUN_ACTION_PARAM };
192197

198+
/**
199+
* The Studio address an app page returns to (`?studio=<address>`,
200+
* objectstack#36906, epic #36890 decision 15). Re-exported, not restated:
201+
* `studioAddress.ts` owns the Studio vocabulary and its builders
202+
* (`withStudioReturn`, `readStudioReturn`); read it through them.
203+
*/
204+
export { STUDIO_RETURN_PARAM };
205+
193206
/**
194207
* All reserved params, for collision checks (e.g. a lint or a dev-time
195208
* assertion that a page-scoped param doesn't shadow the console contract).
@@ -208,6 +221,7 @@ export const RESERVED_URL_PARAMS: readonly string[] = [
208221
KEYBOARD_SHORTCUTS_PARAM,
209222
RECORD_TRAIL_PARAM,
210223
NAV_RUN_ACTION_PARAM,
224+
STUDIO_RETURN_PARAM,
211225
];
212226

213227
/**

‎ui/packages/app-shell/src/views/DashboardInPageEditor.tsx‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,54 @@ export function filtersSectionLabel(locale: SupportedLocale): string | null {
206206
return typeof section?.label === 'string' ? section.label : null;
207207
}
208208

209+
/**
210+
* The narrowest window the edit state is offered in: Tailwind's `sm`, from
211+
* which the page draws the side panel the edit state needs.
212+
*/
213+
export const DASHBOARD_EDIT_MIN_WIDTH = 640;
214+
215+
/** Is the window at least {@link DASHBOARD_EDIT_MIN_WIDTH} wide right now? */
216+
function dashboardEditFitsNow(): boolean {
217+
return typeof window === 'undefined' || window.innerWidth >= DASHBOARD_EDIT_MIN_WIDTH;
218+
}
219+
220+
/**
221+
* Whether the window is wide enough for the edit state (objectstack#36906).
222+
* Read synchronously on the first render, as `usePhoneViewport` reads its
223+
* answer, so a landing that asks for the edit state never sees a phone as wide.
224+
*/
225+
export function useDashboardEditFits(): boolean {
226+
const [fits, setFits] = React.useState<boolean>(dashboardEditFitsNow);
227+
React.useEffect(() => {
228+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
229+
const mql = window.matchMedia(`(min-width: ${DASHBOARD_EDIT_MIN_WIDTH}px)`);
230+
const onChange = () => setFits(dashboardEditFitsNow());
231+
mql.addEventListener('change', onChange);
232+
// A width that moved between the first render and this effect.
233+
onChange();
234+
return () => mql.removeEventListener('change', onChange);
235+
}, []);
236+
return fits;
237+
}
238+
209239
/**
210240
* Whether this principal is offered the Edit button for a dashboard
211241
* `ownerPackageId` owns: the gate of the app → Studio entries
212242
* (`useStudioEntryGate`: a workspace admin who may author metadata, on a
213243
* package Studio lists, writable or not; never a kernel package). A
214244
* read-only package's dashboard is edited through its customization package.
215245
* Not while the shell's design mode is on (objectstack#36692): the two are
216-
* separate entries, never open together.
246+
* separate entries, never open together. Not on a phone either
247+
* (objectstack#36906): the edit state needs its side panel, so a window
248+
* narrower than {@link DASHBOARD_EDIT_MIN_WIDTH} is offered no edit, and a
249+
* landing that asks for one (from Studio, from the design mode) opens none.
217250
*/
218251
export function useDashboardEditOffered(ownerPackageId: string | null | undefined): boolean {
219252
const path = ownerPackageId ? studioPackagePath(ownerPackageId) : null;
220253
const gated = useStudioEntryGate(path) !== null;
221254
const designing = useDesignModeActive();
222-
return gated && !designing;
255+
const fits = useDashboardEditFits();
256+
return gated && !designing && fits;
223257
}
224258

225259
/** The page header's Edit button. */

‎ui/packages/app-shell/src/views/DashboardView.inPageEdit-36372.test.tsx‎

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ const packages = vi.hoisted(() => ({
5151
ensured: [] as string[],
5252
}));
5353
/** objectstack#36364 — the navigation state the page is reached with, and its replaces. */
54-
const route = vi.hoisted(() => ({ state: null as unknown, navigate: null as null | ((...a: unknown[]) => void) }));
54+
const route = vi.hoisted(() => ({ state: null as unknown, search: '', navigate: null as null | ((...a: unknown[]) => void) }));
5555
const toasts = vi.hoisted(() => ({ success: [] as unknown[], error: [] as unknown[] }));
5656

5757
vi.mock('../providers/MetadataProvider', () => ({ useMetadata: () => meta.value }));
5858
vi.mock('react-router-dom', () => ({
5959
useParams: () => ({ dashboardName: 'ops_board' }),
6060
useNavigate: () => route.navigate ?? (() => {}),
61-
useLocation: () => ({ pathname: '/apps/crm/dashboard/ops_board', search: '', hash: '', key: 'landing', state: route.state }),
61+
useLocation: () => ({ pathname: '/apps/crm/dashboard/ops_board', search: route.search, hash: '', key: 'landing', state: route.state }),
6262
}));
6363
vi.mock('./useOpenRecordList', () => ({
6464
useRecordListDrillNavigation: () => ({ openRecordList: vi.fn(), canOpenRecordList: () => true }),
@@ -187,6 +187,7 @@ beforeEach(() => {
187187
toasts.success = [];
188188
toasts.error = [];
189189
route.state = null;
190+
route.search = '';
190191
route.navigate = null;
191192
});
192193

@@ -401,6 +402,90 @@ describe('DashboardView arrival from the design mode (objectstack#36364)', () =>
401402
});
402403
});
403404

405+
describe('DashboardView opened from a Studio list (objectstack#36906)', () => {
406+
const studioList = '/studio/crm/metadata/dashboard?q=ops';
407+
const fromStudio = `?studio=${encodeURIComponent(studioList)}`;
408+
409+
let widthBefore = 0;
410+
beforeEach(() => {
411+
widthBefore = window.innerWidth;
412+
});
413+
afterEach(() => {
414+
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: widthBefore });
415+
});
416+
417+
it('lands in the edit state, and x goes back to the Studio list', async () => {
418+
const navigate = vi.fn();
419+
route.navigate = navigate;
420+
route.state = { designModeNewDashboard: 'ops_board' };
421+
route.search = fromStudio;
422+
mount();
423+
expect(await screen.findByTestId('dashboard-editing-badge')).toBeInTheDocument();
424+
// The landing is cleared, and the address keeps the way back.
425+
expect(navigate).toHaveBeenCalledWith(`/apps/crm/dashboard/ops_board${fromStudio}`, { replace: true, state: null });
426+
const close = screen.getByTestId('studio-return');
427+
expect(close).toHaveAttribute('data-target', studioList);
428+
fireEvent.click(close);
429+
expect(navigate).toHaveBeenLastCalledWith(studioList);
430+
});
431+
432+
it('after a reload (no landing), the viewer still draws x back to the Studio list', async () => {
433+
route.search = fromStudio;
434+
mount();
435+
await screen.findByTestId('dashboard-edit');
436+
expect(screen.queryByTestId('dashboard-editing-badge')).not.toBeInTheDocument();
437+
expect(screen.getByTestId('studio-return')).toHaveAttribute('data-target', studioList);
438+
});
439+
440+
it('x over unsaved edits asks first, and staying keeps the edit state', async () => {
441+
const navigate = vi.fn();
442+
route.navigate = navigate;
443+
route.search = fromStudio;
444+
// This DOM ships no window.confirm: install one, and put back what was there.
445+
const before = window.confirm;
446+
const confirm = vi.fn(() => false);
447+
window.confirm = confirm as unknown as typeof window.confirm;
448+
try {
449+
mount();
450+
await openEdit();
451+
fireEvent.keyDown(screen.getByTestId('dashboard-widget-resize-handle'), { key: 'ArrowRight' });
452+
fireEvent.click(screen.getByTestId('studio-return'));
453+
expect(confirm).toHaveBeenCalledTimes(1);
454+
expect(navigate).not.toHaveBeenCalledWith(studioList);
455+
expect(screen.getByTestId('dashboard-editing-badge')).toBeInTheDocument();
456+
confirm.mockReturnValue(true);
457+
fireEvent.click(screen.getByTestId('studio-return'));
458+
expect(navigate).toHaveBeenLastCalledWith(studioList);
459+
} finally {
460+
window.confirm = before;
461+
}
462+
});
463+
464+
it('on a phone, the landing opens no edit state: it is cleared and the page stays a viewer', async () => {
465+
Object.defineProperty(window, 'innerWidth', { configurable: true, writable: true, value: 390 });
466+
const navigate = vi.fn();
467+
route.navigate = navigate;
468+
route.state = { designModeNewDashboard: 'ops_board' };
469+
route.search = fromStudio;
470+
mount();
471+
await screen.findAllByText('Total (served)');
472+
await act(async () => { await new Promise((r) => setTimeout(r, 0)); });
473+
expect(navigate).toHaveBeenCalledWith(`/apps/crm/dashboard/ops_board${fromStudio}`, { replace: true, state: null });
474+
expect(screen.queryByTestId('dashboard-editing-badge')).not.toBeInTheDocument();
475+
expect(screen.queryByTestId('dashboard-edit')).not.toBeInTheDocument();
476+
expect(client.value.layered).not.toHaveBeenCalled();
477+
// The way back is still there.
478+
expect(screen.getByTestId('studio-return')).toBeInTheDocument();
479+
});
480+
481+
it('a ?studio= value that is not a Studio address draws no x', async () => {
482+
route.search = `?studio=${encodeURIComponent('https://example.com/studio/crm')}`;
483+
mount();
484+
await screen.findByTestId('dashboard-edit');
485+
expect(screen.queryByTestId('studio-return')).not.toBeInTheDocument();
486+
});
487+
});
488+
404489
describe('DashboardView with no cards yet (objectstack#36364)', () => {
405490
it('a dashboard with no cards says so instead of drawing a blank page; one with cards does not', async () => {
406491
mount({ name: 'ops_board', label: 'Payment analysis', _packageId: 'crm', widgets: [] });

‎ui/packages/app-shell/src/views/DashboardView.tsx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ import {
4646
DashboardEditButton,
4747
DashboardEditingBadge,
4848
DashboardEditPanel,
49+
useDashboardEditFits,
4950
useDashboardEditOffered,
5051
useDashboardInPageEdit,
5152
} from './DashboardInPageEditor.js';
53+
import { StudioReturnButton, useStudioReturnPath } from './StudioReturnButton.js';
5254
import { useInSetupApp } from '../console/setupApp.js';
5355
import { useCustomizeDoorWalled } from './studio-design/StudioCustomizeControls.js';
5456
import { readDashboardEditArrival, withoutDashboardEditArrival } from '../layout/designModeArrival.js';
@@ -304,21 +306,29 @@ export function DashboardView({ dataSource }: { dataSource?: any }) {
304306
// objectstack#36364 — a dashboard the design mode just created arrives with
305307
// its page asked to open the edit state, once the Edit button is offered;
306308
// the landing is cleared as it is read, so Back or a reload opens nothing.
309+
// objectstack#36906 — a dashboard opened from a Studio list lands the same
310+
// way. On a phone the edit state is never offered, so the landing is
311+
// cleared there and the page stays a viewer.
307312
const location = useLocation();
308313
const navigate = useNavigate();
314+
const editFits = useDashboardEditFits();
309315
const arrivedToEdit = readDashboardEditArrival(location.state, dashboardName);
310316
const landedRef = useRef<string | null>(null);
311317
useEffect(() => {
312-
if (!arrivedToEdit || !dashboard || !editOffered || editing) return;
318+
if (!arrivedToEdit || !dashboard || editing) return;
319+
if (!editOffered && editFits) return;
313320
if (landedRef.current === location.key) return;
314321
landedRef.current = location.key;
315322
navigate(`${location.pathname}${location.search}${location.hash}`, {
316323
replace: true,
317324
state: withoutDashboardEditArrival(location.state),
318325
});
319-
void startEdit();
326+
if (editOffered) void startEdit();
320327
// eslint-disable-next-line react-hooks/exhaustive-deps -- runs once per landing; `startEdit` is a fresh closure each render
321-
}, [arrivedToEdit, dashboard, editOffered, editing, location.key]);
328+
}, [arrivedToEdit, dashboard, editOffered, editFits, editing, location.key]);
329+
// objectstack#36906 — opened from a Studio list: × goes back to it.
330+
const studioReturn = useStudioReturnPath();
331+
const studioReturnButton = studioReturn ? <StudioReturnButton to={studioReturn} dirty={editing && edit.dirty} /> : null;
322332

323333
const previewSchema = useMemo(() => {
324334
if (!dashboard || !unregistered) return dashboard;
@@ -456,14 +466,17 @@ export function DashboardView({ dataSource }: { dataSource?: any }) {
456466
icon={<LayoutDashboard className="h-4 w-4" />}
457467
badge={editing ? <DashboardEditingBadge /> : undefined}
458468
actions={editing ? (
469+
<div className="flex items-center gap-2">
459470
<DashboardEditActions
460471
onAddCard={edit.addCard}
461472
onDiscard={edit.discard}
462473
onSave={saveEdit}
463474
saving={edit.saving}
464475
dirty={edit.dirty}
465476
/>
466-
) : (refreshState || editOffered) && (
477+
{studioReturnButton}
478+
</div>
479+
) : (refreshState || editOffered || studioReturnButton) && (
467480
<div className="flex items-center gap-2">
468481
{editOffered && <DashboardEditButton onClick={startEdit} busy={edit.opening} />}
469482
{refreshState && (
@@ -480,6 +493,7 @@ export function DashboardView({ dataSource }: { dataSource?: any }) {
480493
{refreshState.refreshing ? tt('dashboard.refreshing', 'Refreshing…') : tt('dashboard.refreshAll', 'Refresh All')}
481494
</Button>
482495
)}
496+
{studioReturnButton}
483497
</div>
484498
)}
485499
/>

‎ui/packages/app-shell/src/views/ReportBuilderHost.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export interface ReportBuilderHostProps {
4040
servedText?: ServedReportText | null;
4141
/** Write the report. `true` when it was saved; the host then closes the builder. */
4242
onSave: (report: ReportDraft) => Promise<boolean>;
43-
/** Leave the builder without saving. */
44-
onClose: () => void;
43+
/** Leave the builder without saving. `dirty`: the builder holds edits that leaving drops. */
44+
onClose: (left: { dirty: boolean }) => void;
4545
/** A notice above the preview (the pending-draft bar). */
4646
banner?: React.ReactNode;
4747
dataSource?: DataSource;
@@ -147,7 +147,7 @@ export function ReportBuilderHost({ initial, servedText, onSave, onClose, banner
147147
}
148148
onSave={handleSave}
149149
onDiscard={() => setDraft(initial)}
150-
onClose={onClose}
150+
onClose={() => onClose({ dirty })}
151151
dirty={dirty}
152152
saving={saving}
153153
banner={banner}

0 commit comments

Comments
 (0)