Repository navigation
fix(core): chart compare-to shifts {current_iso_week} to the compared week - #36416
Conversation
… compared week Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg
|
repo:objectstack#7 · zhuangjianguo · session_01QsR2jREBdDtYvSLn38xUCg Final head: |
|
repo:objectstack#7 · zhuangjianguo · session_01QsR2jSpi3g1dQNTvN6zEuH 席位核对L1 (L1-e) on head
|
|
repo:objectstack#7 · zhuangjianguo · session_01QsR2jREBdDtYvSLn38xUCg Landing: L1-e ACCEPT 7078530466 at |
…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>
Requested by Steedos · project thread
Fixes #35395
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
shiftFilterByCompareTo(ui/packages/core/src/utils/compare-to.ts) renamed date macros but left the{current_iso_week}period key as written, so the server resolved it to the current week and the comparison series filtered the same week as the main one.previousPeriod:{current_iso_week}/${current_iso_week}is replaced by the literal previous ISO week key (2026-W22becomes2026-W21). Week 1 steps back to the previous ISO year's last week: W53 when that year starts on a Thursday (or a Wednesday in a leap year), else W52. The literal key passes through every resolver unchanged. No new public token is added.previousYear: the period key is resolved against the same shifted day the date macros already use (resolvePeriodKeyTokens), so it is the ISO week of the same day one year earlier.compareToTrendLabelKey: a filter on{current_iso_week}now readsvsLastWeekinstead of falling through tovsPreviousPeriod.Other period-key placeholders that share the gap: none.
PERIOD_KEY_TOKENSin@objectstack/spec/datahas one member,current_iso_week.Tests
New block
compare-to on the {current_iso_week} period keyinui/packages/core/src/utils/__tests__/compare-to.test.ts: previousPeriod mid-year (W22 to W21, both spellings), week 1 to 2026-W53 and to 2025-W52, previousYear (2025-W21; Fri 2027-01-01 = 2026-W53 becomes 2026-W01), and the label.Run on a2b9aa6
pnpm exec vitest run packages/core/src/utils/ --maxWorkers=1(fromui/, under the verify lock): Test Files 124 passed (124), Tests 2214 passed (2214).pnpm --filter @object-ui/core type-check: exit 0. Lock:VERDICT command-exit 0.current_iso_weeksubstitution line withscripts/ablation-replace.mjs,grep -cof the anchor = 0 on disk. compare-to.test.ts: Tests 2 failed / 33 passed. Both previousPeriod pins went red, and the received value was'{current_iso_week}', which is the bug. The test imports the source by relative path, so there is no dist leg. Restored withgit checkout HEAD --:git diff HEADis empty and the blob hash matches HEAD (d276c311).Acceptance notes
service-analyticsdataset-executor.tsshifts only the chosen time dimension'sdateRange(shiftRange). A selectionfilteris held constant across the compare pass, whether it holds a date macro or a period key. That is the executor's existing design, not a period-key regression. Noted here, not filed: read from code, no public-door measurement.Verification
Read first:
compare-to.tspreviousIsoWeekKey(the year-edge arithmetic is the risky hunk), then its call inshiftFilterByCompareTo.Two-minute check:
cd ui && pnpm exec vitest run packages/core/src/utils/__tests__/compare-to.test.ts. Expect 35 passed.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg