Skip to content

Commit 19f4cf8

Browse files
committed
fix(app-shell): metadata-admin's report picker reaches the report index by removing reportName (#27525)
The navigation inspector's report combo offered reports only, so once a report was picked there was no way back to the index, and the only empty value the console reads as the index, `''`, is one defineStack refuses as an unknown report. The combo now leads with a "Report index" row (a new optional `emptyLabel` on InspectorComboField), and picking it removes the key, as the Studio inspector does. Pinned in AppNavInspector.reportIndexClear-27525.test.tsx. The @objectstack/cli changeset is graded minor with the PR-wide `Metadata-protocol: added` declaration. Claude-Session: https://claude.ai/code/session_01WGufzhEW5k2a4Vd5KSupfu Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fad3071 commit 19f4cf8

5 files changed

Lines changed: 153 additions & 8 deletions

File tree

‎.changeset/27525-report-nav-index-app-shell.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Metadata-protocol: added
99

1010
The console no longer injects an "All reports" row at the foot of every app's sidebar. The app's report index (`/apps/APP/reports`) is an entry its navigation declares, a `report` item with no `reportName`, drawn and highlighted like any other entry; an app whose navigation declares none shows no index entry. With no `label`, the entry shows the console's own name for the index ("All reports"). The ⌘K palette offers the declared entry, and keeps finding every report the member may open from the reports the app ships, entry or not.
1111

12-
In the Studio, a `report` entry with no report chosen reads as the report index (「报表索引」 / "Report index") instead of an unbound entry, and a save keeps it.
12+
In the Studio, a `report` entry with no report chosen reads as the report index (「报表索引」 / "Report index") instead of an unbound entry, and a save keeps it. The metadata editor's navigation inspector matches it: the report picker leads with a "Report index" row, and picking it removes `reportName` from the entry rather than saving `reportName: ''`.
1313

1414
**Migration.** An app that relied on the injected row adds one entry to its navigation where the index belongs: `{ id: 'nav_reports', type: 'report' }`.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
'@objectstack/cli': patch
2+
'@objectstack/cli': minor
33
---
44

55
docs(cli): `os explain app` says a `report` navigation item may omit `reportName` to open the app's report index
66

7-
Clause-②: no
8-
Metadata-protocol: none
7+
Clause-②: yes (widening)
8+
Metadata-protocol: added
99

