Skip to content

Commit fe49404

Browse files
committed
feat(app-shell): Studio Interfaces opens a list view from 不在导航中 on its object's page; the group lists what the dropdown does not reach; a form view reads a real type
WIP: the three remaining scopes of the Interfaces view dropdown card, with their tests; not yet run. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CXDf4Yt5PtKZFbtLVD
1 parent 1c53783 commit fe49404

13 files changed

Lines changed: 1072 additions & 41 deletions
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#30046 (Scope 8) — a form view's 视图类型 reads a real type.
5+
*
6+
* The view inspector's type picker offered the LIST-view types alone (grid,
7+
* kanban, calendar, …), read off the spec's list-variant schema, for every
8+
* view it was shown on. A form view's `type` is a form layout (`simple`,
9+
* `tabbed`, `wizard`, `FormViewSchema.type`), which that roster does not
10+
* carry, so every form view read 「simple(未找到)」: its own, valid type
11+
* flagged as not found, beside list types it can never take.
12+
*
13+
* The picker now reads the roster of the view's own family: a form view's
14+
* from the spec's form-variant schema, a list view's unchanged. Both sides
15+
* are pinned, through the rendered home panel, in both designer locales.
16+
*/
17+
18+
import * as React from 'react';
19+
import { describe, it, expect, vi, afterEach } from 'vitest';
20+
import { render, screen, cleanup, fireEvent, waitFor } from '@testing-library/react';
21+
22+
const state = vi.hoisted(() => ({
23+
metadataClient: {
24+
get: vi.fn(async () => undefined),
25+
list: vi.fn(async (type: string) => (type === 'object' ? [{ name: 'crm_lead', label: 'Lead' }] : ([] as unknown[]))),
26+
},
27+
}));
28+
vi.mock('../useMetadata', async (importOriginal) => {
29+
const mod = await importOriginal<typeof import('../useMetadata')>();
30+
return { ...mod, useMetadataClient: () => state.metadataClient };
31+
});
32+
33+
import { ViewDefaultInspector } from './ViewInspector';
34+
import { t } from '../i18n';
35+
36+
afterEach(cleanup);
37+
38+
type Locale = 'en-US' | 'zh-CN';
39+
40+
/** A view item as the server serves it: `{ name, object, viewKind, config }` (ADR-0017). */
41+
function renderView(locale: Locale, viewKind: 'form' | 'list', config: Record<string, unknown>) {
42+
render(
43+
<ViewDefaultInspector
44+
type="view"
45+
name={`crm_lead.${viewKind}`}
46+
draft={{ name: `crm_lead.${viewKind}`, object: 'crm_lead', viewKind, config }}
47+
onPatch={vi.fn()}
48+
onSelectionChange={vi.fn()}
49+
readOnly={false}
50+
locale={locale as never}
51+
/>,
52+
);
53+
return screen.getByRole('combobox', { name: t('engine.inspector.view.type', locale) });
54+
}
55+
56+
/** The options the open picker offers, by their text. */
57+
async function optionsOf(trigger: HTMLElement): Promise<string[]> {
58+
fireEvent.keyDown(trigger, { key: 'ArrowDown' });
59+
await waitFor(() => expect(screen.queryAllByRole('option').length).toBeGreaterThan(0));
60+
return screen.getAllByRole('option').map((o) => (o.textContent ?? '').trim());
61+
}
62+
63+
const formType = (value: string, locale: Locale) => t(`engine.inspector.pageBlock.option.formType.${value}`, locale);
64+
const listType = (value: string, locale: Locale) => t(`engine.inspector.view.type.${value}`, locale);
65+
66+
describe('a form view’s 视图类型 reads a real type (objectstack#30046)', () => {
67+
it.each(['en-US', 'zh-CN'] as const)('%s — a form view reads its layout, never flagged as not found', async (locale) => {
68+
const trigger = renderView(locale, 'form', { type: 'simple', sections: [] });
69+
expect(trigger.textContent).toContain(formType('simple', locale));
70+
expect(trigger.textContent).not.toContain(t('engine.form.notFound', locale));
71+
// The form family's own roster, and none of the list types.
72+
expect(await optionsOf(trigger)).toEqual([formType('simple', locale), formType('tabbed', locale), formType('wizard', locale)]);
73+
});
74+
75+
it.each(['en-US', 'zh-CN'] as const)('%s — a form view with no type reads the spec’s default layout', (locale) => {
76+
const trigger = renderView(locale, 'form', { sections: [] });
77+
expect(trigger.textContent).toContain(formType('simple', locale));
78+
expect(trigger.textContent).not.toContain(listType('grid', locale));
79+
});
80+
81+
// The list-view side, unchanged: the same inspector, the list roster.
82+
it.each(['en-US', 'zh-CN'] as const)('%s — CONTROL: a list view still offers the list types', async (locale) => {
83+
const trigger = renderView(locale, 'list', { type: 'kanban', columns: ['name'] });
84+
expect(trigger.textContent).toContain(listType('kanban', locale));
85+
const offered = await optionsOf(trigger);
86+
expect(offered).toContain(listType('grid', locale));
87+
expect(offered).toContain(listType('kanban', locale));
88+
expect(offered).not.toContain(formType('simple', locale));
89+
});
90+
91+
it.each(['en-US', 'zh-CN'] as const)('%s — CONTROL: a list type the spec does not carry is still flagged', (locale) => {
92+
const trigger = renderView(locale, 'list', { type: 'simple', columns: ['name'] });
93+
expect(trigger.textContent).toContain(t('engine.form.notFound', locale));
94+
});
95+
});

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ViewVariantInspector.tsx‎

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
*
1919
* The inspector keeps a thin curated layer for two cross-cutting concerns
2020
* the spec form can't express well on its own:
21-
* 1. the VIEW TYPE picker (options sourced from the spec `type` enum), and
21+
* 1. the VIEW TYPE picker (options sourced from the spec `type` enum of the
22+
* view's own family: list types for a list view, form layouts for a
23+
* form view), and
2224
* 2. the bound OBJECT (stored at `data.object`, drives field loading).
2325
*
2426
* Column add / reorder / select lives in the live column canvas above the
@@ -160,6 +162,27 @@ function typeLabel(value: string, locale?: string): string {
160162
return translated === key ? (TYPE_LABELS[value] ?? value) : translated;
161163
}
162164

