Skip to content

Commit 54aa045

Browse files
committed
test(plugin-report): pin the report export control; flip exportOptions liveness to live
Claude-Session: https://claude.ai/code/session_01JQwxbYfDeaywgrS5N1PZfg Co-authored-by: Claude <noreply@anthropic.com>
1 parent cf5bc39 commit 54aa045

3 files changed

Lines changed: 54 additions & 17 deletions

File tree

‎.changeset/25873-report-export.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/plugin-report': patch
3+
---
4+
5+
feat(plugin-report): the report page offers CSV / XLSX export of the table it draws (`exportOptions`)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`ReportSchema.exportOptions` (`{ formats?, includeHeaders?, fileNamePrefix? }`) was accepted but read by nothing, so a report table could not be downloaded. The report page now reads it:
11+
12+
- **The control.** A non-joined report draws an Export control above its body once its table has rows, offering the declared formats in order: absent means CSV and XLSX, `formats: []` draws no control.
13+
- **What is exported.** The table as drawn: the grouped table or the matrix cross-tab, its header row (dimension and measure labels as shown), its rows in the order shown and the server totals it draws. The file carries whatever the table's own query carried (the report's `runtimeFilter` and, where declared, its period); nothing is re-queried or re-aggregated. `includeHeaders: false` drops the header row.
14+
- **Who may export.** Not a report key: the control is offered only when the viewer's effective API operations on the dataset's base object include `export` (`ObjectPermission.allowExport`, the predicate the list toolbar uses). An absent operation set (no permissions provider, an unrestricted object) keeps it, as on the list.
15+
- **The files.** Both are written in the browser. The CSV is the drawn text (UTF-8 with a byte-order mark, RFC 4180 quoting; a data cell opening with a formula character is prefixed with a tab). The XLSX writes measure cells as numbers; ExcelJS is imported only when an XLSX is asked for. The file is named `fileNamePrefix`, else the report label, plus a local timestamp (the list export's file name builder).
16+
17+
`@object-ui/plugin-report` now depends on `@object-ui/permissions` and `exceljs`.

‎packages/spec/liveness/report.json‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,28 @@
8181
}
8282
},
8383
"exportOptions": {
84-
"status": "planned",
85-
"verifiedAt": "2026-10-27",
86-
"authorWarn": true,
87-
"authorHint": "Keep it, but nothing reads it yet: the Console report page draws no export control, so the report table cannot be downloaded until the report renderer reads this key.",
88-
"note": "PLANNED RECORD (#26548, the spec half of ruling 6408567749 on #25873, letter B). The report export control `{ formats?, includeHeaders?, fileNamePrefix? }`: three members of the list export block (ReportExportOptionsSchema in packages/spec/src/ui/list-view-export-options.ts), formats `csv` / `xlsx` only, on by default (absent = both, `formats: []` = off). Who may export is NOT a report key: the control is gated on the viewer having `export` in the effective apiOperations of the dataset base object (ObjectPermission.allowExport, the predicate the list toolbar uses). Refused on a `joined` container. PLANNED, not live: no renderer reads it. The report page (ui/packages/plugin-report/src/DatasetReportRenderer.tsx#DatasetReportRenderer) draws no export control, no source under ui/packages/plugin-report/src/ names `exportOptions` (0 hits outside tests), and the client-side CSV writer in ui/packages/plugin-report/src/ReportExportEngine.ts serves the legacy presentation schema, not ReportSchema. The renderer writes XLSX in the browser: the list XLSX path is the server record stream, which cannot carry aggregated report rows. Carrier: #25873. Flip to `live` on the commit that cites the renderer read point, and drop `authorWarn` / `authorHint` in that same edit.",
84+
"status": "live",
85+
"verifiedAt": "2026-10-28",
86+
"evidence": "ui/packages/plugin-report/src/ReportExport.tsx#ReportExportControl, ui/packages/plugin-report/src/DatasetReportRenderer.tsx#DatasetReportRenderer",
87+
"note": "#25873 (ruling 6408567749, letter B; spec half #26548). The report export control `{ formats?, includeHeaders?, fileNamePrefix? }`: three members of the list export block (ReportExportOptionsSchema in packages/spec/src/ui/list-view-export-options.ts), formats `csv` / `xlsx` only, on by default (absent = both, `formats: []` = off). Refused on a `joined` container, and not read there. LIVE: a non-joined report draws an Export control (ReportExport.tsx#ReportExportControl, read from DatasetReportRenderer.tsx#DatasetReportRenderer as `report.exportOptions`) once its table has rows. The download is the table AS DRAWN: the grouped table or the matrix cross-tab hands the cells it renders, server totals included, up through ReportExport.tsx#ReportTableSnapshotContext, so the file carries the active `runtimeFilter` and period of the table's own query and nothing is re-queried or re-aggregated. Who may export is NOT a report key: the control is offered only when the viewer's effective apiOperations on the dataset base object (the query answer's `object`) include `export` (ObjectPermission.allowExport, the predicate the list toolbar uses, read through `@object-ui/permissions` usePermissions); an absent operation set (no provider, an unrestricted object) keeps it, as on the list. Both files are written in the browser: the list XLSX path is the server record stream, which cannot carry aggregated report rows, so the XLSX is built with ExcelJS imported only when asked for. Pinned by ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.export-25873.test.tsx.",
8988
"children": {
9089
"formats": {
91-
"status": "planned",
92-
"verifiedAt": "2026-10-27",
93-
"evidence": "packages/spec/src/ui/list-view-export-options.ts#ReportExportOptionsSchema (declares `formats`, csv / xlsx only)",
94-
"note": "The formats the export control offers; absent = both, `[]` = off. Planned with its container: no renderer draws the control."
90+
"status": "live",
91+
"verifiedAt": "2026-10-28",
92+
"evidence": "ui/packages/plugin-report/src/ReportExport.tsx#readReportExportFormats",
93+
"note": "The formats the control offers, in the declared order; absent = csv and xlsx, `[]` draws no control."
9594
},
9695
"includeHeaders": {
97-
"status": "planned",
98-
"verifiedAt": "2026-10-27",
99-
"evidence": "packages/spec/src/ui/list-view-export-options.ts#ReportExportOptionsSchema (declares `includeHeaders`, the list export member)",
100-
"note": "Whether the download carries a header row. Planned with its container: no renderer draws the control."
96+
"status": "live",
97+
"verifiedAt": "2026-10-28",
98+
"evidence": "ui/packages/plugin-report/src/ReportExport.tsx#buildReportCsv, ui/packages/plugin-report/src/ReportExport.tsx#buildReportXlsx",
99+
"note": "Whether the download opens with the table's header row (dimension and measure labels as drawn); absent = true."
101100
},
102101
"fileNamePrefix": {
103-
"status": "planned",
104-
"verifiedAt": "2026-10-27",
105-
"evidence": "packages/spec/src/ui/list-view-export-options.ts#ReportExportOptionsSchema (declares `fileNamePrefix`, the list export member)",
106-
"note": "The download file name prefix, in place of the report label. Planned with its container: no renderer draws the control."
102+
"status": "live",
103+
"verifiedAt": "2026-10-28",
104+
"evidence": "ui/packages/plugin-report/src/ReportExport.tsx#ReportExportControl",
105+
"note": "Replaces the report label as the file name base; the name is built by `@object-ui/core` buildExportFileName (base-YYYYMMDD-HHMMSS.ext, the list export's builder)."
107106
}
108107
}
109108
},

