Repository navigation
Premium Analytics: build the comparison menu from the applied date range - #51779
Conversation
previous-week returns; whole-months previous period steps by month count
labels come from getComparisonOptions; No comparison moves last
derive resolves the preset too and patches stage it
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Premium Analytics plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 6 files. Only the first 5 are listed here.
|
kangzj
left a comment
There was a problem hiding this comment.
Approving 👍 The menu follows the applied range everywhere I poked at it, the whole-month stepping lands on real calendar months, and the restored previous-week works both from the menu and from a saved link.
Blockers: none.
One note that had nowhere to sit on a line - a URL carrying comp=1&compare_preset=previous-week but no compare_from/compare_to names the trigger "Prev. week" and then renders no comparison at all, because nothing re-derives on mount. Every link the app writes carries the compare dates so in practice it's fine, and it's pre-existing and not specific to previous-week, but the deep-link bullet in the testing instructions reads a bit stronger than what actually happens. Just flagging it, not asking for anything.
Testing performed
On my local docker env (Premium Analytics dashboard in wp-admin, built from this branch), plus the package's own jest and typecheck:
| # | What I checked | What I saw | Status |
|---|---|---|---|
| 1 | Last 30 days menu | Previous 30 days · Same period in 2025 · No comparison | ✅ |
| 2 | Last 7 days menu | Previous 7 days · Same period in July · Same period in 2025, no last-week entry | ✅ |
| 3 | Last 24 hours menu | Previous 24 hours · Same period from last week · Same period in July · Same period in 2025 | ✅ |
| 4 | 12 months menu | only Previous 12 months, and the window steps back 12 calendar months | ✅ |
| 5 | Single day (custom Aug 30) | Previous day · last week · July · 2025 | ✅ |
| 6 | Custom 57-day range drawn in 2025 | "Previous 57 days" and "Same period in 2024" | ✅ |
| 7 | Whole month Jul 1-31, pick Previous month | compares Jun 1-30, the previous calendar month | ✅ |
| 8 | Calendar year 2025, pick Previous 12 months | compares Jan 1 - Dec 31 2024, not a Jan 2 window | ✅ |
| 9 | 28 vs 29 day boundary | month shift offered at 28 days, gone at 29 | ✅ |
| 10 | "Same period in July" on 7 days, then switch to 30 days | trigger becomes "Prev. period" and compare_preset=previous-period |
✅ |
| 11 | Step back from calendar 2025 with the arrow | range 2024, comparison calendar 2023, preset kept | ✅ |
| 12 | Deep link with compare_preset=previous-week + compare dates |
trigger reads "Prev. week", comparison renders | ✅ |
| 13 | Pick "Same period from last week" on a single day | writes previous-week and the Aug 23 window |
✅ |
| 14 | Custom range Aug 1-5 drawn in the calendar | compares Jul 27-31, menu follows the 5-day length | ✅ |
| 15 | "No comparison" | sits last, and clears comp/compare_* from the URL |
✅ |
| 16 | jest for packages/premium-analytics |
19 suites / 280 tests pass; datetime + date-filter suites also green under UTC, America/Los_Angeles, Asia/Tokyo and Pacific/Auckland | ✅ |
| 17 | tsgo --noEmit and eslint on the changed files |
clean | ✅ |
| 18 | The report-params-field staging of compare_preset |
couldn't reach it - no widget on the dashboard exposes a per-widget date control, so only its unit tests cover that path | |
| 19 | Deep link with compare_preset but no compare dates |
trigger names the preset, widgets show no comparison (pre-existing, same for every preset) |
Evidence
Compare menu on Last 24 hours, merge-base build vs this branch:
Nice work on this one, the labels naming the target rather than the offset makes it a lot easier to read. Thanks!
| const years = wholeMonths / MONTHS_PER_YEAR; | ||
| return sprintf( | ||
| /* translators: %d: number of years covered by the selected date range. */ | ||
| _n( 'Previous %d year', 'Previous %d years', years, 'jetpack-premium-analytics-pkg' ), |
There was a problem hiding this comment.
This looks like the one branch of the label helper that isn't covered - a two-year custom range hits Previous %d years, and an hour-sized window hits the singular Previous hour just below. Both are reachable I think, so maybe worth a couple more rows in comparison-presets.test.ts? Not blocking.
There was a problem hiding this comment.
Both reachable indeed — added two rows in 929df70: a two-year custom range hitting "Previous 2 years" and a drilled single hour hitting "Previous hour". Thanks for the thorough matrix!

Proposed changes
The Compare menu was a fixed list of three presets. It is now derived from the applied range, so presets, custom ranges, and stepped or drilled windows all resolve through the same rules.
Let
nbe the range's length.n≤ 7 daysn≤ 28 daysn< 365 daysThree rules on top:
Also here:
previous-weekis restored, so links saved before #51094 work again.The trigger face is untouched. The
vsprefix and the exact-dates tooltip are in #51820.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Build:
jetpack build --deps packages/premium-analytics.Open the Compare menu under each range and check what it offers:
"No comparison" sits last in every one of them.
Then:
comp=1,compare_preset=previous-weekand the compare dates. The week-shifted comparison renders.One known gap, flagged by @kangzj: a link carrying
compare_presetwith no compare dates names the trigger but compares nothing. It predates this PR and is not specific toprevious-week. #51820 fixes it.Screen.Recording.2026-09-01.at.1.30.14.PM.mov