165+
/**
166+
* objectstack#30046 — English fallback labels for a FORM view's `type`, the
167+
* form layouts of the spec's `FormViewSchema.type` enum.
168+
*/
169+
const FORM_TYPE_LABELS: Record<string, string> = {
170+
simple: 'Simple',
171+
tabbed: 'Tabbed',
172+
wizard: 'Wizard',
173+
};
174+
175+
/**
176+
* objectstack#30046 — localized label for a form view's layout: the words the
177+
* page form block already gives the same enum (`FormViewSchema.type`), else
178+
* the English map, else the raw value.
179+
*/
180+
function formTypeLabel(value: string, locale?: string): string {
181+
const key = `engine.inspector.pageBlock.option.formType.${value}`;
182+
const translated = t(key, locale);
183+
return translated === key ? (FORM_TYPE_LABELS[value] ?? value) : translated;
184+
}
185+
163186
/** Keys re-pinned from the live draft after every spec-form edit. */
164187
const PRESERVED_KEYS = ['columns', 'data', 'name'] as const;
165188

@@ -189,23 +212,32 @@ function readObjectBinding(
189212
return { value: '', path: 'top' };
190213
}
191214

192-
/** Build the View-type picker's options (`InspectorSelectField`) from the spec `type` enum. */
193-
function useTypeOptions(locale?: string) {
215+
/**
216+
* Build the View-type picker's options (`InspectorSelectField`) from the spec
217+
* `type` enum of the view's own family. objectstack#30046 — a form view's
218+
* `type` is a form layout (`FormViewSchema.type`), which the list-variant
219+
* enum does not carry: read from that roster, every form view's valid type
220+
* read as not found. A list view reads the list-variant enum, as before.
221+
*/
222+
function useTypeOptions(locale: string | undefined, formFamily: boolean) {
194223
return React.useMemo(() => {
195-
const schema = getListVariantSchema();
224+
const schema = formFamily ? getFormVariantSchema() : getListVariantSchema();
196225
const rawEnum = schema?.properties?.type?.enum;
197226
const values: string[] =
198227
Array.isArray(rawEnum) && rawEnum.length
199228
? rawEnum.filter((v: unknown): v is string => typeof v === 'string')
200-
: ['grid', 'kanban', 'calendar', 'gallery', 'gantt', 'timeline'];
201-
const opts = values.map((v) => ({ value: v, label: typeLabel(v, locale) }));
229+
: formFamily
230+
? Object.keys(FORM_TYPE_LABELS)
231+
: ['grid', 'kanban', 'calendar', 'gallery', 'gantt', 'timeline'];
232+
const label = formFamily ? formTypeLabel : typeLabel;
233+
const opts = values.map((v) => ({ value: v, label: label(v, locale) }));
202234
// objectui#8488 — a `type` the spec enum does not carry used to be appended
203235
// here UNFLAGGED, so an off-spec view type read exactly like an offered
204236
// one. `InspectorSelectField` synthesises and flags it now; `typeLabel`
205237
// still gets its say through `unknownValueLabel` at the call site, since a
206238
// retired type can still have a human name in `TYPE_LABELS`.
207239
return opts;
208-
}, [locale]);
240+
}, [locale, formFamily]);
209241
}
210242

