Skip to content

feat(console): 「+ Filter」 under the report builder's data source - #36705

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-x3q7yh
Nov 23, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-x3q7yh

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Warren · project thread

Part of #36645 — item 1 only (「+ 筛选」 under the data source). Items 2 (show zero-count groups, waits on the maintainer's pick) and 3 (compare with the previous period, blocked by the engine card) are not touched, so the card stays open.
Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:系统管理员在报表搭建页的「数据来源」下面多了「+ 筛选」,可以按字段加条件(比如「优先级 等于 高」),图立刻按条件重画,保存后所有人看到的报表都带这个条件;以前带筛选条件的报表点「编辑」进的是旧面板,现在也进搭建页。
  • 为什么做:仪表盘和报表使用体验专题里搭建页剩下的三项之一,是维护者看过的效果图三上的那一项。
  • 出错会怎样:条件只影响这一张报表;搭建页改不了的复杂条件会原样保留、不会被改写;可以直接撤回本次合并。
  • 要你做什么:无。

What changes

The builder (ui/packages/plugin-report/src/builder/)

  • ReportBuilder takes an optional filter slot, drawn under the data source picker while a data source is bound. Host-controlled like the name box: the filterable fields are the dataset object's and the filter's conversion is the console's one shared bridge, so neither is read in this package.
  • The model's doc says what it already did: switching the data source clears runtimeFilter (the old object's fields mean nothing on the new one). Now pinned.