10-
The `navigation` row of `os explain app` now ends its `report -> reportName` target with "(omit it on a report item to open the app's report index)", matching the widening `@objectstack/spec` ships in this release. Only the help text changes; the command's behaviour and output shape are the same.
10+
The `navigation` row of `os explain app` now ends its `report -> reportName` target with "(omit it on a report item to open the app's report index)", the widening `@objectstack/spec` ships in this release. Only the help text changes; the command's behaviour and output shape are the same. Graded `minor` because this PR declares `Metadata-protocol: added`, which sets the floor for every package it moves.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#27525 — metadata-admin's nav inspector reaches the report index
5+
* the way the Studio inspector does: by REMOVING `reportName`, never by
6+
* writing `''`.
7+
*
8+
* A `report` item with no `reportName` opens the app's report index. The
9+
* target combo offered only reports, so an author could not get back to the
10+
* index once a report was picked, and the one empty value the console reads
11+
* as the index (`''`) is a value `defineStack` refuses as an unknown report.
12+
* The combo now leads with a 「Report index」 row for a `report` item; picking
13+
* it drops the key.
14+
*
15+
* - picking the index row writes the item with no `reportName` key;
16+
* - the trigger names the index while the item has no `reportName`;
17+
* - CONTROL: picking a report still writes its name;
18+
* - CONTROL: another type's target combo offers no empty row.
19+
*/
20+
21+
import * as React from 'react';
22+
import { describe, it, expect, vi, afterEach } from 'vitest';
23+
import { render, screen, cleanup } from '@testing-library/react';
24+
import userEvent from '@testing-library/user-event';
25+
import { MetadataCtx } from '@object-ui/react';
26+
27+
// ONE client for the whole file (see AppNavInspector.labelInherits-11196).
28+
const client = vi.hoisted(() => ({
29+
list: async (type: string) =>
30+
type === 'report' ? [{ name: 'pipeline', label: 'Pipeline' }] : type === 'page' ? [{ name: 'home', label: 'Home' }] : [],
31+
}));
32+
33+
vi.mock('../useMetadata', async (importOriginal) => ({
34+
...(await importOriginal<Record<string, unknown>>()),
35+
useMetadataClient: () => client,
36+
}));
37+
38+
import { AppNavInspector } from './AppNavInspector';
39+
40+
afterEach(cleanup);
41+
42+
const METADATA = {
43+
apps: [],
44+
objects: [],
45+
dashboards: [],
46+
reports: [{ name: 'pipeline', label: 'Pipeline' }],
47+
pages: [],
48+
loading: false,
49+
error: null,
50+
refresh: async () => {},
51+
invalidate: () => {},
52+
ensureType: async () => [],
53+
getItem: async () => null,
54+
getItemsByType: () => [],
55+
getTypeStatus: () => 'ready' as const,
56+
};
57+
58+
function inspect(item: Record<string, unknown>) {
59+
const onPatch = vi.fn();
60+
render(
61+
<MetadataCtx.Provider value={METADATA as never}>
62+
<AppNavInspector
63+
type="app"
64+
name="crm"
65+
selection={{ kind: 'nav', id: 'navigation[0]' }}
66+
draft={{ name: 'crm', navigation: [item] }}
67+
onPatch={onPatch}
68+
onClearSelection={() => {}}
69+
locale="en-US"
70+
readOnly={false}
71+
/>
72+
</MetadataCtx.Provider>,
73+
);
74+
return onPatch;
75+
}
76+
77+
/** The single nav item an `onPatch` call wrote. */
78+
function written(onPatch: ReturnType<typeof vi.fn>): Record<string, unknown> {
79+
expect(onPatch).toHaveBeenCalledTimes(1);
80+
return (onPatch.mock.calls[0][0] as { navigation: Array<Record<string, unknown>> }).navigation[0];
81+
}
82+
83+
const NAMED = { id: 'nav_pipeline', type: 'report', label: 'Pipeline', reportName: 'pipeline' };
84+
const INDEX = { id: 'nav_reports', type: 'report', label: 'Reports' };
85+
86+
describe('objectstack#27525 — AppNavInspector clears a report target by removing reportName', () => {
87+
it("picking the Report index row removes the key, never writes ''", async () => {
88+
const user = userEvent.setup();
89+
const onPatch = inspect(NAMED);
90+
await user.click(screen.getByRole('combobox', { name: 'Report' }));
91+
await user.click(await screen.findByRole('option', { name: /Report index/ }));
92+
const item = written(onPatch);
93+
expect(Object.prototype.hasOwnProperty.call(item, 'reportName')).toBe(false);
94+
expect(item).toEqual({ id: 'nav_pipeline', type: 'report', label: 'Pipeline' });
95+
});
96+
97+
it('the trigger names the index while the item has no reportName', () => {
98+
inspect(INDEX);
99+
expect(screen.getByRole('combobox', { name: 'Report' }).textContent).toContain('Report index');
100+
});
101+
102+
it('CONTROL: picking a report writes its name', async () => {
103+
const user = userEvent.setup();
104+
const onPatch = inspect(INDEX);
105+
await user.click(screen.getByRole('combobox', { name: 'Report' }));
106+
await user.click(await screen.findByRole('option', { name: /pipeline/ }));
107+
expect(written(onPatch).reportName).toBe('pipeline');
108+
});
109+
110+
it("CONTROL: a page item's target combo offers no empty row", async () => {
111+
const user = userEvent.setup();
112+
inspect({ id: 'nav_home', type: 'page', label: 'Home', pageName: 'home' });
113+
await user.click(screen.getByRole('combobox', { name: 'Page' }));
114+
await screen.findByRole('option', { name: /home/ });
115+
expect(screen.queryByRole('option', { name: /Report index/ })).toBeNull();
116+
});
117+
});

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,15 @@ export function AppNavInspector({ selection, draft, name, onPatch, onClearSelect
452452
value={String((node as Record<string, unknown>)[target.targetKey] ?? '')}
453453
options={targetOptions.options}
454454
loading={targetOptions.loading}
455-
onCommit={(v) => patch({ [target.targetKey as string]: v })}
455+
// objectstack#27525 — a `report` item's empty pick is the report
456+
// index: the `reportName` key is REMOVED, as the Studio inspector
457+
// does, never written as `''`.
458+
emptyLabel={navType === 'report' ? t('engine.inspector.appNav.reportIndex', locale) : undefined}
459+
onCommit={(v) =>
460+
v === '' && navType === 'report'
461+
? patch({}, [target.targetKey as string])
462+
: patch({ [target.targetKey as string]: v })
463+
}
456464
disabled={readOnly}
457465
mono
458466
/>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ export type InspectorComboFieldProps = InspectorComboFieldNaming & {
125125
allowCustom?: boolean;
126126
/** Render the trigger value in a monospace font. */
127127
mono?: boolean;
128+
/**
129+
* The face of the empty value, for a target whose absence means something
130+
* (a `report` nav item with no `reportName` opens the report index,
131+
* objectstack#27525). Given, the list leads with a row of this text that
132+
* commits `''`, and the trigger shows it while the value is empty; the
133+
* caller decides what `''` writes. Omitted, the combo offers no way back to
134+
* empty, as before.
135+
*/
136+
emptyLabel?: string;
128137
/** Override the trigger label for the currently-selected custom value. */
129138
className?: string;
130139
};
@@ -153,6 +162,7 @@ export function InspectorComboField({
153162
loading,
154163
allowCustom = true,
155164
mono,
165+
emptyLabel,
156166
className,
157167
}: InspectorComboFieldProps) {
158168
const [open, setOpen] = React.useState(false);
@@ -177,7 +187,9 @@ export function InspectorComboField({
177187
const triggerId = label ? autoId : id;
178188

179189
const selected = options.find((o) => o.value === value);
180-
const triggerText = selected ? selected.label : value || (loading ? t('engine.inspector.combo.loading', locale) : placeholder);
190+
const triggerText = selected
191+
? selected.label
192+
: value || (emptyLabel ?? (loading ? t('engine.inspector.combo.loading', locale) : placeholder));
181193
// A chosen option with a label of its own shows that label in the body
182194
// font; only a raw value takes the caller's `mono` (objectui#12303).
183195
const selectedLabelled = !!selected && !!selected.label && selected.label !== selected.value;
@@ -241,7 +253,15 @@ export function InspectorComboField({
241253
<Command shouldFilter={false}>
242254
<CommandInput value={search} onValueChange={setSearch} placeholder={searchPlaceholder} />
243255
<CommandList>
244-
{!showCustom && filtered.length === 0 && <CommandEmpty>{emptyText}</CommandEmpty>}
256+
{!showCustom && filtered.length === 0 && !emptyLabel && <CommandEmpty>{emptyText}</CommandEmpty>}
257+
{emptyLabel && !trimmed && (
258+
<CommandGroup>
259+
<CommandItem value="__empty__" onSelect={() => commit('')}>
260+
<Check className={cn('h-3.5 w-3.5', value === '' ? 'opacity-100' : 'opacity-0')} />
261+
<span className="truncate">{emptyLabel}</span>
262+
</CommandItem>
263+
</CommandGroup>
264+
)}
245265
{showCustom && (
246266
<CommandGroup>
247267
<CommandItem value={`__custom__${trimmed}`} onSelect={() => commit(trimmed)}>

0 commit comments

Comments
 (0)