Skip to content

Commit dad9b55

Browse files
feat(console): create a dashboard from the design mode's Add menu item (#36606)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi93yJM5eSHAibimwWb6xCgvP)_ Part of #36364 Clause-②: yes (widening) — new `@object-ui/i18n` keys (`designMode.menu.*` for the new picker row and name step, `dashboard.noCards.*`), in all 11 locales; no spec, schema or public export change Metadata-protocol: none repo:objectstack#2 · os-steve · session_01ADHkmPiTdmLxHXBjakSvJy ## 维护者速读 - 用户能看到什么变化:管理员在设计模式里「添加菜单项 → 仪表盘」,第一行是「新建仪表盘…」,填名称确定后,新仪表盘出现在占好的菜单位置,其他改动一起保存,然后直接进入它的编辑状态;没有卡片的仪表盘会显示「还没有卡片」。 - 为什么做:设计模式专题的第三张卡,让管理员不用进 Studio 就能在应用里新建仪表盘并挂到菜单上。 - 出错会怎样:菜单保存失败时,刚建的仪表盘会被删掉,设计模式保持打开并说明原因;中途取消什么都不写;可以直接撤回本次合并。 - 要你做什么:不用做什么。新建报表这一半席位已定(报表必须先选数据集和指标,改为从报表搭建页新建),等 #36374 合并后另做。 ## What changes - The design-mode picker's Dashboards list starts with 「New dashboard…」 (`DesignModeMenu.tsx`). It asks for a name only. 「Cancel」 (or closing the dialog) writes nothing and drops the held place. - 「Create」 runs, in order (`designModeMenuCreate.ts`): every check of the menu save first (`prepareAppMenuSave`, split out of `saveAppMenu` unchanged in behaviour); the dashboard created empty (`{ name, label, widgets: [] }`) and published in the menu's own package (the app's package when listed writable, else its `.custom` pair via the ensure door; ADR-0146 D2, #35624 ruling C) through the existing confirmed-save door `saveDashboardInPlace`; then the menu written and published with the new entry in the held place and every other staged menu edit (`writeAppMenu`). Where the menu cannot be saved, nothing is created: no package-less fallback. - A refused menu removes the dashboard again (the item DELETE with `?package=`, measured on a live server: `Deleted dashboard ... it no longer exists`). If that removal is refused too, the error says the dashboard was left. - The design mode gains `saveWith(key, change)` (`designMode.tsx`): commit everything staged with one change in its key's place, never staging it on its own, so a failed create leaves no half-written entry staged for a later Save. - The machine name is generated from the name (Chinese through pinyin), and checked free on the server (`GET /meta/dashboard/:name`) so a create never publishes over an existing dashboard. - On success the mode is left and the page navigates to the dashboard with a one-time navigation-state landing (`designModeArrival.ts`); `DashboardView.tsx` opens its #36372 edit state on that landing once the Edit button is offered, and clears it. - A dashboard with no cards now draws 「No cards yet」 instead of a blank canvas (view mode only). - **Not in this PR: 「New report…」.** The spec refuses a report without `dataset` + `values`, and the server's draft save refuses it too (`INVALID_METADATA`, measured), so a name-only report cannot be created. The seat's premise correction on the card (comment 7090058961) settles it: 「New report…」 opens the report builder (#36374) in a create mode and writes the report and its menu entry once a dataset and a measure are picked; that half follows after #36374 merges. Branch name: this card thread's container pushes only to `claude/project-thread-un7cwb`, so the `claude/issue-36364-*` spelling the Duplicate Fix Guard looks for is not available; the card is #36364 (claim comment 7088329990). Overlap: touches `DashboardView.tsx`, which draft PR #36461 also touches; `overlap-check` reads both merging cleanly. This PR lands after #36461 per the claim. ## Tests <details><summary>Unit and component tests (head 313b6bf)</summary> Run from the repo root under `os-verify-lock`; vitest root `ui/`. - Head `313b6bf8` merges `origin/main`, bringing #36604 (the `designModeMenu.ts` rename to `designModeMenuModel.ts`), #36622 (#36591's menu `order` rule) and #36461. The one conflict, in `DesignModeMenu-36363.test.tsx`, was resolved by keeping both sides: this card's `server` mock, its reset and its describe, next to #36591's `servedNav` and its describe. Two imports were moved to the renamed module (`designModeMenuCreate.ts` and its test); no file names the old module any more. #36591's `inShownOrder` / `withOrderRewritten` auto-merged into `prepareAppMenuSave`, so the create path applies the same rule. It is pinned by a new test: the new entry, held between two entries of an `order`-carrying level, is saved as `[customer 0, nav_item_1 1, contact 2, opportunity 3]`. - At `313b6bf8`, after rebuilding the app-shell dependency closure (`VERDICT command-exit 0`): `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/layout/ packages/i18n/` plus the 9 `packages/app-shell/src/views/DashboardView*.test.tsx` files gives `Test Files 271 passed (271)`, `Tests 3301 passed | 13 skipped (3314)`, `VERDICT command-exit 0`. This covers the 4 card files and every layout/i18n/DashboardView test the merge touched. - At `313b6bf8`: `designModeMenuCreate-36364.test.ts` alone gives `Tests 14 passed (14)`. - At `313b6bf8`: `pnpm --dir ui --filter @object-ui/app-shell --filter @object-ui/i18n run type-check` (both `tsc --noEmit` and `tsconfig.test.json`) gives `VERDICT command-exit 0`, 0 `error TS`. - Earlier, at `ab2257f4`: the i18n run plus the 4 card files gave 110 files and 2050 tests passing. At `0647077c`, a narrowed app-shell + i18n run found 3 failures caused by this change: zh-Hant was not regenerated, and the de quote count was 125 against 126. Both were fixed. The full app-shell suite is left to CI's `Test` shards. - New and extended pins: - `designModeMenuCreate-36364.test.ts`: 14 tests (13, plus the `order` pin). - `DesignModeMenu-36363.test.tsx`: 4 tests (the create row, Cancel writes nothing, the create-and-land flow, a refused menu). - `designMode-36362.test.tsx`: 3 tests for `saveWith`. - `DashboardView.inPageEdit-36372.test.tsx`: 3 landing tests and 2 empty-state tests. </details> <details><summary>Ablations (one-shot, not kept)</summary> - Removal of the created dashboard on a refused menu deleted (`ablation-replace`, anchor 1 to 0, restored blob equals HEAD): 3 tests red (`a refused menu removes the dashboard it was made for…`, `…cannot be removed says the dashboard was left`, `a refused menu removes the new dashboard; the mode, the held place and the other staged edits stay`). - The dashboard created before the menu-save checks: 8 of 13 red in `designModeMenuCreate-36364.test.ts`, every "nothing is created" case among them. A first attempt of this leg was refused by the tool (the replacement contained its own anchor) and ran no tests; the second attempt is the reading above. </details> ## Acceptance notes - The card's first acceptance line names the group 「数据洞察」; the CRM example's group is 「数据分析」, used for the screenshots. - 「Members see an empty state」 was checked as the admin in view mode; the empty-state branch has no role gate. A non-admin session was NOT MEASURED. - Test pins went into the existing harness files for the design mode, the menu editor and the dashboard in-page edit (AGENTS.md: a new pin for a component with a shared harness goes into that file), plus one new file for the new module, `designModeMenuCreate-36364.test.ts`. ## Verification Screenshots (live CRM example on a `--fresh` backend, console dev server, zh-CN, deviceScaleFactor 2) are stored with the seat (`objectstack-seat2/36364-shots/`): design mode; picker 「仪表盘」 with 「新建仪表盘…」 first; the name step; the new 「回款分析」 in its edit state, in the held place under 数据分析; Cancel leaving nothing; the new dashboard in view mode (「还没有卡片」); Studio 「界面」 listing the same 回款分析 in the app's navigation. After the run: the dashboard is the only item of `com.example.crm.custom`, the app's stored menu holds `nav_item_1: hui_kuan_fenxi` under `group_analytics`, no draft is pending, and the cancelled name has no item (404). Read first: `ui/packages/app-shell/src/layout/designModeMenuCreate.ts` (the order and the removal), `designMode.tsx` (`saveWith`'s drop rule after a commit), `DashboardView.tsx` (the landing effect). Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/layout/__tests__/designModeMenuCreate-36364.test.ts` shows 14 passing. <details><summary>Derived gates (head ab2257f)</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 41 commands from the tree at commit ab2257f. Each was run with stdin from /dev/null, and its exit code was captured before any pipe. The two heavy commands ran under `os-verify-lock`: `pnpm --dir ui exec vitest run scripts/` and `pnpm check:type-check-debt`. - All 41 exited 0. The reconciliation with `--ran` reads: `Run reconciliation — 41 derived, 41 run, 0 NOT-MEASURED, 0 UNRUN.` - The record is stored with the seat (`objectstack-seat2/36364-gates-ran.txt`). - Before the PR was opened, `overlap-check` gave `VERDICT clean exit 0` against origin/main and the open PR heads. - At `313b6bf8`, `dispatch-gates --commands` derives the same 41 commands as at `ab2257f4`. The merge brought no new gate family for the touched paths, so the run above was not repeated. At push, `overlap-check` against origin/main is clean; it conflicts with open PR #36629 on the serial de quote-count pin, and whichever lands second rebumps it. - CI families (lint farm, `Test` shards, `Test Core`) are left to this PR's check-runs; none was rerun locally. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPiTdmLxHXBjakSvJy)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmPiTdmLxHXBjakSvJy --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f590f3e commit dad9b55