211243
export function ViewVariantInspector({
@@ -225,9 +257,12 @@ export function ViewVariantInspector({
225257
const variant = (draft[variantKey] as Record<string, unknown> | undefined) ?? {};
226258

227259
const isFormFamily = isFormFamilyKey(familyKey ?? variantKey);
260+
// objectstack#30046 — a form view without a `type` is the spec's default
261+
// layout (`FormViewSchema.type` defaults to `simple`), not a grid.
228262
const viewType =
229-
typeof variant.type === 'string' ? (variant.type as string) : 'grid';
230-
const typeOptions = useTypeOptions(locale);
263+
typeof variant.type === 'string' ? (variant.type as string) : isFormFamily ? 'simple' : 'grid';
264+
const typeOptions = useTypeOptions(locale, isFormFamily);
265+
const viewTypeLabel = isFormFamily ? formTypeLabel : typeLabel;
231266
const binding = readObjectBinding(variant, draft);
232267

233268
// Canonical label lives at the top level (`draft.label`); a list `config`
@@ -431,7 +466,7 @@ export function ViewVariantInspector({
431466
value={viewType}
432467
options={typeOptions}
433468
unknownValueLabel={(v) =>
434-
flagUnknownValue(typeLabel(v, locale), t('engine.form.notFound', locale), locale)
469+
flagUnknownValue(viewTypeLabel(v, locale), t('engine.form.notFound', locale), locale)
435470
}
436471
onCommit={(v) => writeVariant({ type: v })}
437472
disabled={readOnly}

‎ui/packages/app-shell/src/views/studio-design/InterfacesNavRail.tsx‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,48 @@ export function navOpenedItems(nodes: readonly NavNode[], locale: string): Set<s
403403
return opened;
404404
}
405405

406+
/**
407+
* objectstack#30046 — whether the 视图 group leaves `item` out: a list view
408+
* whose object a nav entry opens (`opened`, {@link navOpenedItems}), which the
409+
* entry's header dropdown reaches. A form view, a list view of an object no
410+
* entry opens, and a view whose family or object is unknown stay listed, as
411+
* does a view a read-only base's pair adds (`addedIn`), which opens at that
412+
* pair.
413+
*/
414+
export function offNavViewReachedByEntry(
415+
item: Pick<PackageSurface, 'object' | 'viewKind'> & { addedIn?: string },
416+
opened: ReadonlySet<string>,
417+
): boolean {
418+
return item.viewKind === 'list' && !!item.object && !item.addedIn && opened.has(itemKeyOf('object', item.object));
419+
}
420+
421+
/**
422+
* objectstack#30046 — the 视图 group's heading, saying what it holds once
423+
* the list views the dropdowns reach are gone: form views, list views (of
424+
* objects no entry opens), or both.
425+
*/
426+
export function offNavViewHeading(items: ReadonlyArray<Pick<PackageSurface, 'viewKind'>>, locale: string): string {
427+
const forms = items.filter((item) => item.viewKind === 'form').length;
428+
if (forms === 0) return t('engine.studio.if.offNav.view', locale);
429+
return t(forms === items.length ? 'engine.studio.if.offNav.viewForms' : 'engine.studio.if.offNav.viewMixed', locale);
430+
}
431+
432+
/**
433+
* objectstack#30046 — what a 视图 row reads: the view's label, else, for a
434+
* form view, its object's name and the word for a form ("Lead form"; a named
435+
* form adds its key), never the item name (`crm_lead.form`). `objectLabel` is
436+
* the object's name as the Studio shows it. A list view without a label keeps
437+
* its item name, as before.
438+
*/
439+
export function offNavViewLabel(item: PackageSurface, objectLabel: string, locale: string): string {
440+
const own = item.label && item.label !== item.name ? item.label : '';
441+
if (own || item.viewKind !== 'form') return own || item.name;
442+
const form = tFormat('engine.studio.if.offNav.formName', locale, { object: objectLabel });
443+
const prefix = item.object ? `${item.object}.` : '';
444+
const key = prefix && item.name.startsWith(prefix) ? item.name.slice(prefix.length) : item.name;
445+
return key === 'form' ? form : `${form} · ${key}`;
446+
}
447+
406448
/**
407449
* objectstack#26889 — the package's pages, dashboards, reports and views that
408450
* no nav entry opens (`navOpenedItems`), one collapsible section per type,
@@ -414,11 +456,22 @@ export function navOpenedItems(nodes: readonly NavNode[], locale: string): Set<s
414456
export function OffNavSections({
415457
sections,
416458
active,
459+
activeViewId = null,
417460
onPick,
418461
onlyCustomized = false,
419462
}: {
420-
sections: ReadonlyArray<{ type: OffNavType; items: ReadonlyArray<PackageSurface & { addedIn?: string }> }>;
463+
/**
464+
* objectstack#30046 — a section may name itself (`label`): the 视图 group
465+
* says what it holds. Without one, the type's own heading.
466+
*/
467+
sections: ReadonlyArray<{ type: OffNavType; label?: string; items: ReadonlyArray<PackageSurface & { addedIn?: string }> }>;
421468
active: Surface | null;
469+
/**
470+
* objectstack#30046 — the list view the open object page shows, when that
471+
* page was opened from here (an object no entry opens): its row is the
472+
* active one, as a tree row is for its entry.
473+
*/
474+
activeViewId?: string | null;
422475
onPick: (s: Surface) => void;
423476
/** objectstack#28572 — "only customizations" is on: the sections list the marked items, and head nothing. */
424477
onlyCustomized?: boolean;
@@ -432,7 +485,15 @@ export function OffNavSections({
432485
<p className="px-2 pb-1 text-[11px] text-muted-foreground">{t('engine.studio.if.offNav.heading', locale)}</p>
433486
)}
434487
{shown.map((s) => (
435-
<OffNavSection key={s.type} type={s.type} items={s.items} active={active} onPick={onPick} />
488+
<OffNavSection
489+
key={s.type}
490+
type={s.type}
491+
label={s.label}
492+
items={s.items}
493+
active={active}
494+
activeViewId={activeViewId}
495+
onPick={onPick}
496+
/>
436497
))}
437498
</div>
438499
);
@@ -441,13 +502,17 @@ export function OffNavSections({
441502
/** One type's section: its rows, open until the author closes it. */
442503
function OffNavSection({
443504
type,
505+
label,
444506
items,
445507
active,
508+
activeViewId,
446509
onPick,
447510
}: {
448511
type: OffNavType;
512+
label?: string;
449513
items: ReadonlyArray<PackageSurface & { addedIn?: string }>;
450514
active: Surface | null;
515+
activeViewId: string | null;
451516
onPick: (s: Surface) => void;
452517
}): React.ReactElement {
453518
const locale = useMetadataLocale();
@@ -457,7 +522,7 @@ function OffNavSection({
457522
return (
458523
<StudioRailGroup
459524
testId={`if-off-nav-${type}`}
460-
label={t(`engine.studio.if.offNav.${type}`, locale)}
525+
label={label ?? t(`engine.studio.if.offNav.${type}`, locale)}
461526
count={items.length}
462527
collapsed={!open}
463528
onToggle={() => setOpen((v) => !v)}
@@ -474,7 +539,7 @@ function OffNavSection({
474539
<StudioRailRow
475540
key={item.name}
476541
onClick={() => onPick(surface)}
477-
active={!!active && isSameSurface(active, surface)}
542+
active={(!!active && isSameSurface(active, surface)) || (type === 'view' && item.name === activeViewId)}
478543
indent
479544
// The label is what the row says; the machine name rides on the
480545
// tooltip with the type, as on a tree row (objectui#11862).

‎ui/packages/app-shell/src/views/studio-design/InterfacesPillar.offNavDeepLink-28561.test.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function seedWithApp() {
9696
server.published.set('view', [
9797
{ name: 'crm_lead.mine', label: 'Mine', object: 'crm_lead', viewKind: 'list', config: { type: 'grid', columns: ['name'] } },
9898
{ name: 'crm_lead.hot', label: 'Hot Leads', object: 'crm_lead', viewKind: 'list', config: { type: 'grid', columns: ['name'] } },
99+
{ name: 'crm_lead.web_form', label: 'Web Form', object: 'crm_lead', viewKind: 'form', config: { type: 'simple', sections: [] } },
99100
// The container the server keeps beside the expanded items: no item of its own.
100101
{ name: 'crm_lead', object: 'crm_lead', listViews: { hot: { columns: ['name'] } } },
101102
]);
@@ -134,11 +135,13 @@ const surfaceParam = () => new URLSearchParams(screen.getByTestId('where').textC
134135
const canvas = () => screen.findByTestId('stub-canvas', undefined, { timeout: 8000 });
135136

136137
describe('objectstack#28561 — Interfaces opens an off-nav item by `?surface=`', () => {
138+
// objectstack#30046 — a form view: a link to a LIST view lands on its
139+
// object's page instead (`InterfacesPillar.offNavListViews-30046`).
137140
it('a view no nav entry opens: the view, not the first leaf', async () => {
138141
seedWithApp();
139-
renderPillar('view:crm_lead.hot');
140-
expect(await canvas()).toHaveTextContent('view:crm_lead.hot');
141-
expect(surfaceParam()).toBe('view:crm_lead.hot');
142+
renderPillar('view:crm_lead.web_form');
143+
expect(await canvas()).toHaveTextContent('view:crm_lead.web_form');
144+
expect(surfaceParam()).toBe('view:crm_lead.web_form');
142145
});
143146

144147
it('a report and a record page no entry opens', async () => {

‎ui/packages/app-shell/src/views/studio-design/InterfacesPillar.offNavItems-26889.test.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ function seedWithApp() {
104104
server.published.set('report', [{ name: 'pipeline', label: 'Pipeline' }]);
105105
server.published.set('view', [
106106
{ name: 'crm_lead.mine', label: 'Mine', object: 'crm_lead', viewKind: 'list', config: { type: 'grid', columns: ['name'] } },
107-
{ name: 'crm_lead.hot', label: 'Hot Leads', object: 'crm_lead', viewKind: 'list', config: { type: 'grid', columns: ['name'] } },
107+
// objectstack#30046 — a form view: a list view of `crm_lead`, which an
108+
// entry opens, is reached by that entry's header dropdown and not listed
109+
// here (`InterfacesPillar.offNavListViews-30046`).
110+
{ name: 'crm_lead.web_form', label: 'Web Form', object: 'crm_lead', viewKind: 'form', config: { type: 'simple', sections: [] } },
108111
// The container the server keeps beside the expanded items: no item of its own.
109112
{ name: 'crm_lead', object: 'crm_lead', listViews: { hot: { columns: ['name'] } } },
110113
]);
@@ -156,7 +159,7 @@ describe('objectstack#26889 — Interfaces lists what no navigation entry names'
156159
'page · welcome',
157160
'dashboard · sales_overview',
158161
'report · pipeline',
159-
'view · crm_lead.hot',
162+
'view · crm_lead.web_form',
160163
]);
161164
// A draft-only page reads as the label its `_drafts` row carries.
162165
expect(within(sections).getByRole('button', { name: 'Welcome' })).toHaveAttribute('title', 'page · welcome');
@@ -188,7 +191,7 @@ describe('objectstack#26889 — Interfaces lists what no navigation entry names'
188191
renderPillar();
189192
const sections = await offNav();
190193
for (const [label, opened] of [
191-
['Hot Leads', 'view:crm_lead.hot'],
194+
['Web Form', 'view:crm_lead.web_form'],
192195
['Lead Detail', 'page:lead_detail'],
193196
['Sales Overview', 'dashboard:sales_overview'],
194197
] as const) {

0 commit comments

Comments
 (0)