Skip to content

Commit 31826d3

Browse files
fix(app-shell): clear dateRange and exportOptions when a report switches to Joined (#29260)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9Ubb8C2BwXpb9gUHV68debZjbR)_ Fixes #29195 Clause-②: no Metadata-protocol: none Claim 6574419052. ## 维护者速读 - **改了什么**:Studio 报表属性里把「报表类型」切换为「联合」时,除了原来清掉的数据集、度量、行、列、图表和排序,现在同一次修改里也清掉「日期范围」(`dateRange`)和「导出选项」(`exportOptions`)。 - **为什么改**:联合报表不接受这两个键,而切换后表单会把「期间与导出」整节隐藏。原来带着这两个键的报表切到联合后保存会被服务端拒收,拒收落在一个页面上没有任何控件能改的位置,作者无法自行修复。 - **风险与回滚**:只改类型切换到联合那一个补丁,且只清报表上本来就有的键;切回非联合类型不会恢复它们,非联合类型之间切换完全不变。没有新文案、没有规范改动。回滚即 revert 本 PR。 - **先看**:`ReportDefaultInspector.tsx` 的 `JOINED_CONTAINER_CLEARED_KEYS`;新测试 `ReportDefaultInspector.joinedClearsRefused-29195.test.tsx` 里的 "SPEC AS JUDGE" 用例(由 `ReportSchema` 判定清掉的键是否恰好等于规范拒收的键)。 - **两分钟验证**:Studio 打开一个设置了日期范围或导出选项的汇总报表,把报表类型改为「联合」并添加一个块:保存成功,保存的报表里没有 `dateRange` 与 `exportOptions`。 - **需要你做的**:无,席位落地。 ## What changes - **`JOINED_CONTAINER_CLEARED_KEYS` gains `dateRange` and `exportOptions`.** `ReportSchema`'s joined arm refuses both on the container whatever their value, `{}` included (#26548), and the report form's "Period & export" section is hidden on a joined report. The type picker's switch to Joined cleared the other six refused keys (objectui#10746) and kept these two, so a report carrying either one was sent and refused at a key no visible control reached. Both are now cleared in the same patch, the same way: an own key holding `undefined`, which the wire omits, and only when the draft carries the key. - **The list is not a second hand-kept copy of the spec's rule.** The spec exports no list of the refused keys, so the new test makes `ReportSchema` the judge: a report carrying every top-level key a non-joined report can carry is switched to Joined through the inspector, and the keys the patch clears must equal the keys `ReportSchema` refuses on the type-only switch, after which the report must parse. A coverage case holds that fixture against the spec's own property list, so a key the spec adds later must join the fixture (or the named exclusion set, with its reason) and the parse then decides whether the switch must clear it. - Switching back to a non-joined type restores nothing, and switching between two non-joined types keeps both keys. `runtimeFilter`, `drilldown` and `description` travel through the switch untouched. No spec, i18n or export change. ## Tests - `ReportDefaultInspector.joinedClearsRefused-29195.test.tsx` (new, 7 cases): the maximal matrix fixture parses (instrument); coverage against the spec's property list, excluding `blocks`, `protection`, the ADR-0010 envelope keys (`MetadataProtectionFields`) and `overrides` (`OverrideDeclarationFields`), both read from `@objectstack/spec/kernel`; the spec-as-judge case above; the card's case (a summary report with `dateRange` and `exportOptions` switched to Joined saves without them and `ReportSchema` accepts the save); an empty `dateRange` and `formats: []` are cleared too; Joined back to Summary brings neither back; Matrix to Summary keeps both. - `ReportDefaultInspector.joinedClearsBinding-10746.test.tsx`: the comment on its six-keys constant now says those are the six its draft carries and points at the new file for the whole list. No assertion changed. ## Acceptance notes - The card asks that "the server accepts the save". The test's verdict is `ReportSchema.safeParse` on the JSON-encoded draft, which is the schema the metadata save door validates a report with. It was not measured against a running server. - The coverage pin's exclusion set reads two of its groups from the spec (`MetadataProtectionFields`, `OverrideDeclarationFields`); `blocks` and `protection` are named by hand with their reason. ## Verification All on head `42c8f2b1` (base `origin/main` `45e9b2f1`, which contains `1e4841a2`). <details><summary>New tests, and the ablation that shows they fail on main's list</summary> - `vitest run` on the new file and the 10746 file: 2 files, 15/15 passed. - Ablation with `scripts/ablation-replace.mjs`, deleting the two new entries from `JOINED_CONTAINER_CLEARED_KEYS` (which leaves main's six-key list; anchor 1 to 0, blob `da0eaccf` to `c8803708`): 4 failed, 3 passed. The failures are the spec-as-judge case, the card's case, the empty-values case and the back-switch case. The three that pass are the instrument, the coverage pin and the non-joined control, which do not depend on the list. Restored: blob equals HEAD and `git diff HEAD` is empty. </details> <details><summary>Sweep, type-check and gates</summary> - Test sweep under the verify lock: every ui test file naming `ReportDefaultInspector` or `JOINED_CONTAINER_CLEARED_KEYS`, plus the 29022 and 27785 report hold files: 20 files, 131/131 passed. - `turbo run type-check --filter=@object-ui/app-shell`: 65/65 tasks, exit 0 (both `tsc --noEmit` and `tsc -p tsconfig.test.json`). - `dispatch-gates --commands`: 34 derived families, all exit 0, including `check-sdui-manifest`, `check-changeset-no-major`, `check-adr-0087-registration`, `check-closing-keyword-parity` (run against this body) and `pnpm --dir ui exec vitest run scripts/` (169 files passed, 2 skipped). `dispatch-gates --ran`: 34 derived, 34 run, 0 NOT-MEASURED. `check:new-line-citations`: 0 new. - Narrowing: the whole app-shell vitest suite is CI's Test UI; it was not run locally. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jRtcfS3JVWfX3soquJ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 344a16d commit 31826d3

4 files changed

Lines changed: 256 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): switching a report to Joined in Studio also clears its `dateRange` and `exportOptions`
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A joined report refuses a container `dateRange` and `exportOptions`, and the report form hides both once the type is Joined. The report type picker cleared the dataset binding, chart and order on that switch but kept these two, so a report that carried either one saved into a refusal at a key no visible control reached. The switch now clears them in the same patch. Switching back to a non-joined type restores neither, and switching between two non-joined types keeps both.