‎ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.export-25873.test.tsx‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ import { DatasetReportRenderer } from '../DatasetReportRenderer';
3333

3434
const OBJECT = 'crm_opportunity';
3535

36+
// A result that names its `object` makes the dimension-label hook read
37+
// `/api/v1/meta/object/NAME` through the global `fetch` (no host `apiFetch`
38+
// here). Answered by ONE module-scope double that stays up for the whole file
39+
// (the network-escape guard's prescription), declaring no option fields, so
40+
// the rows are drawn exactly as the server sent them. Any other URL is refused.
41+
const META_OBJECT_ROUTE = /^\/api\/v1\/meta\/object\/(.+)$/;
42+
const strayUrls: string[] = [];
43+
vi.stubGlobal(
44+
'fetch',
45+
vi.fn(async (input: unknown) => {
46+
const url = String(input && typeof input === 'object' && 'url' in input ? (input as { url: unknown }).url : input);
47+
const m = META_OBJECT_ROUTE.exec(url);
48+
if (!m) {
49+
strayUrls.push(url);
50+
return { ok: false, status: 404, json: async () => ({}) };
51+
}
52+
return { ok: true, status: 200, json: async () => ({ item: { name: decodeURIComponent(m[1]), fields: {} } }) };
53+
}),
54+
);
55+
3656
function makeSource(result: Record<string, unknown>) {
3757
return { queryDataset: vi.fn(async () => result) };
3858
}
@@ -80,6 +100,7 @@ beforeEach(() => {
80100
afterEach(() => {
81101
cleanup();
82102
vi.restoreAllMocks();
103+
expect(strayUrls).toEqual([]);
83104
});
84105

85106
function permissions(apiOperations?: string[]): MePermissionsResponse {

0 commit comments

Comments
 (0)