Skip to content

Commit bd611ad

Browse files
committed
feat(spec): a report nav item without reportName opens the app's report index
Claude-Session: https://claude.ai/code/session_01WGufzhEW5k2a4Vd5KSupfu Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 57c51aa commit bd611ad

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎packages/spec/src/ui/app.test.ts‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,29 @@ describe('ReportNavItemSchema', () => {
886886
expect(item.reportName).toBe('pipeline_overview');
887887
});
888888

889-
it('should reject report nav item without reportName', () => {
890-
expect(() => ReportNavItemSchema.parse({
891-
id: 'nav_bad_report',
892-
label: 'Bad Report',
893-
type: 'report',
894-
})).toThrow();
889+
// A `report` item without `reportName` is the app's report index entry: it
890+
// parses on the variant, through the union and inside an app, and names no
891+
// report afterwards.
892+
it('accepts a report item without reportName as the app report index entry', () => {
893+
const bare = { id: 'nav_reports', type: 'report' as const };
894+
expect(ReportNavItemSchema.safeParse(bare).success).toBe(true);
895+
const item = NavigationItemSchema.parse(bare);
896+
expect(item.type).toBe('report');
897+
expect('reportName' in item).toBe(false);
898+
const app = AppSchema.safeParse({ name: 'crm', label: 'CRM', navigation: [bare] });
899+
expect(app.success).toBe(true);
900+
});
901+
902+
it('still refuses an unknown key on the index entry, and still teaches reportName on other types', () => {
903+
const misspelt = ReportNavItemSchema.safeParse({ id: 'nav_reports', type: 'report', report: 'pipeline' });
904+
expect(misspelt.success).toBe(false);
905+
const elsewhere = NavigationItemSchema.safeParse({ id: 'nav_x', type: 'page', pageName: 'p', reportName: 'r' });
906+
expect(elsewhere.success).toBe(false);
907+
expect(JSON.stringify(elsewhere.error?.issues)).toContain("type: 'report' (with reportName)");
908+
});
909+
910+
it('describes what an absent reportName opens', () => {
911+
expect(ReportNavItemSchema.shape.reportName.description).toContain('report index');
895912
});
896913
});
897914

‎packages/spec/src/ui/app.zod.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,28 @@ export const UrlNavItemSchema = lazySchema(() => strictObject(navItemSurface('ur
669669

670670
/**
671671
* 5. Report Navigation Item
672-
* Navigates to a specific report.
672+
*
673+
* ONE variant with two targets, chosen by whether `reportName` is written:
674+
*
675+
* - `{ type: 'report', reportName }` opens that report (`report/NAME`).
676+
* - `{ type: 'report' }` opens the app's report index (`reports`): the list of
677+
* the reports the app ships that the member may open, each linking to its
678+
* own route.
679+
*
680+
* The index entry is the author's to place. The console draws an index entry
681+
* only where the navigation declares one, as it draws every other entry; an
682+
* app whose navigation declares none shows no index entry.
673683
*/
674684
export const ReportNavItemSchema = lazySchema(() => strictObject(navItemSurface('report'), {
675685
...BaseNavItemSchema.shape,
676686
type: z.literal('report'),
677-
reportName: z.string().describe('Target report name'),
687+
reportName: z
688+
.string()
689+
.optional()
690+
.describe(
691+
'Target report name. Omit it and the entry opens the app\'s report index (the reports the app ships '
692+
+ 'that the member may open) instead of one report.',
693+
),
678694
}));
679695

680696
/**

0 commit comments

Comments
 (0)