Skip to content

Commit 49a078e

Browse files
fix(ui): an empty report index points at the apps that have reports (#28254)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} --> _Requested by **Tesla** · [project thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoDnVj7S3St12zLfDBXSN5gF)_ ## 维护者速读 - 改了什么:某个应用的报表首页没有任何可看的报表时(例如 Setup 的「All reports」),除了「This app has no reports you can open.」,现在还会列出你有报表可看的其它应用,每个都链接到该应用自己的报表首页。 - 为什么改:#27356 第 11 行(hotcrm#2320 Setup S11):HotCRM 浏览器走查指出 Setup 的 All reports 是一个死胡同。 - 风险与回滚:只在报表首页为空时多出一组链接;有报表的首页完全不变;侧栏入口保持静态,不做隐藏。新增一个文案键,10 个语言包都有。回滚就是 revert 本 PR。 - 先看:`appReportIndex.ts` 的 `useOtherAppsWithReports` 与 `AppReportIndexView.tsx` 空状态里的 `report-index-other-apps`。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/views/__tests__/AppReportIndex.otherApps-27356.test.tsx`,应见 2 passed。 - 需要你做的:无,席位落地。 Fixes #27356 Clause-②: no Metadata-protocol: none ## What changes - **An empty report index points somewhere.** `AppReportIndexView`'s empty state (Setup's All reports is the case HotCRM hit) keeps its title and "This app has no reports you can open.", and under it now lists, as links, the other apps whose own index has a report for the reader: "Reports in your other apps:" followed by one chip per app linking to `/apps/APP/reports`. The app's name is its served, localized label. - **Which apps.** The new `useOtherAppsWithReports` (`appReportIndex.ts`) keeps a launcher app when it is not the current app and `appShippedReports` gives it at least one report `mayOpenReport` lets the member read: the same served report list and read rule `useAppReportEntries` uses for the index itself. Each app's index still applies that app's navigation gates when it opens. While the report or dataset list is still loading it returns nothing, so no link flickers in. - **The sidebar entry stays static.** Hiding All reports in an app with no reports was the other reading of the row; it is not taken, because the index is also the route the ⌘K palette and links land on. - One new key, `console.reportIndex.otherApps`, in all ten locale packs. ## Tests - New `AppReportIndex.otherApps-27356.test.tsx` (2 tests), on the real `MetadataProvider` (a fake adapter answers `/meta/:type`), `MePermissionsProvider`, `ExpressionProvider` and `I18nProvider`, the harness of `AppReportIndex-13020`: - Setup's empty index lists CRM (a report the member may read) with href `/apps/com.example.crm/reports`, and not People (its only report reads an object the member may not read), Notes (no report) or Setup itself; - CONTROL: CRM's own index lists its reports and draws no other-apps links. <details><summary>Readings (head c2241b2, base origin/main 39da1bd unless marked; the same commit was first measured as 7b81b623 on 3a2f4c0)</summary> - New file: 2/2 passed. - Every ui test file naming `appReportIndex`, `AppReportIndexView` or `reportIndex` (10 files): 10 passed, 171/171 tests. - `pnpm --dir ui --filter @object-ui/i18n --filter @object-ui/app-shell run type-check` (both programs each, both scripts echoed): lock VERDICT command-exit 0 on 7b81b623 (the main commits between the two bases touch none of the files this diff edits or imports from app-shell/i18n; the re-run on c2241b2 is reported in the os-dev-report comment). - Ablation (on 7b81b623), through `scripts/ablation-replace.mjs`: the read rule `appShippedReports(reports, app).some((report) => mayOpenReport(report, datasetObjects, can)),` to `appShippedReports(reports, app).length > 0,`: 1 failed / 1 passed (People is offered; the control stays green); restored blob = HEAD blob `d4e7c01cfe47`, `git diff HEAD` empty. - vitest resolves `@object-ui/*` to source, so the ablation needed no rebuild leg. </details> ## Acceptance notes - **Per-row status of #27356's Setup rows** (the Studio rows 12–22 are settled, handoff 6524323618): | Row | Disposition | |---|---| | 5 | **Landed** in #28197 (Setup metadata lists take their title from the sidebar and lead with the label). | | 11 | **Taken here.** | | 10 | **Will not do on this card.** HotCRM saw Export under Display at 1440 px, not only at phone width: the bundled Display panel with Refresh and Export in its footer is the default at every width by objectui#12423's maintainer-approved design. Moving Export back to the bar or the ⋯ menu reverses that design and needs a maintainer call. | | 1 | The seat files or screens out the `domain:server` finding: Create User's params are server metadata (`create_user` on `sys_user`, platform-objects; `permissionSet` is an inline `type: 'text'` param) and the create-user door accepts no position. | | 4 | The seat files or screens out the `domain:server` finding: `POST /automation/:name/trigger` refuses a `runAs: 'system'` schedule flow for anyone but the system principal (`flowStartRefusal`); all of HotCRM's schedule flows run as system. | | 6 | The seat files or screens out the `domain:server` finding: the Users row menu is `sys_user`'s server actions; there is no deactivate verb, only Ban. | | 7 | The seat files or screens out the `domain:server` finding: "Record ID" is `sys_approval_request`'s own field label (plugin-approvals). | | 8 | The seat files or screens out the `domain:server` finding: plugin-approvals knows a request opened on its fallback approvers but persists no marker a reader can show. | Every Setup row is landed or answered, so this PR closes the card. - An app counts by its shipped reports and the read rule only; an app whose reports are all hidden by its own navigation gates is still offered, and its index then shows its own empty state. Gating every other app's navigation from here would read every app's gates on one page. - Measured in happy-dom, not in a browser. ## Verification On 7b81b623: `dispatch-gates --commands` derived 34 families for this diff; all 34 were run locally with stdin closed, each exit 0, and `--ran` reconciled 34 run, 0 NOT-MEASURED, 0 UNRUN. On c2241b2 the derivation is the identical 34-line list; its re-run is reported in the os-dev-report comment. `check:new-line-citations`: 0 new (report-only gate). 209 changed lines. The harness's after-PR assign and review-request step is skipped on the order's word (the seat lands). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L9qibwpXbWKjEuA5DF45BL Co-authored-by: Claude <noreply@anthropic.com>
1 parent 04c8930 commit 49a078e

14 files changed

Lines changed: 208 additions & 1 deletion

File tree

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+
fix(console): an empty report index points at the apps that have reports
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
An app's report index with nothing to list, such as Setup's All reports, said only "This app has no reports you can open." It now also lists the other apps whose report index has a report for the reader, each linking to that app's index: an app counts when it ships at least one report whose datasets the reader may read, the same served reports and read rule the index uses. The current app, an app that ships no report, and an app whose reports the reader may not read are not listed. The sidebar entry stays static by design. One key is added in all ten locale packs: `console.reportIndex.otherApps`.

‎ui/packages/app-shell/src/views/AppReportIndexView.tsx‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ import { useId, useState, type ReactNode } from 'react';
3636
import { Link, useParams } from 'react-router-dom';
3737
import { BarChart3, ChevronDown, ChevronRight, Loader2, Search } from 'lucide-react';
3838
import { Empty, EmptyTitle, EmptyDescription, Input, cn } from '@object-ui/components';
39-
import { useDisplayLocale, useObjectTranslation } from '@object-ui/i18n';
39+
import { useDisplayLocale, useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
40+
import { useMetadata } from '../providers/MetadataProvider.js';
41+
import { useLauncherApps } from '../hooks/useLauncherApps.js';
42+
import { appRouteSegment, resolveKeyedI18nLabel } from '../utils/index.js';
4043
import { useExpressionContext } from '../providers/ExpressionProvider.js';
4144
import { useNavMemberGates } from '../hooks/useNavMemberGates.js';
4245
import { useRecentItems } from '../context/RecentItemsProvider.js';
@@ -50,6 +53,7 @@ import {
5053
navigationObjectOrder,
5154
reportMatchesQuery,
5255
useAppReportEntries,
56+
useOtherAppsWithReports,
5357
useReportObjectLabels,
5458
type AppReportEntry,
5559
type ReportIndexView,
@@ -78,9 +82,16 @@ export function AppReportIndexView() {
7882
const [view, setView] = useWorkspacePreference(REPORT_INDEX_VIEW_PREFERENCE, 'user', DEFAULT_REPORT_INDEX_VIEW);
7983
const [query, setQuery] = useState('');
8084
const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(() => new Set());
85+
const otherAppsHeadingId = useId();
8186
const objects = [...new Set(entries.flatMap((entry) => (entry.object ? [entry.object] : [])))];
8287
const labels = useReportObjectLabels(app, objects);
8388
const title = t('console.reportIndex.title', { defaultValue: 'Reports' });
89+
// objectstack#27356 — an index with nothing to list points at the apps
90+
// whose index has something for this reader.
91+
const { apps: metadataApps } = useMetadata();
92+
const { apps: launcherApps } = useLauncherApps(metadataApps);
93+
const otherApps = useOtherAppsWithReports(launcherApps, app);
94+
const { appLabel } = useObjectLabel();
8495

8596
if (loading) {
8697
return (
@@ -172,6 +183,31 @@ export function AppReportIndexView() {
172183
defaultValue: 'This app has no reports you can open.',
173184
})}
174185
</EmptyDescription>
186+
{otherApps.length > 0 && (
187+
<nav
188+
aria-labelledby={otherAppsHeadingId}
189+
className="mt-4 flex flex-col items-center gap-2"
190+
data-testid="report-index-other-apps"
191+
>
192+
<p id={otherAppsHeadingId} className="text-sm text-muted-foreground">
193+
{t('console.reportIndex.otherApps', { defaultValue: 'Reports in your other apps:' })}
194+
</p>
195+
<ul className="flex flex-wrap justify-center gap-2">
196+
{otherApps.map((other) => (
197+
<li key={String(other.name)}>
198+
<Link
199+
to={`/apps/${appRouteSegment(other) ?? String(other.name)}/reports`}
200+
className="inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm font-medium hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
201+
data-testid={`report-index-other-app-${String(other.name)}`}
202+
>
203+
<BarChart3 className="h-4 w-4 text-muted-foreground" aria-hidden />
204+
{appLabel({ name: String(other.name), label: resolveKeyedI18nLabel(other.label, t) })}
205+
</Link>
206+
</li>
207+
))}
208+
</ul>
209+
</nav>
210+
)}
175211
</Empty>
176212
</div>
177213
) : (
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#27356 (row 11) — an app's report index with nothing to list
5+
* (Setup → All reports, "This app has no reports you can open.") points the
6+
* reader at the apps whose index has a report for them, each linking to that
7+
* app's own index.
8+
*
9+
* Pinned through the real `MetadataProvider` (a fake adapter answers
10+
* `/meta/:type`), the real `MePermissionsProvider`, `ExpressionProvider` and
11+
* `I18nProvider` in `en`, the harness of `AppReportIndex-13020`:
12+
*
13+
* - an app that ships a report the member may read is offered;
14+
* - an app whose only report reads an object the member may not read, an app
15+
* that ships no report, and the current app are not;
16+
* - CONTROL: an index that lists reports draws no such links.
17+
*/
18+
19+
import '@testing-library/jest-dom/vitest';
20+
import * as React from 'react';
21+
import { describe, it, expect, vi, beforeEach } from 'vitest';
22+
import { render, screen, cleanup, within } from '@testing-library/react';
23+
import { MemoryRouter, Route, Routes } from 'react-router-dom';
24+
import { createI18n, I18nProvider } from '@object-ui/i18n';
25+
import { MePermissionsProvider, type MePermissionsResponse } from '@object-ui/permissions';
26+
27+
vi.mock('@object-ui/auth', async (importOriginal) => ({
28+
...(await importOriginal<Record<string, unknown>>()),
29+
useAuth: () => ({ user: { id: 'u_admin' }, activeOrganization: null }),
30+
}));
31+
32+
import { MetadataProvider } from '../../providers/MetadataProvider';
33+
import { ExpressionProvider } from '../../providers/ExpressionProvider';
34+
import { AppReportIndexView } from '../AppReportIndexView';
35+
36+
const SETUP_APP = { name: 'setup', label: 'Setup', active: true, _packageId: 'com.objectstack.setup', navigation: [] };
37+
const CRM_APP = { name: 'crm', label: 'CRM', active: true, _packageId: 'com.example.crm', navigation: [] };
38+
const HR_APP = { name: 'hr', label: 'People', active: true, _packageId: 'com.example.hr', navigation: [] };
39+
const EMPTY_APP = { name: 'notes', label: 'Notes', active: true, _packageId: 'com.example.notes', navigation: [] };
40+
41+
const REPORTS = [
42+
{ name: 'crm_win_rate', label: 'Win Rate', dataset: 'ds_accounts', _packageId: 'com.example.crm' },
43+
{ name: 'hr_salaries', label: 'Salaries', dataset: 'ds_salaries', _packageId: 'com.example.hr' },
44+
];
45+
46+
const DATASETS = [
47+
{ name: 'ds_accounts', object: 'crm_account' },
48+
{ name: 'ds_salaries', object: 'hr_salary' },
49+
];
50+
51+
const ANSWER: MePermissionsResponse = {
52+
authenticated: true,
53+
userId: 'u_admin',
54+
tenantId: null,
55+
roles: [],
56+
permissionSets: ['admin'],
57+
systemPermissions: [],
58+
objects: {
59+
crm_account: { allowRead: true },
60+
hr_salary: { allowRead: false },
61+
},
62+
fields: {},
63+
};
64+
65+
function adapterFor(apps: unknown[]) {
66+
const items: Record<string, unknown[]> = { app: apps, report: REPORTS, dataset: DATASETS };
67+
return {
68+
clearCache: vi.fn(),
69+
getObjectSchema: () => Promise.resolve(null),
70+
getClient: () => ({
71+
meta: {
72+
getItems: (type: string) => Promise.resolve({ type, items: items[type] ?? [] }),
73+
getItem: () => Promise.resolve({ item: null }),
74+
},
75+
}),
76+
} as unknown as Parameters<typeof MetadataProvider>[0]['adapter'];
77+
}
78+
79+
function renderIndex(current: any) {
80+
const fetcher = vi.fn(async () => ({ ok: true, status: 200, json: async () => ANSWER }) as unknown as Response);
81+
render(
82+
<I18nProvider instance={createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false })} persistLanguage={false}>
83+
<MePermissionsProvider endpoint="/api/v1/auth/me/permissions" fetcher={fetcher as unknown as typeof fetch}>
84+
<MetadataProvider adapter={adapterFor([SETUP_APP, CRM_APP, HR_APP, EMPTY_APP])}>
85+
<ExpressionProvider app={current}>
86+
<MemoryRouter initialEntries={[`/apps/${current.name}/reports`]}>
87+
<Routes>
88+
<Route path="/apps/:appName/reports" element={<AppReportIndexView />} />
89+
</Routes>
90+
</MemoryRouter>
91+
</ExpressionProvider>
92+
</MetadataProvider>
93+
</MePermissionsProvider>
94+
</I18nProvider>,
95+
);
96+
}
97+
98+
beforeEach(() => {
99+
cleanup();
100+
localStorage.clear();
101+
sessionStorage.clear();
102+
});
103+
104+
describe('an empty report index points at the apps that have reports (objectstack#27356 row 11)', () => {
105+
it('offers the apps whose index has a report for this reader, each linking to its index', async () => {
106+
renderIndex(SETUP_APP);
107+
expect(await screen.findByText('This app has no reports you can open.')).toBeInTheDocument();
108+
const nav = await screen.findByTestId('report-index-other-apps');
109+
expect(within(nav).getByText('Reports in your other apps:')).toBeInTheDocument();
110+
const links = within(nav).getAllByRole('link');
111+
expect(links.map((a) => a.textContent)).toEqual(['CRM']);
112+
expect(links[0]).toHaveAttribute('href', '/apps/com.example.crm/reports');
113+
// Not an app whose only report the reader may not read, one with none, or this one.
114+
expect(within(nav).queryByText('People')).toBeNull();
115+
expect(within(nav).queryByText('Notes')).toBeNull();
116+
expect(within(nav).queryByText('Setup')).toBeNull();
117+
});
118+
119+
it('CONTROL: an index that lists reports draws no links to other apps', async () => {
120+
renderIndex(CRM_APP);
121+
expect(await screen.findByRole('link', { name: /Win Rate/ })).toBeInTheDocument();
122+
expect(screen.queryByTestId('report-index-other-apps')).toBeNull();
123+
});
124+
});

‎ui/packages/app-shell/src/views/appReportIndex.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,32 @@ export function useAppReportEntries(
335335
return { entries, loading: false };
336336
}
337337

338+
/**
339+
* The apps in `apps` other than `current` that ship at least one report the
340+
* member may read (objectstack#27356): where an app's empty report index sends
341+
* the reader. The list reads the same served reports and read rule as
342+
* {@link useAppReportEntries}; each app's own index still applies that app's
343+
* navigation gates when it opens. Empty while either list is loading.
344+
*/
345+
export function useOtherAppsWithReports<T extends { name?: unknown }>(apps: readonly T[], current: unknown): T[] {
346+
const metadata = useMetadata();
347+
const { can } = usePermissions();
348+
const reports = metadata.reports;
349+
const datasets = metadata.getItemsByType('dataset');
350+
const pending = (type: string) => {
351+
const status = metadata.getTypeStatus?.(type);
352+
return status === 'idle' || status === 'loading';
353+
};
354+
if (pending('report') || pending('dataset')) return [];
355+
const currentName = current && typeof current === 'object' ? (current as { name?: unknown }).name : undefined;
356+
const datasetObjects = datasetObjectIndex(datasets);
357+
return apps.filter(
358+
(app) =>
359+
app.name !== currentName &&
360+
appShippedReports(reports, app).some((report) => mayOpenReport(report, datasetObjects, can)),
361+
);
362+
}
363+
338364
/**
339365
* The object names the `type: 'object'` entries of the app's served
340366
* navigation name, in the order each is first named, at any depth: the order

‎ui/packages/i18n/src/locales/ar.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,7 @@ const ar = {
23812381
title: "التقارير",
23822382
emptyTitle: "لا توجد تقارير",
23832383
emptyDescription: "لا يحتوي هذا التطبيق على تقارير يمكنك فتحها.",
2384+
otherApps: "التقارير في تطبيقاتك الأخرى:",
23842385
viewsLabel: "طرق عرض التقارير",
23852386
viewAll: "كل التقارير",
23862387
viewRecent: "الأخيرة",

‎ui/packages/i18n/src/locales/de.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,7 @@ const de = {
21582158
title: "Berichte",
21592159
emptyTitle: "Keine Berichte",
21602160
emptyDescription: "Diese App hat keine Berichte, die Sie öffnen können.",
2161+
otherApps: "Berichte in Ihren anderen Apps:",
21612162
viewsLabel: "Berichtsansichten",
21622163
viewAll: "Alle Berichte",
21632164
viewRecent: "Zuletzt geöffnet",

‎ui/packages/i18n/src/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,7 @@ const en = {
23262326
title: 'Reports',
23272327
emptyTitle: 'No reports',
23282328
emptyDescription: 'This app has no reports you can open.',
2329+
otherApps: 'Reports in your other apps:',
23292330
viewsLabel: 'Report views',
23302331
viewAll: 'All reports',
23312332
viewRecent: 'Recent',

‎ui/packages/i18n/src/locales/es.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,7 @@ const es = {
22162216
title: "Informes",
22172217
emptyTitle: "No hay informes",
22182218
emptyDescription: "Esta aplicación no tiene informes que puedas abrir.",
2219+
otherApps: "Informes en tus otras aplicaciones:",
22192220
viewsLabel: "Vistas de informes",
22202221
viewAll: "Todos los informes",
22212222
viewRecent: "Recientes",

‎ui/packages/i18n/src/locales/fr.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,7 @@ const fr = {
22122212
title: "Rapports",
22132213
emptyTitle: "Aucun rapport",
22142214
emptyDescription: "Cette application n’a aucun rapport que vous pouvez ouvrir.",
2215+
otherApps: "Rapports dans vos autres applications :",
22152216
viewsLabel: "Vues des rapports",
22162217
viewAll: "Tous les rapports",
22172218
viewRecent: "Récents",

‎ui/packages/i18n/src/locales/ja.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,7 @@ const ja = {
21602160
title: "レポート",
21612161
emptyTitle: "レポートはありません",
21622162
emptyDescription: "このアプリには開けるレポートがありません。",
2163+
otherApps: "ほかのアプリのレポート:",
21632164
viewsLabel: "レポートビュー",
21642165
viewAll: "すべて",
21652166
viewRecent: "最近",

0 commit comments

Comments
 (0)