Premium Analytics: add date range picker to the dashboard#49572
Premium Analytics: add date range picker to the dashboard#49572Nikschavan wants to merge 5 commits into
Conversation
|
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! |
There was a problem hiding this comment.
Pull request overview
Ports the Premium Analytics dashboard to support a shared date range picker (with comparison), syncing date state through URL search params so all widgets resolve consistent report parameters.
Changes:
- Render
DateFiltersPanelin the Premium Analytics dashboard route and wire it to staged URL search params with an Apply/Cancel flow. - Update widgets-toolkit
WidgetRootto default its search param source to/(the Premium Analytics dashboard route). - Add/adjust internal package dependencies and lockfile entries to ensure route bundling can resolve shared packages.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/packages/premium-analytics/routes/dashboard/stage.tsx | Adds the date range + comparison UI and stages/commits selected values to URL search params. |
| projects/packages/premium-analytics/routes/dashboard/package.json | Adds required internal deps and date-fns for the dashboard route bundle. |
| projects/packages/premium-analytics/packages/widgets-toolkit/src/components/widget-root/widget-root.tsx | Changes default search-param source route to / for report param normalization. |
| projects/packages/premium-analytics/package.json | Adds link:packages/* deps so wp-build can resolve internal packages for the route bundle. |
| projects/packages/premium-analytics/changelog/add-pa-date-range-picker | Changelog entry for the new dashboard date range picker. |
| pnpm-lock.yaml | Lockfile updates for the new link dependencies. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
| const onComparisonChange = useCallback( | ||
| ( nextComparisonRange: DateRange | undefined, nextComparisonPresetId?: ComparisonPresetId ) => { | ||
| stage( { | ||
| compare_from: encodeDateToSearchParam( nextComparisonRange?.from ), | ||
| compare_to: encodeDateToSearchParam( nextComparisonRange?.to ), | ||
| compare_preset: nextComparisonPresetId ?? undefined, | ||
| comp: nextComparisonRange ? '1' : undefined, | ||
| } ); | ||
|
|
||
| commit(); | ||
| }, | ||
| [ stage, commit ] |
| */ | ||
| stage( { | ||
| from: encodeDateToSearchParam( nextRange.from ), | ||
| to: encodeDateToSearchParam( endOfDay( nextRange.to ) ), |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
5bb6dd9 to
7ff7f71
Compare
7ff7f71 to
22e10a7
Compare
acec56a to
979e1c4
Compare
|
@claude Review the PR |
|
Claude finished @Nikschavan's task in 3m 8s —— View job Code ReviewI read through the diff and the supporting packages ( 🔴 Bugs / correctness1. Comparison The inverse is also true: because the commit navigates and the URL→staged mirror effect ( Cleanest fix is to make comparison bypass the staged buffer with a direct navigate — the routing package already exposes 2. Convert first, then take end-of-day, so the boundary is computed in the site TZ regardless of host: to: encodeDateToSearchParam( endOfDay( localTZDate( nextRange.to ) ) ),(Worth confirming what 🟡 Worth a look3. Default seeding can clobber partial deep-links ( 4. Redundant ✅ Looks good
|
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for working on this! @Nikschavan
I verified the full flow on a local site. Overall looks good. Just two issues discovered during the testing, see inline comments below:
fc4303e to
589e65f
Compare
|
Thank you for the review @chihsuan, I have addressed the suggestions/bugs and Pr is ready for re-review |
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for adding feedback! @Nikschavan
I just went deeper this round and caught a few things I missed earlier, so apologies for the late notes 🙏
- I noticed that if I select "Last 7 days" without clicking Apply and then click outside, the UI still shows "Last 7 days." After changing "Compare to," the URL unexpectedly updates to
preset=last-7-days. Clicking theCancelbutton works as expected. See the video below:
Screen.Recording.2026-06-25.at.4.43.55.PM.mov
- Seed force-enables comparison on custom
from/todeep-links (route.ts) - Unguarded
await ensureCoreSettingsReady()(route.ts) — matches upstream; non-blocking.
| * values instead of being reset to the defaults. | ||
| */ | ||
| const seeded: Record< string, unknown > = { | ||
| ...getDefaultQueryParams( true, preset ), |
There was a problem hiding this comment.
Should the seed reuse normalizeReportParams instead of a raw default spread?
I found that opening a URL like …&p=/?from=2026-01-01T00:00:00.000+02:00&to=2026-01-31T23:59:59.999+02:00 → URL comes back with comp="1". It seems it's because { ...getDefaultQueryParams( true, preset ), ...params } always carries comp: '1', and ...params can't override a key it doesn't have.
Screen.Recording.2026-06-25.at.4.38.25.PM.mov
| const params = ( search ?? {} ) as DashboardSearch; | ||
| if ( ! params.from || ! params.to || ! params.interval ) { | ||
| // Seed dates in the site timezone, not the browser's (see above). | ||
| await ensureCoreSettingsReady(); |
There was a problem hiding this comment.
minor: ensureCoreSettingsReady() can reject, and an uncaught rejection turns the first load into an error page. Same as upstream's loader, so non-blocking.
But it might be worth add try/catch that proceeds with the default seed.
cbe92a9 to
37fee84
Compare
Add the date range picker with comparison support to the dashboard stage, syncing the selected range to URL search params so all widgets share it. The dashboard route seeds default date params (last 30 days, previous-period comparison) on first visit.
… range When a partial URL is supplied (e.g. preset deep-link or custom from/to without interval), seed only the missing params so user-supplied values are kept, deriving the range from a concrete preset when possible. On the stage, re-derive the comparison window from the new primary range when comparison is enabled, so widgets compare against the matching previous period instead of stale dates.
Await ensureCoreSettingsReady() before seeding the default date range so getDefaultQueryParams encodes dates in the site timezone instead of falling back to the browser's. Also mark partial custom from/to URLs as 'custom' preset so normalizeReportParams keeps the supplied dates.
Resolve seed date params through the shared normalizeReportParams resolver so the URL and widgets agree on dates/interval/preset/comparison, and avoid forcing comp onto custom deep-links. Make ensureCoreSettingsReady non-fatal by falling back to the default seed on rejection, and overlay resolved params onto the original search to preserve deep-linked params like section.
37fee84 to
acc5d52
Compare
Fixes WOOA7S-1587
Proposed changes
Ports the date range picker from the next-woocommerce-analytics dashboard into the Premium Analytics dashboard, syncing the selected range to URL search params so every widget picks it up.
DateFiltersPanel(already vendored inpackages/ui) at the top of the dashboard, wired touseStagedSearchfrom@jetpack-premium-analytics/routing. Date range and preset edits are staged locally and committed atomically to the URL search params on Apply (from,to,preset); thetodate is adjusted to end-of-day since the calendar component returns midnight. Comparison changes (compare_from,compare_to,compare_preset,comp) commit immediately, matching the original dashboard behavior.WidgetRoot's default search source at/(the premium-analytics dashboard route) instead of the WooCommerce Analytics route path, so widgets resolve their report params from the dashboard URL vianormalizeReportParams. No widget changes needed — they already read params throughuseWidgetRootContext().link:packages/*deps for thedata/datetime/formatters/routing/uiinternal packages so wp-build can resolve them from the route bundle; documents the new deps in the dashboard route's package.json; updatespnpm-lock.yamlaccordingly.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
from,toandpresetsearch params inside thepparam) and widgets re-fetch for the new range.compare_from/compare_to/compare_preset/compparams commit immediately without pressing Apply.