23 files changed

Lines changed: 1096 additions & 20 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(console): a new dashboard is created from the design mode's 「Add menu item」 and opens for editing
7+
8+
Clause-②: yes (widening)
9+
Metadata-protocol: none
10+
11+
In the design mode's 「Add menu item」 picker, the 「Dashboards」 list now starts with 「New dashboard…」, above the existing dashboards that are not in the menu yet. It asks for a name only. 「Create」 creates the dashboard, empty, in the package the menu is saved to (the app's package when it is writable, else its customization package), publishes it, puts its entry in the place the editor held for it, and saves the menu with every other change staged in the mode; the mode is then left and the new dashboard opens in its page's edit state. A dashboard with no cards yet now says so on its page (「No cards yet」) instead of drawing a blank canvas, so members see an empty dashboard, not an error. 「Cancel」 writes nothing and leaves nothing in the menu. Where the menu cannot be saved (the app's package is not listed, an installed app states no version, or its customization package cannot be had or written) nothing is created. When the menu save is refused after the dashboard was created, the dashboard is removed again, the mode stays on and the reason is said. The machine name is generated from the name (a Chinese name through its pinyin), unused by any dashboard. A report cannot be created this way yet: a report needs a dataset and measures before it can be published. New `@object-ui/i18n` keys under `designMode.menu` and `dashboard.noCards`.

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

Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
* item before or after it stays open; no other entry is moved past it (a
3333
* move up, a move down or a drop onto it), since its place is that package's.
3434
*
35+
* In the picker's 「Dashboards」, the first row is 「New dashboard…」
36+
* (objectstack#36364): it asks for a name, and on 「Create」 the dashboard is
37+
* created, empty, where the menu is saved, its entry takes the dashed row's
38+
* place, and the mode saves at once, every other staged change with it
39+
* (`saveAppMenuWithNewItem`); then the mode is left and the new dashboard
40+
* opens for editing (`dashboardEditArrival`). 「Cancel」 writes nothing.
41+
*
3542
* Every edit is staged with the mode (`useDesignModeChange`), under one key
3643
* for the app's menu: the mode's 「Save」 writes it (`saveAppMenu`), its
3744
* 「Cancel」 drops it. The menu drawn is the staged one, so it survives a page
@@ -49,7 +56,8 @@
4956
*/
5057

5158
import * as React from 'react';
52-
import { Link } from 'react-router-dom';
59+
import { Link, useNavigate } from 'react-router-dom';
60+
import { toast } from 'sonner';
5361
import {
5462
DndContext,
5563
KeyboardSensor,
@@ -150,6 +158,8 @@ import {
150158
readStoredMenu,
151159
saveAppMenu,
152160
} from './designModeMenuSave.js';
161+
import { freeItemName, isNewMenuItemKind, saveAppMenuWithNewItem, type NewMenuItemKind } from './designModeMenuCreate.js';
162+
import { dashboardEditArrival } from './designModeArrival.js';
153163

154164
/**
155165
* The group label's icon-mode hiding, as the sidebar's own labels declare it
@@ -362,6 +372,51 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
362372
setAddAt(null);
363373
};
364374

375+
// objectstack#36364 — a new dashboard, in the held place: created, put in
376+
// the menu and saved with every other staged change in one act, then opened
377+
// for editing. Resolves `false` when nothing was saved (the mode has said
378+
// why); the held place and the picker stay, for another try or a cancel.
379+
const navigate = useNavigate();
380+
const saveWith = change.saveWith;
381+
const createItem = async (kind: NewMenuItemKind, label: string, taken: readonly string[]): Promise<boolean> => {
382+
if (!addAt) return false;
383+
let name: string;
384+
try {
385+
name = await freeItemName(kind, label, taken, client as never);
386+
} catch (err) {
387+
toast.error(
388+
t('designMode.saveFailed', {
389+
defaultValue: 'Some changes were not saved: {{reason}}',
390+
reason: err instanceof Error ? err.message : String(err),
391+
}),
392+
);
393+
return false;
394+
}
395+
const entry = entryFor(kind, name, newEntryId([...menu, ...(storedMenu ?? [])]));
396+
const item = { kind, name, label };
397+
const itemTexts = {
398+
...texts,
399+
itemPendingDraft: t('designMode.menu.newItemPendingDraft', {
400+
defaultValue: 'A draft with this name is already pending. Try again.',
401+
}),
402+
itemLeft: t('designMode.menu.newItemLeft', {
403+
defaultValue: 'The new dashboard "{{name}}" could not be removed again; remove it in Studio.',
404+
name: label,
405+
}),
406+
};
407+
const saved = await saveWith(insertEntry(menu, addAt.parentId, addAt.index, entry), (navigation) =>
408+
saveAppMenuWithNewItem(
409+
{ appName, packageId, served, navigation, item },
410+
itemTexts,
411+
consoleAppMenuDoors(client as never),
412+
),
413+
);
414+
if (!saved) return false;
415+
setAddAt(null);
416+
navigate(resolveHref(entry as unknown as NavigationItem, basePath).href, { state: dashboardEditArrival(name) });
417+
return true;
418+
};
419+
365420
const renderLeaf = (entry: MenuEntry, depth: number) => {
366421
const id = String(entry.id);
367422
const place = placeOf(menu, id);
@@ -467,6 +522,7 @@ export default function DesignModeMenu({ app, basePath, resolveTargetLabel, reso
467522
inMenu={menuTargets(menu)}
468523
onClose={() => setAddAt(null)}
469524
onPick={(kind, name, link) => pick(entryFor(kind, name, newEntryId([...menu, ...(storedMenu ?? [])]), link))}
525+
onCreate={createItem}
470526
language={language}
471527
/>
472528
)}
@@ -754,19 +810,39 @@ function MenuItemPicker({
754810
inMenu,
755811
onClose,
756812
onPick,
813+
onCreate,
757814
language,
758815
}: {
759816
packageId: string;
760817
inMenu: ReadonlySet<string>;
761818
onClose: () => void;
762819
onPick: (kind: MenuTargetKind, name: string, link?: { label: string; url: string }) => void;
820+
/** Create a new `kind` named `label`; `taken` is every name of that kind the picker lists. */
821+
onCreate: (kind: NewMenuItemKind, label: string, taken: readonly string[]) => Promise<boolean>;
763822
language: string;
764823
}) {
765824
const { t } = useObjectTranslation();
766825
const { rows, loading } = useTargetRows(packageId, language);
767826
const [kind, setKind] = React.useState<MenuTargetKind | null>(null);
768827
const [query, setQuery] = React.useState('');
769828
const [link, setLink] = React.useState({ label: '', url: '' });
829+
/** The kind being named for creation (objectstack#36364), `null` while picking. */
830+
const [naming, setNaming] = React.useState<NewMenuItemKind | null>(null);
831+
if (naming !== null) {
832+
return (
833+
<NewItemDialog
834+
kind={naming}
835+
onCancel={onClose}
836+
onCreate={(label) =>
837+
onCreate(naming, label, rows.filter((row) => row.kind === naming).map((row) => row.name))
838+
}
839+
/>
840+
);
841+
}
842+
// Each key written whole, so the i18n call-site gate sees every one.
843+
const newTexts: Record<NewMenuItemKind, string> = {
844+
dashboard: t('designMode.menu.newDashboard', { defaultValue: 'New dashboard…' }),
845+
};
770846
// Each key written whole, so the i18n call-site gate sees every one.
771847
const kindTexts: Record<MenuTargetKind, string> = {
772848
object: t('designMode.menu.kind.object', { defaultValue: 'Objects' }),
@@ -854,6 +930,19 @@ function MenuItemPicker({
854930
</ul>
855931
) : (
856932
<ul className="flex max-h-72 flex-col overflow-y-auto" data-testid="design-menu-picker-rows">
933+
{kind !== null && isNewMenuItemKind(kind) && (
934+
<li>
935+
<button
936+
type="button"
937+
onClick={() => setNaming(kind)}
938+
className="flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm font-medium text-primary hover:bg-accent"
939+
data-testid={`design-menu-picker-new-${kind}`}
940+
>
941+
<Plus className="h-4 w-4 shrink-0" aria-hidden="true" />
942+
<span className="flex-1 truncate">{newTexts[kind]}</span>
943+
</button>
944+
</li>
945+
)}
857946
{loading ? (
858947
<li className="px-2 py-2 text-sm text-muted-foreground">{t('designMode.menu.loading', { defaultValue: 'Loading…' })}</li>
859948
) : offered.length === 0 ? (
@@ -885,6 +974,86 @@ function MenuItemPicker({
885974
);
886975
}
887976

977+
/**
978+
* The name step of 「New dashboard…」 (objectstack#36364): a name, and
979+
* 「Create」 or 「Cancel」. 「Cancel」 (and closing the dialog) writes nothing;
980+
* 「Create」 waits on `onCreate`, and stays open with the name when it fails.
981+
*/
982+
function NewItemDialog({
983+
kind,
984+
onCancel,
985+
onCreate,
986+
}: {
987+
kind: NewMenuItemKind;
988+
onCancel: () => void;
989+
onCreate: (label: string) => Promise<boolean>;
990+
}) {
991+
const { t } = useObjectTranslation();
992+
const [label, setLabel] = React.useState('');
993+
const [busy, setBusy] = React.useState(false);
994+
const busyRef = React.useRef(false);
995+
// Each key written whole, so the i18n call-site gate sees every one.
996+
const titles: Record<NewMenuItemKind, string> = {
997+
dashboard: t('designMode.menu.newDashboardTitle', { defaultValue: 'New dashboard' }),
998+
};
999+
const submit = async () => {
1000+
const name = label.trim();
1001+
if (!name || busyRef.current) return;
1002+
busyRef.current = true;
1003+
setBusy(true);
1004+
try {
1005+
await onCreate(name);
1006+
} finally {
1007+
busyRef.current = false;
1008+
setBusy(false);
1009+
}
1010+
};
1011+
return (
1012+
<Dialog open onOpenChange={(open) => !open && !busyRef.current && onCancel()}>
1013+
<DialogContent className="sm:max-w-sm" data-testid={`design-menu-new-${kind}`}>
1014+
<DialogHeader>
1015+
<DialogTitle>{titles[kind]}</DialogTitle>
1016+
</DialogHeader>
1017+
<form
1018+
className="flex flex-col gap-3"
1019+
onSubmit={(e) => {
1020+
e.preventDefault();
1021+
void submit();
1022+
}}
1023+
>
1024+
<div className="flex flex-col gap-1.5">
1025+
<Label htmlFor="design-menu-new-name">{t('designMode.menu.name', { defaultValue: 'Name' })}</Label>
1026+
<Input
1027+
id="design-menu-new-name"
1028+
autoFocus
1029+
value={label}
1030+
disabled={busy}
1031+
onChange={(e) => setLabel(e.target.value)}
1032+
aria-describedby="design-menu-new-hint"
1033+
data-testid="design-menu-new-name"
1034+
/>
1035+
<p id="design-menu-new-hint" className="text-xs text-muted-foreground">
1036+
{t('designMode.menu.newItemSavesAll', {
1037+
defaultValue: 'Creating it saves your other design changes too, then opens it for editing.',
1038+
})}
1039+
</p>
1040+
</div>
1041+
<DialogFooter>
1042+
<Button type="button" variant="outline" onClick={onCancel} disabled={busy} data-testid="design-menu-new-cancel">
1043+
{t('common.cancel', { defaultValue: 'Cancel' })}
1044+
</Button>
1045+
<Button type="submit" disabled={busy || !label.trim()} data-testid="design-menu-new-create">
1046+
{busy
1047+
? t('designMode.menu.creating', { defaultValue: 'Creating…' })
1048+
: t('designMode.menu.create', { defaultValue: 'Create' })}
1049+
</Button>
1050+
</DialogFooter>
1051+
</form>
1052+
</DialogContent>
1053+
</Dialog>
1054+
);
1055+
}
1056+
8881057
function RenameDialog({
8891058
label,
8901059
icon,

0 commit comments

Comments
 (0)