The console host (ui/packages/app-shell/src/views/)

  • ReportBuilderHost fills the slot with the existing FilterConditionField (the dataset designer's editor: the list toolbar's FilterBuilder behind the datasetFilterCondition bridge), bound to the report's runtimeFilter. Each committed edit lands in the draft, so the preview redraws at once; the last condition removed drops the key (no {} stored).
  • reportFilterFields.ts (new): the fields offered are the dataset OBJECT's own fields, because runtimeFilter is keyed by object fields at the dataset door (not by dimensions). Read through the data source's getObjectSchema and mapped by the list Filter panel's mapping (conditionCandidatesOf), so labels are translated, a select offers its options and a lookup its record picker. Hidden fields and virtual (formula) fields are left out (the dataset door refuses a filter on a formula field with 400 INVALID_FIELD); business fields come before system ones (so "Add filter" seeds on a business field); a record-mode amount's currency pairing is dropped because the bridge cannot hold its companion row.
  • The shared bridge datasetFilterCondition.conditionToGroup reads $and as the group only when it is the ONLY top-level key: { $and: [...], amount: {...} } or { $and: [...], $not: {...} } (valid spec shapes) are now not representable, and a logical operator in a field slot ($not) is not a row. Before, the siblings were ignored, the filter opened as editable, and the next edit dropped them. This also closes the same hole in the dataset designer.
  • FilterConditionField gains two optional props: addLabel (while empty, the trigger is a small 「+ 筛选」 link like 「+ 再分一层」; with rows it keeps the counted box) and an optional label.
  • opensInBuilder: a dataset report with a saved filter now opens in the builder when the filter is one the editor can hold (field conditions joined by AND, read by the editor's own conditionToGroup); an OR, a nested group, two operators on one field, or $and beside other keys still keep the inspector panel.

Exports and strings

  • @object-ui/plugin-list exports conditionCandidatesOf, conditionOptionsOf and the ConditionCandidateField type (the one mapping, reused rather than copied).
  • @object-ui/i18n: report.builder.source.addFilter, filterAdvanced, filterLoading, filterNoFields in all 11 locales.
  • Changeset: .changeset/36645-report-builder-filter.md (patch; plugin-report, app-shell, plugin-list, i18n).

Read first (by risk): ReportView.tsx opensInBuilder (which reports now route to the builder) · reportFilterFields.ts (which fields are offered) · FilterConditionField.tsx (shared with the dataset designer; additive props only).

Two-minute check: open any dataset report's 「编辑」, click 「+ 筛选」 → 「添加筛选」, pick a field and a value — the chart redraws at once; Save, reopen 「编辑」 — the trigger reads 「1 个条件」.

Tests

  • plugin-report reportBuilder-36374.test.tsx, new top-level describe 「the report filter under the data source (objectstack#36645)」: the slot draws under the data source only once one is bound; a filter set/cleared reaches the preview's queryDataset selection at once and the report stays spec-valid; switching data source drops the filter, re-picking the same one keeps it.
  • app-shell ReportBuilderHost.filter-36645.test.tsx (new; real host, builder, FilterConditionField, FilterBuilder): field list (hidden and formula fields out, system last, options and lookup target kept, no currency pairing); 「+ Filter」 offered and the object definition read; a condition typed is in the preview query and in what Save hands over; an existing filter opens counted, an edit saves, Clear all saves NO runtimeFilter; a filter the editor cannot hold is shown as kept and saved byte-identical, both by shape and by field type ($gt on a text field, once the fields are read).
  • app-shell datasetFilterCondition.test.ts: $and with a field or $not sibling, a non-array $and, and a top-level $not are not representable; a lone $and still round-trips.
  • app-shell ReportView.saveRefusal-11583.test.tsx: the opensInBuilder pin that asserted "a saved filter keeps the panel" is replaced by the new routing (holdable filter → builder; OR / nested / two-operator / $and with siblings / $not → panel). That old assertion encoded the premise this card changes; the other shapes it pinned (cross-tab, several values) are kept.
Local runs
  • Targeted on bdf493b: the bridge's whole inspectors/ folder plus the three files above — Test Files 251 passed (251), Tests 3297 passed | 1 skipped (3298).
  • Red without the fix: on ba67929, reverting the builder, host and routing sources turned 7 of the 8 first-round pins red; on the rework, reverting datasetFilterCondition.ts and reportFilterFields.ts turned the 3 new pins red (bridge $and siblings, routing table, field list).
  • Package suites and derived gates: reported on the thread hand-off with the head they ran on.

Acceptance notes

  • Browser run (showcase app, zh-CN, admin): on 「按状态统计工时(图表)」 「+ 筛选」 sits under 「数据来源」; 「优先级 等于 高」 redraws the bars from five statuses to two at once (the dataset query's SQL gains the priority condition). On a new report: the condition saved (runtimeFilter: { priority: { $eq: 'high' } } read back from the served report), 「编辑」 reopened in the builder with 「1 个条件」, Clear all brought back 「+ 筛选」 and the saved report carries no runtimeFilter. Six frames are attached on the project thread (GitHub's image store takes browser uploads only).
  • Pre-existing, not this PR: Save on a report that ships in an app package (the showcase's own reports) is refused 403 by the metadata write door (ADR-0146 D11: a package-shipped item must be saved into the .custom overlay package). Measured with a chart-type change and no filter on the same report — same refusal, so it is the builder's save path, not the filter. Filed as 报表编辑器保存应用包里自带的报表时返回 403,没有写到 .custom 覆盖包 #36716.
  • First cut is base-object fields only; relationship paths (account.region) are out of reach, as they are in the dataset designer's filters.
  • The field list reads the object through the console's data source with no per-field read check; the builder is admin-only today.

Verification

  • CI: the PR's check-runs on the head.
  • Screenshots: on the project thread.

Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01JQwxbXeiNLk9jGd2XxhBfz

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 23, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj

Contract review

Served-tier: TIER_DEFAULT
Head-sha: ba6792906cef46be53570f5847e1dfb87d5d153e
Local-runs: none
Scope: whole diff against merge base 4034a6d2f8: .changeset/36645-report-builder-filter.md, ui/packages/plugin-list/src/index.tsx, ui/packages/plugin-report/src/builder/ReportBuilder.tsx, ui/packages/plugin-report/src/builder/reportBuilderModel.ts, ui/packages/plugin-report/src/__tests__/reportBuilder-36374.test.tsx, ui/packages/app-shell/src/views/ReportBuilderHost.tsx, ui/packages/app-shell/src/views/reportFilterFields.ts, ui/packages/app-shell/src/views/ReportView.tsx, ui/packages/app-shell/src/views/metadata-admin/inspectors/FilterConditionField.tsx, ui/packages/app-shell/src/views/ReportBuilderHost.filter-36645.test.tsx, ui/packages/app-shell/src/views/ReportView.saveRefusal-11583.test.tsx, ui/packages/i18n/src/locales/*.ts (11). Cited, read only: ui/packages/app-shell/src/views/metadata-admin/inspectors/datasetFilterCondition.ts, ui/packages/plugin-list/src/ListView.tsx (conditionCandidatesOf, filterConditionFieldsOf), ui/packages/components/src/custom/filter-builder.tsx, packages/services/service-analytics/src/dataset-filter-field-binding.ts, packages/services/service-analytics/src/read-scope-sql.ts, packages/objectql/src/filter-comparand-shape.ts, packages/spec/src/data/filter.zod.ts (FilterConditionSchema), .changeset/config.json, AGENTS.md step 3
Security-touching: no
Rule-change-verified: none

The head did not move during the review. Everything below comes from reading the diff and the tree. I ran nothing. CI on the head is green: every check-run is success or skipped.

① Derived judgments

The widening is minimal and additive. @object-ui/plugin-list index.tsx adds two value exports (conditionCandidatesOf, conditionOptionsOf) and one type export (ConditionCandidateField). All three already existed as exports of the ListView module. No body changed. Nothing was removed or renamed. The changeset names exactly these three. ReportBuilderProps.filter?: React.ReactNode is a new optional prop, so every existing caller is unaffected. The label that became optional on FilterConditionField is not on the published surface: app-shell's exports maps only . and ./styles.css, and its index does not reach the component. The widening has a reason. The dataset designer's own field list has no option pickers or lookup target. Reusing the list's one mapping avoids writing a second copy.

Declarations: correct. Clause-②: yes (widening) and Metadata-protocol: none appear at line start in both the PR body and the changeset. none is true: runtimeFilter is already a spec key, and no key, value or type moves. Each of the 11 locales gains exactly the four keys the changeset names.

Round trip of a holdable filter: exact. FilterBuilder emits nothing on read (its read boundary only re-seeds state). FilterConditionField commits only from the builder's onChange. So opening a report, and opening the popover, never writes the draft. Save passes the draft object as it is. An edit rewrites only spelling: {stage:'won'} becomes {stage:{$eq:'won'}}, and a single-member $and collapses. The meaning is the same.

Last condition removed drops the key: yes. An empty group passes isClearedGroup, onCommit(undefined) runs, and commitFilter deletes runtimeFilter. An unfinished seeded row commits nothing. The Clear-all path is pinned. The remove-row path takes the same branch.

Unholdable filter saved byte-identical: yes, for the shapes the bridge recognises. When representable is false, the field shows only a note and has no commit path. The draft keeps the same reference, so Save sends the same bytes. Exception: see M1.

Does opening ever rewrite? No. Nothing commits on open. But one valid shape is read wrongly and is lost on the next edit (M1).

Pins fail without the fix: consistent by reading. Without the change, these fail:

  • the two slot and preview pins in reportBuilder-36374 (the slot is not drawn);
  • four of the five host pins (no 「+ Filter」 and no note);
  • the new opensInBuilder pin (its true cases).

That is 7, the thread's number. Two pins pass on base, and that is right: the pure reportFilterFields pin, and the pickDataset pin, which only pins existing behaviour (base already deletes runtimeFilter on a switch). I read this and did not run it.

Fields the door won't lower. Relationship paths are not offered. The door binds a bare object-field key past a shadowing dimension (bindDatasetFiltersToObjectFields). So for stored fields, the list matches what the door lowers. Two gaps remain: S1 (virtual fields) and N3 (readability).

② Semver level

  • All four moved packages are graded patch: plugin-report, app-shell, plugin-list, i18n.
  • patch is right. AGENTS.md step 3: a non-protocol change, widening or breaking, ships patch. Metadata-protocol: none takes patch.
  • The @object-ui/* packages are one fixed group in .changeset/config.json. So app-shell's workspace:^ peer on plugin-list always resolves to a version that has the new exports.
  • There is no BREAKING banner and no ADR-0087 marker, and none is owed.

③ Boundary flags

  • $and with sibling keys is read as holdable (M1). conditionToGroup (datasetFilterCondition.ts line 406) reads only cond.$and whenever it is an array. Any other top-level key is ignored. Examples: { $and: [{stage:'won'}], amount: {$gt: 5} } or { $and: [...], $not: {...} }. Both are valid spec shapes, because FilterConditionSchema is a record intersected with optional $and/$or/$not. The read says representable: true, so opensInBuilder now routes such a report to the builder. The trigger reads "1 condition". The first edit to any row commits only the $and rows, and Save stores a wider filter. Nothing tells the author. Before this PR, every report with a filter opened the panel, so this path is new for reports.
  • Shape-holdable but field-unholdable (N1). opensInBuilder decides on shape alone. A filter like {amount:{$in:[1,2]}} on a number field opens the builder. There it reads unrepresentable and shows "cannot be changed here", and the report no longer reaches the panel that could edit it. It is kept, not rewritten. The PR body says so. The same note also shows while fields load, and stays forever if getObjectSchema fails (N2).
  • Error shape, SQL pushdown: no new id materialisation and no in-app join. The only new read is one getObjectSchema per bound object.
  • No test weakened. One opensInBuilder assertion ("a saved filter keeps the panel") is replaced. It encoded the premise this card changes. The cross-tab and several-values assertions stay.
  • Author: objectstack-fleet[bot], so no login note.

④ Design judgment

The slot design is right. The builder stays field-agnostic, and the host supplies the one shared editor and the one shared field mapping. pickDataset already drops the filter on a switch. It is wrong to rely on the shared bridge's shape read without first checking that it covers the whole spec shape. M1 is that gap.

  • M1 (must-fix) — A saved runtimeFilter with $and beside other top-level keys is silently narrowed on the next edit. conditionToGroup drops the sibling keys of $and and still calls the result representable. So opensInBuilder routes the report to the builder, the editor shows only the $and rows, and the first edit plus Save loses the sibling conditions. The report then shows more rows. This breaks the PR's own claim that an unholdable filter is kept byte-identical. Fix in the shared bridge: when $and is present, require it to be the only key, else return representable: false. Add two pins: the opensInBuilder table ({ $and:[…], x:… } and { $and:[…], $not:… } keep the panel) and a bridge round-trip pin. The fix also closes the same hole in the dataset designer.
  • S1 (should-fix) — The builder offers virtual (formula) fields, and the dataset door refuses a filter on one. reportFilterFields drops only hidden. The engine's admission (filter-comparand-shape.ts, reached from the analytics path per read-scope-sql.ts) refuses a filter on a field that isVirtualSearchField matches, with 400 INVALID_FIELD. The author sees the preview fail, but can still save a report that then fails for every viewer. Fix: leave out isVirtualSearchField fields in reportFilterFields, as the list already does for grouping, and add one line to the field-list pin.

Notes:

  • N1. A filter that holds by shape but not by field type now opens the builder with a "kept" note and can no longer reach the panel. Consider passing the fields to the routing decision, or having the note say where to edit. Not a data risk.
  • N2. While fields load (fields = []), a non-text operator reads against the default text bucket and briefly shows the "cannot be changed here" note. If the schema read fails, the note stays. Also, while the catalog has not yet named the object, loading reports false, so the popover would say "no fields" rather than "loading".
  • N3. Fields are not narrowed by canReadField, as the list's filterConditionFieldsOf does. The door's field-read admission refuses an unreadable field, and the builder is admin-only. The PR body says this. Not security-touching.
  • N4. A stored condition on a hidden field (for example organization_id), or on a dotted path, draws a row whose field is not in the dropdown. The list keeps such a held field listed so its row is not blank. The value is kept on save.
  • N5. The "unholdable, kept byte-identical" pin uses toEqual on a shape that opensInBuilder already routes to the panel. A field-unholdable case (for example $gt on a text field) would pin the in-builder path more directly.

Implemented-by: objectstack-fleet[bot] (session 01JQwxbXeiNLk9jGd2XxhBfz)
Reviewed-by: session_01JQwxbZeHNsF3RWcWpj7rGj

VERDICT: FAIL

…er no formula fields

The shared filter bridge read only the $and rows of a filter that also has
other top-level keys and called it editable, so the report builder (and the
dataset designer) opened it where the next edit would drop the siblings. It
now needs $and to be the only key, and a logical operator in a field slot is
not a row. The report filter no longer offers virtual (formula) fields, which
the dataset door refuses.

Claude-Session: https://claude.ai/code/session_01JQwxbXeiNLk9jGd2XxhBfz
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the tests label Nov 23, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj

Contract review

Served-tier: TIER_DEFAULT
Head-sha: bdf493b77bb873bddad2f487b8ab7a3e58984eca
Local-runs: none
Scope: the delta ba67929..bdf493b (one commit, 6 files: .changeset/36645-report-builder-filter.md, datasetFilterCondition.ts and its .test.ts, reportFilterFields.ts, ReportBuilderHost.filter-36645.test.tsx, ReportView.saveRefusal-11583.test.tsx) plus, read only: the rest of conditionToGroup and groupToCondition, ReportView.tsx opensInBuilder, FilterConditionField.tsx, packages/spec/src/data/search-fields.ts (isVirtualSearchField, SEARCH_VIRTUAL_TYPES), packages/spec/package.json (./data), ui/packages/app-shell/package.json, ui/packages/plugin-list/src/ListView.tsx (conditionCandidatesOf), the PR body.
Security-touching: no
Rule-change-verified: none

The PR head is still bdf493b7. I ran nothing; everything here comes from reading the code. CI on the head is still running. 9 checks passed and 15 were skipped. 19 are in progress, including Type Check UI, Lint UI and Check Changeset. None has failed.

Round-1 items

  • M1 (must-fix): closed. conditionToGroup has a new guard just after the $or check. If $and is present, it must be the only key and must be an array; otherwise the result is representable: false. A second new guard rejects a row whose key starts with $, so $not is caught at top level and inside $and.
    • The $and + amount and $and + $not shapes now keep the panel. So does a non-array $and.
    • A lone $and array takes the same path as before.
    • groupToCondition writes only three shapes: undefined, one row, or a lone { $and: parts }. All three still read back as holdable. The new control pin shows this: a two-row lone $and reads representable: true, and groupToCondition gives it back unchanged (toEqual).
    • The bridge pin covers five shapes. The $and-with-siblings cases and { $not: { $eq } } would have read as holdable before this fix. The other cases already failed on base through readBackOperator and act as controls.
    • The opensInBuilder table has three new false rows: $and + field, $and + $not, and a lone $not.
    • Dataset designer: nothing changes for valid shapes. The only shapes that change are the misread ones above and a field key starting with $. No real field name starts with $. No existing test asserts a $-keyed row.
  • S1 (should-fix): closed. reportFilterFields now skips any field where isVirtualSearchField is true. This uses the spec's own predicate, which is true only for formula. It is imported from @objectstack/spec/data. That subpath is exported, and app-shell already depends on @objectstack/spec and imports from it elsewhere. The field-list pin adds a weighted formula field and keeps the expected list ['name','stage','amount','account']. conditionCandidatesOf does not drop formula fields itself, so this pin would fail without the fix.

Declarations, exports, tests

  • Declarations. Clause-②: yes (widening) and Metadata-protocol: none still start their lines in both the changeset and the PR body. Both are still true: this round changes no protocol key and widens nothing new. The changeset adds two bullets that match the change. All four packages are still patch.
  • No new export. No index or exports map changed. reportFilterFields.ts and datasetFilterCondition.ts gained no exported symbol.
  • No test weakened. The only removed line is the old title of the field-list test; its assertion is unchanged. Every other test change is an addition. A new host pin covers a filter that holds by shape but not by field type: { name: { $gt: 'M' } } on a text field shows the "kept" note and saves the same filter (toEqual). That answers round-1 N5.

No must-fix, no should-fix.

  • N6. Round-1 notes N1–N4 are unchanged by this delta. None of them is a data risk.

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-warren · session_01JQwxbZeHNsF3RWcWpj7rGj

维护者速读

报表编辑器的数据来源下面加了「+ 筛选」:选完数据来源可以直接加条件(比如只看本季度、只看某个负责人),优先列出业务字段,公式字段不出现。条件编辑器复用列表页已有的那一个,不另做一套。#36645 的第 2 项(显示数量为 0 的分组)已按你的选择单开成 #36722,第 3 项(和上一期对比)还在等引擎卡 #35395,所以这张卡先不关。
要你做的:无。

席位核对 — ACCEPT (L1) · repo:objectstack#1 · head eb351d17 · 2026-11-23T14:27Z

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 23, 2026 14:27
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit c54aa57 Nov 23, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-x3q7yh branch November 23, 2026 14:48
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…od chip (objectstack-ai#36767)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Hx43jgsjNPA5ohr5yAhkBL)_

Fixes objectstack-ai#36645 — item 3 (「和上一期对比」). Item 1 shipped in objectstack-ai#36705; item 2 moved
to its own card, objectstack-ai#36722; so this closes the card.
Clause-②: yes (widening)
Metadata-protocol: none

## 维护者速读

-
用户能看到什么变化:报表上方的时间范围旁边多了一个「和上一期对比」开关,和「之前同样长的一段时间」比。打开后,按类别分组的柱状图、折线图(比如按状态)每组旁边多一根浅色柱,就是上一期的数;「数字」图在数字下面写「较上期
3(+133.3%)」。横轴本身就是按月/按周的日期时,不提供这个开关,因为两段时间的月份数可能不一样,柱子会对错月份。报表页和搭建页的预览都有。
- 为什么做:仪表盘和报表专题里搭建页的最后一项,是维护者看过的效果图三第 6 项的后半句;挡它的引擎缺陷 objectstack-ai#35395 已于 11-22
修好。
-
出错会怎样:开关只是看的人自己的选择,不存进报表,关掉就和以前一样;服务器拒绝对比时,图的位置会写明原因,不会悄悄消失。选「全部时间」时没有可对比的上一期,开关变灰。可以直接撤回本次合并。
- 要你做什么:无。(两件事没做、需要的话另开功能卡:「默认就打开对比」随报表保存;按「上一个自然月/季度」对比,好让日期横轴也能用。)

## What changes

**The switch** (`ui/packages/plugin-report/src/ReportDateRange.tsx`)
- `ReportCompareToggle`: 「Compare with previous period」 beside the
period chip. Like the chip's own pick it is the viewer's state, keyed on
the report's `dateRange` declaration, never written into the report.
Off, and disabled, while the period names no window (All time, or a
custom range missing an end).
- `reportChartComparable(chart, windowDimension)`: offered only where
the chart can draw a clean comparison — `bar`, `column`,
`horizontal-bar`, `line`, `area` over an x axis that is NOT the window's
own date dimension, or a single number (`metric`, `kpi`) — and not on a
`seriesBy` split (its series are values of the split dimension, so no
series pairs with the measure's earlier window). Pie / donut / funnel /
treemap / sankey / table are not offered it. Nothing is offered until
the window's dimension is known.
- `reportCompareTo`: the selection's `compareTo` only while on AND a
window exists.

**The chart**
(`ui/packages/plugin-report/src/DatasetReportRenderer.tsx`)
- `useDatasetRows` takes an optional `compareTo` and sends it beside the
window it shifts (`compareTo: { kind: 'previousPeriod', dimension: <the
window's dimension> }`, the existing `DatasetSelection.compareTo`
contract); it is part of the query signature, so toggling re-queries.
Only the embedded chart passes it; the table beside the chart is not
asked for a comparison.
- Series charts get one more series, `<measure>__compare` (the
executor's column), labelled `<measure> ·
<dashboard.trend.vsPreviousPeriod>` with `variant: 'comparison'`, the
chart's existing muted / dashed styling — the dashboard's overlay shape.
The chart is compared with the same-length window just before the
current one (the contract's `previousPeriod`). On a category axis the
rows merge by key, so each category's earlier total sits beside its
current one.
- A single number shows the previous value and the signed percent change
under it (`formatPeriodChange`, module-local; no percent when the
previous value is 0).
- A click on an earlier-window mark opens no record list (the
dashboard's `chartDrillMeasure` rule for the same series); a current
mark drills as before.
- A refused comparison is drawn as the error where the chart was.
Before, any chart error fell back silently to the table; with the switch
on that would leave it on over a vanished chart.

**Strings, docs, changeset**
- `@object-ui/i18n`: one key, `report.dateRange.comparePrevious`, in all
11 locales. The series caption reuses the dashboard's
`dashboard.trend.vsPreviousPeriod`.
- `content/docs/ui/reports.mdx` › *Period and export*: one bullet on the
switch, and the stale 「Declared, not drawn yet」 callout replaced (see
Acceptance notes).
- `.changeset/36645-report-compare-previous-period.md` (patch;
plugin-report, i18n).

No spec key, schema, export or server change.

Read first (by risk): `DatasetReportChart` in
`DatasetReportRenderer.tsx` (the series and the drill guard) ·
`reportChartComparable` (where the switch is offered).

## Why

objectstack-ai#36374 item 6 (board 49, figure 3): the time switch offers 「和上一期对比」 and
the chart draws both periods. It waited on objectstack-ai#35395 (`{current_iso_week}`
left unshifted by compare-to), closed 2026-11-22 by objectstack-ai#36416. On base
`460af0e4` the report renderer never sent `compareTo`, although the
analytics executor answers it.

## Verification

- New `DatasetReportRenderer.comparePrevious-36645.test.tsx`: `pnpm
--dir ui exec vitest run
packages/plugin-report/src/__tests__/DatasetReportRenderer.comparePrevious-36645.test.tsx`
→ 15 passed at `fd8a9260`. Ablation at the first head:
`DatasetReportRenderer.tsx` checked out from `origin/main` (the new
`ReportDateRange.tsx` exports left in place) → 8 failed | 4 passed; the
4 green by design are the "not offered" cases (donut, table, `seriesBy`,
no period), which hold on base because base offers no switch at all.
Ablation of the date-axis rule at `fd8a9260`: `ReportDateRange.tsx` and
`DatasetReportRenderer.tsx` checked out from `ccb43920` (before the
rule) → 2 failed | 13 passed, the two red being the new bar / line "not
offered on the window's own date axis" pins. Both restored; `git status`
clean before each commit.
- `pnpm --dir ui exec vitest run --maxWorkers=3 packages/plugin-report/`
at `fd8a9260` → 38 files, 377 passed | 7 skipped. `packages/i18n/`
(first head) → 107 files, 2006 passed | 13 skipped (key parity across
the 11 locales included).
- ESLint on the three touched plugin-report files: 0 errors (warnings
only, the file's existing `react-refresh` / test `any` kinds). `pnpm
check:new-line-citations` → 0 new.
- Not measured locally: the plugin-report type-check (it needs the built
`@object-ui/*` declarations this container did not build); covered by CI
Type Check UI.
- Executor, live (showcase, `showcase_invoice_metrics`, `last_90_days`,
grouped by `issued_on`):
`{"issued_on":"2026-09","invoice_count":2,"invoice_count__compare":1}`,
`2026-10` 2/1, `2026-11` 3/1 — the executor answers `compareTo`. (That
date-axis shape is the one the switch no longer offers; see Acceptance
notes.)
- Browser (showcase on a local server, console from this branch's `ui/`
source, zh-CN, admin). Frames in the project folder `issue-36645/`:
- `item3-1-switch-beside-period.png` (first head) — the switch beside
「今年」 on a number, off.
- `item3-6-date-axis-bar-not-offered.png` (`fd8a9260`) — new report →
Invoice Metrics → group by Issued → 近 90 天, bar: the period chip and no
switch.
- `item3-4-number-previous-and-change.png` (`fd8a9260`) — the same
report as 数字: switch on, 7, 「较上期 3 (+133.3%)」.
- `item3-7-category-axis-two-periods.png` (`fd8a9260`) — report page
「按状态统计工时(图表)」, its list response intercepted in the browser to add
`dateRange: { dimension: 'created_at', defaultRange: 'this_month' }`
(showcase ships no report with a period): 本月 + switch on, a lighter
earlier-window bar beside each status; the request carried
`"dimensions":["status"],…,"timeDimensions":[{"dimension":"created_at","dateRange":"this_month"}],"compareTo":{"kind":"previousPeriod","dimension":"created_at"}`.
- `item3-5-all-time-switch-off.png` (first head) — 全部时间: switch off and
disabled, one series.

## Acceptance notes

- Not done, by design: saving "compare on" as the report's default. That
is a new report spec key (a widening of `ReportSchema.dateRange`), a
separate Feature if wanted.
- Not done: a comparison column in the report's table / 「计算值」 grid; the
card asks the chart to draw both periods.
- Contract review S1 (comment 7109766175), resolved by the seat's
ruling: `ccb43920` first documented the position pairing; `fd8a9260`
then stops offering the switch on a chart whose x axis is the window's
own date dimension (the bars could pair with the wrong period where the
two windows split into different bucket counts), and words docs,
changeset and this body as "the same-length window just before it". A
calendar-aligned comparison would be a new `compareTo` kind (a spec
widening) and the seat files it as a separate Feature card. The
`runCompare` unaligned-bucket overwrite the review escalated is an
executor defect outside this diff, filed as objectstack-ai#36770.
- Fixed here on the seat's word (same file):
`content/docs/ui/reports.mdx` › *Period and export* carried the callout
「Declared, not drawn yet … there is no period chip」, false since the
renderer draws the chip and the Export control (both `live` in the spec
liveness ledger, so `os validate` no longer warns). Replaced with one
paragraph saying what the page draws.

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; lint passes on the touched files.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the maintainer
quick-read above is the allowed Chinese channel).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01JQwxbYCxqr63HW2KJGpmAq

<!-- signed: repo:objectstack#1 · os-warren ·
session_01JQwxbYCxqr63HW2KJGpmAq -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants