Skip to content

Commit c75453e

Browse files
feat(studio): one detail header and tool tabs for a metadata item (#36977)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBTuMGhLAZx29zwDrayDGZZF)_ repo:objectstack#3 · os-support-ai · session_01WGufziBCAytAzzCu3iPBFR Fixes #36901 Part of #36890 Clause-②: no Metadata-protocol: none ## 维护者速读 - 在 Studio 里打开任意一个元数据条目(以及邮件模板、翻译的表单编辑器),顶部换成统一的详情头:关闭回到列表、上一条/下一条翻阅、类型与来源包标签;原来右侧弹出的六个抽屉改成页面里的标签页(详情、预览、相关、被引用、历史、源码),草稿审阅变成头部的状态标签。 - 属于 Studio 重构总计划的第二阶段第一步,替维护者和搭建者解决"抽屉层层叠、找不到工具、刷新后丢失位置"的问题;共享标签组件留给后续三个设计器卡直接挂载。 - 出错时最可能是某个标签打不开或地址里的标签没生效,数据不会丢,保存逻辑未改;本 PR 可整体撤回,旧的抽屉地址仍能打开对应标签。 - 无。 ## What changes Studio's generic item page (`ResourceEditPage`) and the area's form editor (`StudioBundleItemEditor`: email templates, translations) now draw the shared `StudioDetailHeader` (#36892), and the six side sheets are tabs of the page. - **Header** (`metadata-admin/ResourceDetailHeader.tsx`, new): × opens the type's list with the list context (`q`, `source`, `customized`, `status`, `sort`) and the scope (`package`, `scope`) the item's address carries; ‹ › walk `useListOrderedNames(type)` and keep the open tab. Item-only params (`tab`, `review`, `open`, `sel`, `member`) never travel. Both go through `confirmUnsavedLeave`; browser Back is not intercepted. The parent path is read from the address, not the route, so the header works wherever a host mounts the page. - **Tabs** (`item-tools/ItemToolTabs.tsx`, new — the ONE shared component for #36903 / #36904 / #36905): `offeredItemToolTabs`, `defaultItemToolTab`, `useItemToolTab` (`?tab=` in the address, replace-only), `ItemToolTabStrip`, and `ItemToolTabPanel` wrapping the existing References, History (+ Audit as its second view) and Source (+ the layered diff as its second view) panels unchanged. Legacy `?tab=layers` opens Source → Layers; `?tab=audit` opens History → Audit. - **Review** is the header's amber status chip while a draft is pending; `?review=1` still opens the review sheet and is consumed. - **History route**: `/studio/PKG/metadata/TYPE/NAME/history` redirects (replace) to the item with `?tab=history`, query kept. It keeps the standalone page for a type with its own `EditPage` (the permission matrix links `./history`) and for an item a pillar's designer opens (no tab row there yet). - **Kept**: the `embedded` branch (PageShell, no tabs; review chip + actions in its actions slot), canvas-owned keys, diagnostics, the draft conflict guard, every write gate (rollback still on Save's gate, objectui#12183). - Strings: `engine.studio.itemTabs.*` (en, zh) added; `engine.edit.related` removed (its last reader was the retired Related sheet; `check:i18n-dead-keys` flagged it). ### Decision 4 — canvas types A canvas type opens on **Preview**. **Details** shows the whole-item form with the canvas-owned keys hidden as before. Both edit **one draft**, and **one Save** (header button, ⌘S, autosave) saves it whichever tab is open. Consequence: a tab switch keeps every unsaved edit, so the generic page does not prompt on a tab switch. `ItemToolTabStrip` has a `confirmSwitch` prop for a host whose tabs would drop a buffer (the designers may need it). ### Decision 15 — the "from Studio" marker Not added. This page is Studio's own address, so × always returns to Studio's list; the marker governs pages that open inside an app. ### Carrier notes from #36896 - Same-name rows (bundle members, two-holder permission sets) are one ‹ › step; the step opens the canonical member (`member` is dropped). - On `~all`, a row link carries `?package=X` and `areaLocationRedirect` re-roots onto X's leg, so ‹ › and × follow X's list. Rows of a `.custom` pair keep `?package=BASE`; rows with no package carry no package param. ### Deviations from the dispatch wording - Tab switches on the generic page do not go through `confirmUnsavedLeave` (one shared buffer, nothing is lost — see decision 4); × and ‹ › do. - The form editor has no Preview tab: its preview is a live rendering beside the form, not a canvas. - Test files outside the claim's literal surface were edited because this change turned them red (they opened the retired sheets): `metadataAreaHost.gates-28561`, `trailDoorsGate-12475`, `walledCatalogReadOnly-12183`, `StudioBundleItemEditor.customize-28569`, `StudioDesignSurface.itemTools-28239` (test only — `StudioDesignSurface.tsx` untouched), `StudioMetadataArea.routes-28561`. `ResourceDetailHeader.tsx` is a new file beside the page. ## Tests <details><summary>New and updated suites</summary> - `item-tools/ItemToolTabs.test.tsx` (new): offered tabs and order, decision-4 default, address round-trip incl. legacy values, hook + strip (seed, write, default drops `?tab=`, unknown dropped, counts, `confirmSwitch`), the three panels. - `metadata-admin/ResourceDetailHeader.test.tsx` (new): pure hrefs, ‹ › with and without list context, ×, leave guard declines and accepts, create page has no pager. - `metadata-admin/ResourceEditPage.detailTabs-36901.test.tsx` (new): plain type opens on Details; canvas type opens on Preview and a canvas edit is in the draft Source reads; `?review=1` opens the review through the chip (and CONTROL with no draft); **N2** — Esc during the non-Radix canvas fullscreen leaves fullscreen and the page stays, the next Esc is the header ×. - `ResourceEditPage.tabDeepLink-12496.test.tsx` rewritten for the tabs; `StudioBundleItemEditor.customize-28569` adds the shared-buffer + × case; `StudioMetadataArea.routes-28561` pins the redirect and both CONTROLs. </details> <details><summary>Ablation (N2)</summary> `node scripts/ablation-replace.mjs --anchor "closeOnEscape={!isFullscreen}" --replacement "closeOnEscape={true}"` on `ResourceEditPage.tsx` at 4de0ca7: mutation landed (anchor 1 → 0, blob 0aa6c36 → ad96efcc), the N2 case went red (1 failed | 4 passed), restore proven (blob == HEAD, `git diff HEAD` empty). A first attempt with replacement `closeOnEscape` was refused by the tool as a no-op (replacement count did not rise) and ran nothing. The suite imports the page from `src` (no `dist` hop). </details> ## Acceptance notes - Walked in tests: a plain type, a canvas type (registered canvas stub), the form editor (email template), `?review=1`, the old `/history` address. - Out of scope, noted only: the area's `/history` address for a designer-opened item still shows the standalone page until #36903–#36905 mount the tabs. ## Verification All readings at head `be293d754` (branch merged with `origin/main` 0212714; 2,198 changed lines, under the 3,000 Tier H line). <details><summary>Local readings</summary> - Affected set (156 files, ui vitest, `--maxWorkers=2`, under the verify lock): `Test Files 156 passed (156)`, `Tests 1407 passed (1407)`. - `pnpm --dir ui exec vitest run scripts/`: `Test Files 172 passed | 2 skipped (174)`, `Tests 5126 passed | 2 skipped (5128)`. - `pnpm --filter @object-ui/app-shell run type-check` (src + `tsconfig.test.json`): exit 0, after `@objectstack/spec` rebuilt on the merged tree. - `dispatch-gates.mjs --commands`: 39 families, all run, all exit 0 (`check:test-source-alias` was red on the first pass — new and edited suites reached a dynamic `@objectstack/lint` / editor import inside a case clock — fixed in be293d7, then exit 0). `--ran`: 39 derived, 39 run, 0 NOT-MEASURED, 0 UNRUN. - ui i18n: `check:i18n-keys` 0, `check:i18n-drift` 0, `check:i18n-dead-keys` 0 (it reported `engine.edit.related` dead after this change; removed). `check:new-line-citations`: 0 new, exit 0. </details> <details><summary>Browser walk (showcase, Chromium, private port)</summary> Built the showcase closure and the console from this branch, booted `objectstack dev --ui --seed-admin` on a private port, signed in as the seeded admin, and walked: - hook item: header (title, api name, type, package, `6 / 8`), Details pressed, no Preview tab; History writes `tab=history`, Audit view; Source → Layers writes `tab=layers`; References; › opened the next hook with `tab=references` kept; × returned to `…/metadata/hook?package=…`. - old address `…/hook/NAME/history?package=…` opened the item on the History tab (`…?package=…&tab=history`). - email template: the form editor under the header, tabs Details / Referenced by / History / Source; Source opens. - a page (canvas type) in the environment scope: the generic page opened on Preview. - 0 page errors. Translation: NOT MEASURED in the browser — the showcase ships no translation item; the bundle path is covered by `StudioBundleItemEditor.customize-28569`. </details> Two-minute check: open `/studio/PKG/metadata/hook/NAME/history` — expect the item page with the History tab pressed and the address rewritten to `…/hook/NAME?package=PKG&tab=history`. Read first (by risk): `ResourceEditPage.tsx` (the `renderFrame` / `toolTabBody` hunks and `closeOnEscape`), `item-tools/ItemToolTabs.tsx` (`useItemToolTab` address writes), `studio-design/StudioMetadataArea.tsx` (`AreaHistoryRedirect`). Session: https://claude.ai/code/session_01WGufziBCAytAzzCu3iPBFR 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufziBCAytAzzCu3iPBFR --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 586c3a2 commit c75453e

21 files changed

Lines changed: 1701 additions & 497 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): a metadata item fills the content pane under one detail header, and its tools are tabs instead of side sheets
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
Studio's generic item page and the form editor of an email template or a translation now draw the shared Studio detail header: × back to the type's list (its search, filters, sort and package scope kept), ‹ › to the previous and next item in the list's order with "index / total", the type and source package as chips, and the page's actions at the right. Both × and ‹ › ask first when the page holds unsaved edits; the browser's Back is not intercepted.
12+
13+
The six side sheets of the generic item page are tabs of the page: Details, Preview (a type with an editing canvas), Related (a type with anchors), Referenced by, History (the versions with rollback, and the audit log read inside it; shown to a caller who may read the authoring trail) and Source (the JSON source, and the layered comparison read inside it, for read-only callers too). The open tab is in the address as `?tab=`; the values the sheets wrote still open the same place (`?tab=layers` opens Source on the layers, `?tab=audit` opens History on the audit log). The draft review is a status chip in the header while a draft is pending, and `?review=1` still opens it.
14+
15+
On a type with a canvas the page opens on Preview; Details shows the whole item's form. Both edit one draft, and one Save (the header's button, ⌘S or autosave) saves it whichever tab is open, so a tab switch keeps every unsaved edit.
16+
17+
The address `/studio/PACKAGE/metadata/TYPE/NAME/history` opens the item on its History tab; the permission set, whose item page is its own matrix editor, and an item a pillar's designer opens (a flow, an object) keep the standalone history page there.
18+
19+
New in `@object-ui/app-shell`: `item-tools/ItemToolTabs.tsx` (the tab strip, the address helpers and the References, History and Source panels, for the designers to mount) and `metadata-admin/ResourceDetailHeader.tsx`. New locale keys `engine.studio.itemTabs.*` in the studio catalogue (en, zh). No metadata changes; nothing to migrate.
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#36901 (epic objectstack#36890 decision 8) — the shared item
5+
* tabs: which tabs a page offers and in what order, the tab a page opens on,
6+
* the address each tab has (the retired sheets' `layers` and `audit` still
7+
* land on their tab), the strip, and the three tool panels it wraps.
8+
*/
9+
import '@testing-library/jest-dom/vitest';
10+
import { describe, it, expect, vi, afterEach } from 'vitest';
11+
import * as React from 'react';
12+
import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react';
13+
import { MemoryRouter } from 'react-router-dom';
14+
15+
const mockClient = {
16+
references: vi.fn(async () => [{ fromType: 'view', fromName: 'all_accounts', fromLabel: 'All accounts', path: 'object' }]),
17+
history: vi.fn(async () => ({ events: [] })),
18+
audit: vi.fn(async () => ({ events: [] })),
19+
layered: vi.fn(async () => ({ code: { name: 'x', label: 'Shipped' }, overlay: null, effective: { name: 'x', label: 'Shipped' } })),
20+
};
21+
22+
vi.mock('../metadata-admin/useMetadata', async (importOriginal) => ({
23+
...(await importOriginal<typeof import('../metadata-admin/useMetadata')>()),
24+
useMetadataClient: () => mockClient,
25+
}));
26+
27+
const confirmSpy = vi.fn((go: () => unknown) => go());
28+
vi.mock('../../chrome/unsavedEdits', async (importOriginal) => ({
29+
...(await importOriginal<typeof import('../../chrome/unsavedEdits')>()),
30+
confirmUnsavedLeave: (go: () => unknown) => confirmSpy(go),
31+
}));
32+
33+
// Monaco's loader fails (offline), so the JSON source editor is its textarea.
34+
vi.mock('@monaco-editor/react', () => {
35+
const Editor = () => null;
36+
return { Editor, default: Editor, loader: { init: () => Promise.reject(new Error('offline')) } };
37+
});
38+
vi.mock('@object-ui/plugin-editor', () => ({ configureBundledMonaco: () => Promise.resolve() }));
39+
40+
import {
41+
ItemToolTabPanel,
42+
ItemToolTabStrip,
43+
defaultItemToolTab,
44+
itemToolAddress,
45+
offeredItemToolTabs,
46+
readItemToolLocation,
47+
useItemToolTab,
48+
type ItemToolTab,
49+
} from './ItemToolTabs';
50+
51+
afterEach(() => {
52+
cleanup();
53+
vi.clearAllMocks();
54+
window.history.replaceState({}, '', '/');
55+
});
56+
57+
describe('offeredItemToolTabs — which tabs, in which order', () => {
58+
it('a plain type with the trail: details, references, history, source', () => {
59+
expect(offeredItemToolTabs({ trail: true })).toEqual(['details', 'references', 'history', 'source']);
60+
});
61+
62+
it('a canvas type with anchors: preview and related take their places', () => {
63+
expect(offeredItemToolTabs({ preview: true, related: true, trail: true })).toEqual([
64+
'details',
65+
'preview',
66+
'related',
67+
'references',
68+
'history',
69+
'source',
70+
]);
71+
});
72+
73+
it('no trail: no history (the audit log rides inside it), source still offered', () => {
74+
expect(offeredItemToolTabs({ trail: false })).toEqual(['details', 'references', 'source']);
75+
});
76+
77+
it('no tools (a create draft): details alone', () => {
78+
expect(offeredItemToolTabs({ trail: true, tools: false })).toEqual(['details']);
79+
});
80+
});
81+
82+
describe('defaultItemToolTab — decision 4', () => {
83+
it('opens on the canvas where the type has one, else on the details', () => {
84+
expect(defaultItemToolTab(['details', 'preview', 'source'])).toBe('preview');
85+
expect(defaultItemToolTab(['details', 'source'])).toBe('details');
86+
});
87+
});
88+
89+
describe('the tab address', () => {
90+
const all: ItemToolTab[] = ['details', 'preview', 'related', 'references', 'history', 'source'];
91+
92+
it('the retired sheet values open their tab on its second view', () => {
93+
expect(readItemToolLocation('audit', all)).toEqual({ tab: 'history', view: 'audit' });
94+
expect(readItemToolLocation('layers', all)).toEqual({ tab: 'source', view: 'layers' });
95+
});
96+
97+
it('a tab the page does not offer, an unknown value or none opens nothing', () => {
98+
expect(readItemToolLocation('history', ['details', 'source'])).toBeNull();
99+
expect(readItemToolLocation('audit', ['details', 'source'])).toBeNull();
100+
expect(readItemToolLocation('review', all)).toBeNull();
101+
expect(readItemToolLocation(null, all)).toBeNull();
102+
});
103+
104+
it('round-trips through itemToolAddress', () => {
105+
for (const raw of ['details', 'preview', 'related', 'references', 'history', 'source', 'audit', 'layers']) {
106+
expect(itemToolAddress(readItemToolLocation(raw, all)!)).toBe(raw);
107+
}
108+
});
109+
});
110+
111+
function Harness({ offered, confirmSwitch }: { offered: ItemToolTab[]; confirmSwitch?: boolean }) {
112+
const { location, address, select } = useItemToolTab(offered);
113+
return (
114+
<div>
115+
<output data-testid="where">{`${location.tab}:${location.view ?? ''}:${address ?? ''}`}</output>
116+
<ItemToolTabStrip tabs={offered} active={location.tab} onSelect={(tab) => select(tab)} confirmSwitch={confirmSwitch} counts={{ references: 3 }} />
117+
</div>
118+
);
119+
}
120+
121+
function mountHarness(search: string, offered: ItemToolTab[], confirmSwitch?: boolean) {
122+
window.history.replaceState({}, '', `/studio/x/metadata/hook/h${search}`);
123+
render(
124+
<MemoryRouter initialEntries={[`/studio/x/metadata/hook/h${search}`]}>
125+
<Harness offered={offered} confirmSwitch={confirmSwitch} />
126+
</MemoryRouter>,
127+
);
128+
}
129+
130+
const tabParam = () => new URLSearchParams(window.location.search).get('tab');
131+
132+
describe('useItemToolTab + ItemToolTabStrip', () => {
133+
it('seeds from ?tab=, keeps the value in the address, and a click writes the new tab', async () => {
134+
mountHarness('?tab=audit', ['details', 'references', 'history', 'source']);
135+
expect(screen.getByTestId('where')).toHaveTextContent('history:audit:audit');
136+
expect(screen.getByTestId('item-tab-history')).toHaveAttribute('aria-pressed', 'true');
137+
expect(tabParam()).toBe('audit');
138+
fireEvent.click(screen.getByTestId('item-tab-source'));
139+
expect(screen.getByTestId('where')).toHaveTextContent('source::source');
140+
await waitFor(() => expect(tabParam()).toBe('source'));
141+
});
142+
143+
it('the default tab has no address: choosing it drops ?tab=', async () => {
144+
mountHarness('?tab=references', ['details', 'references', 'source']);
145+
fireEvent.click(screen.getByTestId('item-tab-details'));
146+
expect(screen.getByTestId('where')).toHaveTextContent('details::');
147+
await waitFor(() => expect(tabParam()).toBeNull());
148+
});
149+
150+
it('a value this page does not offer opens the default tab and is dropped from the address', async () => {
151+
mountHarness('?tab=history', ['details', 'references', 'source']);
152+
expect(screen.getByTestId('where')).toHaveTextContent('details::');
153+
await waitFor(() => expect(tabParam()).toBeNull());
154+
});
155+
156+
it('draws a count beside a tab', () => {
157+
mountHarness('', ['details', 'references', 'source']);
158+
expect(screen.getByTestId('item-tab-references')).toHaveTextContent('3');
159+
});
160+
161+
it('a switch asks nothing on a shared buffer, and the leave guard with confirmSwitch', () => {
162+
mountHarness('', ['details', 'references', 'source']);
163+
fireEvent.click(screen.getByTestId('item-tab-source'));
164+
expect(confirmSpy).not.toHaveBeenCalled();
165+
cleanup();
166+
mountHarness('', ['details', 'references', 'source'], true);
167+
fireEvent.click(screen.getByTestId('item-tab-source'));
168+
expect(confirmSpy).toHaveBeenCalledTimes(1);
169+
expect(screen.getByTestId('where')).toHaveTextContent('source::source');
170+
});
171+
});
172+
173+
describe('ItemToolTabPanel — the panels the sheets held, as tab bodies', () => {
174+
function Panel(props: Partial<React.ComponentProps<typeof ItemToolTabPanel>> & { tab: 'references' | 'history' | 'source' }) {
175+
const [view, setView] = React.useState(props.view);
176+
return (
177+
<MemoryRouter>
178+
<ItemToolTabPanel type="hook" name="h" onViewChange={setView} {...props} view={view} />
179+
</MemoryRouter>
180+
);
181+
}
182+
183+
it('References runs its own scan when the host holds none', async () => {
184+
render(<Panel tab="references" />);
185+
expect(await screen.findByText('all_accounts')).toBeInTheDocument();
186+
expect(mockClient.references).toHaveBeenCalledWith('hook', 'h');
187+
});
188+
189+
it('History reads the versions, and its second view is the audit log', async () => {
190+
render(<Panel tab="history" />);
191+
await waitFor(() => expect(mockClient.history).toHaveBeenCalled());
192+
expect(screen.getByTestId('item-tab-view-versions')).toHaveAttribute('aria-pressed', 'true');
193+
fireEvent.click(screen.getByTestId('item-tab-view-audit'));
194+
await waitFor(() => expect(mockClient.audit).toHaveBeenCalled());
195+
});
196+
197+
it('Source shows the host buffer read-only without onChange, and the layered view to the same caller', async () => {
198+
render(<Panel tab="source" source={{ value: { name: 'h', label: 'Mine' } }} layered={null} />);
199+
expect(screen.getByTestId('item-tab-source-readonly')).toBeInTheDocument();
200+
fireEvent.click(screen.getByTestId('item-tab-view-layers'));
201+
expect(screen.getByTestId('item-tab-view-layers')).toHaveAttribute('aria-pressed', 'true');
202+
// The host's layered answer is used as it is: no second read.
203+
expect(mockClient.layered).not.toHaveBeenCalled();
204+
});
205+
206+
it('Source without a host buffer reads the served body, read-only', async () => {
207+
render(<Panel tab="source" packageId="crm" />);
208+
await waitFor(() => expect(mockClient.layered).toHaveBeenCalledWith('hook', 'h', { packageId: 'crm' }));
209+
expect(screen.getByTestId('item-tab-source-readonly')).toBeInTheDocument();
210+
});
211+
});

0 commit comments

Comments
 (0)