‎ui/packages/app-shell/src/views/metadata-admin/inspectors/ReportDefaultInspector.joinedClearsBinding-10746.test.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ const baseProps = {
7878
datasetCatalogOverride: catalog,
7979
};
8080

81-
/** The six keys the type switch clears, in the order the inspector names them. */
81+
/**
82+
* The six keys `boundDraft` carries that the type switch clears, in the order the
83+
* inspector names them. The switch also clears `dateRange` and `exportOptions`
84+
* (objectstack#29195); `ReportDefaultInspector.joinedClearsRefused-29195.test.tsx`
85+
* holds the whole list against `ReportSchema`.
86+
*/
8287
const CLEARED = ['dataset', 'values', 'rows', 'columns', 'chart', 'order'] as const;
8388
/** The four the spec's joined arm refuses on the container (objectstack PR #20160). */
8489
const SPEC_REFUSED_SELECTION = ['dataset', 'rows', 'columns', 'values'] as const;
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#29195 — switching a report to `joined` clears EVERY container key
5+
* the joined arm of `ReportSchema` refuses, `dateRange` and `exportOptions`
6+
* included, and `ReportSchema` is the judge of "every".
7+
*
8+
* The joined arm refuses a container `dateRange` and `exportOptions` whatever
9+
* their value (objectstack#26548: "a `joined` report takes no `dateRange`" /
10+
* "a `joined` report offers no export"), and the spec form's "Period & export"
11+
* section hides both on a joined report. The type picker cleared the six
12+
* selection / ordering / chart keys (objectui#10746) but not these two, so a
13+
* report that carried either one and was switched to Joined saved into a
14+
* refusal at a key no visible control reached.
15+
*
16+
* The spec exports no list of the refused keys, so this file does not keep a
17+
* second one. It builds a report carrying every top-level key a non-joined
18+
* report can carry (`MAXIMAL`), pins that fixture against the spec's own
19+
* property list (a key the spec adds later must join the fixture or the
20+
* named exclusion set), switches it to `joined` through the inspector, and
21+
* asks `ReportSchema` two things: the keys it refuses on the type-only switch
22+
* are exactly the keys the patch clears, and the switched report parses.
23+
*
24+
* Patches are read with `toStrictEqual`: `toEqual` treats an own key holding
25+
* `undefined` as absent, so it cannot tell a clear from a missing key.
26+
*/
27+
28+
import { describe, it, expect, vi, afterEach } from 'vitest';
29+
import { render, screen, cleanup } from '@testing-library/react';
30+
import userEvent from '@testing-library/user-event';
31+
import { ReportSchema } from '@objectstack/spec/ui';
32+
import { MetadataProtectionFields, OverrideDeclarationFields } from '@objectstack/spec/kernel';
33+
import { ReportDefaultInspector } from './ReportDefaultInspector';
34+
import { getReportSchema } from '../report-schema';
35+
import type { DatasetCatalogEntry } from '../previews/useDatasetCatalog';
36+
37+
afterEach(cleanup);
38+
39+
// One fetch double at MODULE scope, never torn down: `useDatasetSemantics`
40+
// fires a fire-and-forget read that no test body awaits (as in
41+
// `ReportDefaultInspector.test.tsx`).
42+
vi.stubGlobal(
43+
'fetch',
44+
vi.fn(async () => new Response('null', { status: 404, headers: { 'content-type': 'application/json' } })),
45+
);
46+
47+
const catalog: DatasetCatalogEntry[] = [
48+
{
49+
name: 'sales_metrics',
50+
label: 'Sales metrics',
51+
dimensions: [
52+
{ name: 'stage', type: 'text' },
53+
{ name: 'close_quarter', type: 'date' },
54+
],
55+
measures: [
56+
{ name: 'total_amount', aggregate: 'sum' },
57+
{ name: 'deal_count', aggregate: 'count' },
58+
],
59+
},
60+
];
61+
62+
const baseProps = {
63+
type: 'report',
64+
name: 'pipeline',
65+
locale: 'en-US' as const,
66+
onSelectionChange: vi.fn(),
67+
datasetCatalogOverride: catalog,
68+
};
69+
70+
/** One dataset-bound block: what a joined report needs before it saves. */
71+
const block = { name: 'won_deals', dataset: 'sales_metrics', rows: ['stage'], values: ['total_amount'] };
72+
73+
/**
74+
* A matrix report carrying every top-level key a non-joined report can carry,
75+
* each with a value the spec accepts there. The `coverage` case below holds it
76+
* against the spec's property list.
77+
*/
78+
const MAXIMAL: Record<string, unknown> = {
79+
name: 'pipeline',
80+
label: 'Pipeline',
81+
description: 'Won deals by stage and quarter',
82+
type: 'matrix',
83+
dataset: 'sales_metrics',
84+
rows: ['stage'],
85+
columns: ['close_quarter'],
86+
values: ['total_amount'],
87+
runtimeFilter: { stage: 'won' },
88+
order: [{ by: 'total_amount' }],
89+
drilldown: false,
90+
chart: { type: 'bar', xAxis: 'stage', yAxis: 'total_amount' },
91+
dateRange: { dimension: 'close_quarter', defaultRange: 'this_quarter', allowCustomRange: false },
92+
exportOptions: { formats: ['csv'], includeHeaders: true, fileNamePrefix: 'pipeline' },
93+
};
94+
95+
/**
96+
* Spec properties `MAXIMAL` deliberately leaves out, each read from the spec
97+
* where it can be: `blocks` is the joined report's own key (added after the
98+
* switch below); `protection` is the package author's lock block, which the
99+
* save door refuses; the ADR-0010 envelope (`MetadataProtectionFields`) is set
100+
* by the loader; `overrides` is the ADR-0146 override declaration
101+
* (`OverrideDeclarationFields`). None of them is report-type data.
102+
*/
103+
const EXCLUDED = new Set([
104+
'blocks',
105+
'protection',
106+
...Object.keys(MetadataProtectionFields),
107+
...Object.keys(OverrideDeclarationFields),
108+
]);
109+
110+
type Patch = Record<string, unknown>;
111+
112+
/** Mount on `draft`, pick `optionLabel` in the Report type control, hand back the one patch. */
113+
async function switchType(draft: Record<string, unknown>, optionLabel: string): Promise<Patch> {
114+
const onPatch = vi.fn<(patch: Patch) => void>();
115+
render(<ReportDefaultInspector {...baseProps} draft={draft} onPatch={onPatch} readOnly={false} />);
116+
await userEvent.click(screen.getByRole('combobox', { name: 'Report type' }));
117+
await userEvent.click(await screen.findByRole('option', { name: optionLabel }));
118+
expect(onPatch, 'the type picker commits exactly one patch').toHaveBeenCalledTimes(1);
119+
return onPatch.mock.calls[0][0];
120+
}
121+
122+
/** The hosts' shallow merge (`{ ...draft, ...patch }`). */
123+
const merge = (draft: Record<string, unknown>, patch: Patch): Record<string, unknown> => ({ ...draft, ...patch });
124+
125+
/** What reaches the wire: the draft JSON-encoded, as `client.save` sends a body. */
126+
const serialised = (doc: Record<string, unknown>): Record<string, unknown> => JSON.parse(JSON.stringify(doc));
127+
128+
/** Top-level keys `ReportSchema` refuses on `doc`, sorted. */
129+
function refusedTopLevelKeys(doc: Record<string, unknown>): string[] {
130+
const parsed = ReportSchema.safeParse(doc);
131+
if (parsed.success) return [];
132+
return [...new Set(parsed.error.issues.map((i) => String(i.path[0])))].sort();
133+
}
134+
135+
/** Keys a patch clears (an own key holding `undefined`), sorted. */
136+
const clearedKeys = (patch: Patch): string[] =>
137+
Object.keys(patch)
138+
.filter((k) => patch[k] === undefined)
139+
.sort();
140+
141+
describe('ReportDefaultInspector — switching to `joined` clears every key the joined arm refuses (objectstack#29195)', () => {
142+
it('INSTRUMENT: the maximal fixture is a valid non-joined report', () => {
143+
const parsed = ReportSchema.safeParse(MAXIMAL);
144+
expect(parsed.success, JSON.stringify(parsed.success ? null : parsed.error.issues)).toBe(true);
145+
});
146+
147+
it('coverage: the fixture carries every spec property except the named exclusions', () => {
148+
const specKeys = Object.keys(getReportSchema().properties ?? {}).sort();
149+
const covered = [...Object.keys(MAXIMAL), ...EXCLUDED].sort();
150+
expect(
151+
covered,
152+
'a top-level key the spec added joins MAXIMAL (with a valid non-joined value) or EXCLUDED (with its reason)',
153+
).toStrictEqual(specKeys);
154+
});
155+
156+
it('SPEC AS JUDGE: the patch clears exactly the keys `ReportSchema` refuses on a joined container, and the switched report parses', async () => {
157+
const patch = await switchType(MAXIMAL, 'Joined');
158+
// What the type alone would commit, with the blocks a joined report needs.
159+
const typeOnly = serialised({ ...MAXIMAL, type: 'joined', blocks: [block] });
160+
const refused = refusedTopLevelKeys(typeOnly);
161+
expect(refused, 'INSTRUMENT CONTROL: the spec refuses the type-only switch').toContain('dateRange');
162+
expect(clearedKeys(patch)).toStrictEqual(refused);
163+
164+
const saved = serialised({ ...merge(MAXIMAL, patch), blocks: [block] });
165+
const parsed = ReportSchema.safeParse(saved);
166+
expect(parsed.success, JSON.stringify(parsed.success ? null : parsed.error.issues)).toBe(true);
167+
// The keys the joined branch reads travel through.
168+
expect(saved).toMatchObject({ runtimeFilter: { stage: 'won' }, drilldown: false, description: MAXIMAL.description });
169+
});
170+
171+
it('THE DEFECT: a report with `dateRange` and `exportOptions` switched to `joined` saves without them, and the spec accepts the save', async () => {
172+
const draft = {
173+
name: 'pipeline',
174+
label: 'Pipeline',
175+
type: 'summary',
176+
dataset: 'sales_metrics',
177+
values: ['total_amount'],
178+
dateRange: { defaultRange: 'this_month' },
179+
exportOptions: { formats: ['csv', 'xlsx'] },
180+
blocks: [block],
181+
};
182+
const patch = await switchType(draft, 'Joined');
183+
expect(patch).toStrictEqual({
184+
type: 'joined',
185+
dataset: undefined,
186+
values: undefined,
187+
dateRange: undefined,
188+
exportOptions: undefined,
189+
});
190+
const saved = serialised(merge(draft, patch));
191+
expect(saved).not.toHaveProperty('dateRange');
192+
expect(saved).not.toHaveProperty('exportOptions');
193+
const parsed = ReportSchema.safeParse(saved);
194+
expect(parsed.success, JSON.stringify(parsed.success ? null : parsed.error.issues)).toBe(true);
195+
});
196+
197+
it('an empty `dateRange` and an export turned off are cleared too: the joined arm refuses any present value', async () => {
198+
const draft = { name: 'pipeline', label: 'Pipeline', type: 'tabular', dateRange: {}, exportOptions: { formats: [] } };
199+
const patch = await switchType(draft, 'Joined');
200+
expect(patch).toStrictEqual({ type: 'joined', dateRange: undefined, exportOptions: undefined });
201+
});
202+
203+
it('`joined` → non-joined brings neither key back: the patch is the type alone', async () => {
204+
const first = await switchType(MAXIMAL, 'Joined');
205+
const joined = { ...serialised(merge(MAXIMAL, first)), blocks: [block] };
206+
cleanup();
207+
const patch = await switchType(joined, 'Summary');
208+
expect(patch).toStrictEqual({ type: 'summary' });
209+
const committed = merge(joined, patch);
210+
expect(committed).not.toHaveProperty('dateRange');
211+
expect(committed).not.toHaveProperty('exportOptions');
212+
});
213+
214+
it('CONTROL: switching between two non-joined types keeps `dateRange` and `exportOptions`', async () => {
215+
const patch = await switchType(MAXIMAL, 'Summary');
216+
expect(patch).toStrictEqual({ type: 'summary' });
217+
expect(serialised(merge(MAXIMAL, patch))).toMatchObject({
218+
dateRange: MAXIMAL.dateRange,
219+
exportOptions: MAXIMAL.exportOptions,
220+
});
221+
});
222+
});

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ const REPORT_CURATED_FIELDS = new Set([
8686
* `blocks[]`, or delete it", PR objectstack#20160) and has always refused a
8787
* container `order` ("a `joined` report orders per block"). `chart` is inert
8888
* on a joined container (objectstack#20161) and is hidden by the same switch.
89+
* `dateRange` and `exportOptions` are keys of ONE table over ONE dataset, and
90+
* the joined arm refuses both whatever their value (objectstack#26548); the
91+
* spec form's "Period & export" section hides them on a joined report.
92+
*
93+
* The list is every container key the joined arm of `ReportSchema` refuses.
94+
* The spec exports no such list, so `ReportSchema` is the judge in the tests:
95+
* a report carrying every key a non-joined report can carry, switched to
96+
* `joined` here, must parse (`joinedClearsRefused-29195.test.tsx`).
8997
*
9098
* Why CLEAR rather than un-hide: the moment the type becomes `joined` this
9199
* inspector hides its dataset / values / rows / columns / chart controls
@@ -102,7 +110,16 @@ const REPORT_CURATED_FIELDS = new Set([
102110
* refinement skips. `runtimeFilter` and `drilldown` are deliberately NOT here:
103111
* the joined branch reads both.
104112
*/
105-
const JOINED_CONTAINER_CLEARED_KEYS = ['dataset', 'values', 'rows', 'columns', 'chart', 'order'] as const;
113+
const JOINED_CONTAINER_CLEARED_KEYS = [
114+
'dataset',
115+
'values',
116+
'rows',
117+
'columns',
118+
'chart',
119+
'order',
120+
'dateRange',
121+
'exportOptions',
122+
] as const;
106123

107124
/**
108125
* Chart types offered in the curated Chart panel. A dataset-bound report plots

0 commit comments

Comments
 (0)