[WIP] feat(premium-analytics): port components package from next-woocommerce-analytics#49360
Draft
chihsuan wants to merge 8 commits into
Conversation
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
First UI leaf in M2 — Shared Packages Integration: port
@next-woo-analytics/componentsinto@automattic/jetpack-premium-analyticsas the internaluipackage. Provides the date-filtering UI consumed by analytics widgets — the date-range popover (calendar + presets + manual inputs), the comparison dropdown, and theDateFiltersPanelcontainer that ties them together — plus the SCSS for all of it. This is the first ported package that ships React components and styles.It depends on both previously ported leaves, so this branch is built on an integration base that merges them in:
@jetpack-premium-analytics/datetime— feat(premium-analytics): port datetime package from next-woocommerce-analytics #49221 (WOOA7S-1312)@jetpack-premium-analytics/formatters— feat(premium-analytics): port formatters package from next-woocommerce-analytics #49226 (WOOA7S-1313)Commits
Reviewed most easily commit-by-commit — the verbatim copy is isolated first, so every later diff shows exactly what the monorepo port changed.
d17e81031e41d3f1bc5f196765f56277b5215577806998be42f5dc81dd44224ba59624What's in the package
src/date-filters-panel/**DateFiltersPanel— the package's public entry; owns comparison state and composes the popover + comparison dropdownsrc/date-range-popover/**DateRangePopover/DateRangePopoverContent— responsive calendar + presets + manual inputs in a dropdownsrc/date-range-presets/**DateRangePresets(preset menu); also re-exports datetime preset constants/types for existing barrel consumerssrc/date-range-input/**DateRangeInput— typed from/to date fieldssrc/date-comparison-dropdown/**DateComparisonDropdown— comparison preset menusrc/use-comparison-date-presets/**useComparisonDatePresetshook (derives comparison presets from a primary range)src/lock/unlock.ts@wordpress/private-apisunlock helper (replaces@automattic/admin-toolkit)src/**/*.scssMonorepo adaptations
packages/componentspackages/ui@wordpress/buildhard-codes an Emotion Babel pass for any package directory literally namedcomponents(needsEmotionPlugin = packageName === 'components'), which runs Babel without a TypeScript preset and breaks TS transpilation. These components use SCSS, not Emotion, so the pass is incidental — naming the diruilets esbuild transpile the TS natively with no extra Babel toolingname: @next-woo-analytics/componentsname: @automattic/jetpack-premium-analytics-ui@jetpack-premium-analytics/ui(from the tsconfig path alias), separate from thename:field… from '@next-woo-analytics/datetime'(11 imports)… from '@jetpack-premium-analytics/datetime'… from '@wc-analytics/formatters'… from '@jetpack-premium-analytics/formatters'formatDate+formatDateRangeare used)import { unlock } from '@automattic/admin-toolkit'(3 files)src/lock/unlock.tsvia@wordpress/private-apisadmin-toolkitisn't available here. The helper opts in with__dangerousOptInToUnstableAPIsOnlyForCoreModulesto reach the privateMenuof@wordpress/components— mirrors existing Jetpack precedent (jetpack-mu-wpcomgetUnlock,js-packages/chartsstories)@next-woo-analytics/data,@automattic/design-systemindependencies@next-woo-analytics/componentsStorybook stories (3)'woocommerce-analytics'text domain'jetpack-premium-analytics'tsconfig.jsonincludes: [packages/**/*]and supplies the@jetpack-premium-analytics/*path alias; mirrorspackages/datetime/packages/formatters*version specs@automattic/ui 1.0.2,@wordpress/components 33.1.0,@wordpress/compose 7.46.0,@wordpress/ui 0.13.0,@wordpress/private-apis 1.46.0,clsx 2.1.1)One small TS adaptation worth flagging:
DateComparisonDropdownreusesDateRangePresets(typed for primary presets) to render comparison presets. Upstream's loosertscallowed it; the repo'stsgodoes not, so the two props are cast at that one call site with a comment — the component only readsid/label/rangeto render, so the runtime shape matches.Parent-level wiring (
projects/packages/premium-analytics/):package.json: adds the real runtime deps imported by the components (@automattic/ui,@wordpress/components,@wordpress/compose,@wordpress/private-apis,@wordpress/ui,clsx;@wordpress/icons/date-fnsalready present), plus@wordpress/base-styles(dev) so the SCSS@use "@wordpress/base-styles/…"resolves at build time. The leaf isn't a pnpm workspace member (the root glob doesn't reach two levels in), so the parent's deps are the load-bearing ones. Nolink:dependency is added yet — nothing importsui(same as datetime/formatters); the first consumer will add it.eslint.config.mjs(temporary): extends the existing JSDoc softening topackages/ui/**and additionally relaxesreact/jsx-no-bind+jsdoc/require-jsdoc/escape-inline-tagsso the upstream inline-handler JSX style lands as-is. Tracked for follow-up alongside datetime/formatters.Build / SCSS
pnpm build(wp-build) transpiles every internal package;uinow transpiles cleanly and its SCSS compiles —@use "@wordpress/base-styles/colors"resolves ($gray-300→#ddd),--wpds-*tokens and class names are emitted, and the compiled CSS is inlined into the per-component output as a runtime style injection. Like datetime/formatters, the package is a library (not a build target), so it only lands inbuild/once a route imports it; building it standalone confirms the JS and styles compile.What's intentionally not here
@automattic/admin-toolkit— replaced by the localunlockhelper.@next-woo-analytics/data/@automattic/design-system— declared upstream, imported nowhere.link:dependency on the parent —uiisn't imported anywhere yet, so wiring it into the build is deferred to the first consumer (mirrors datetime/formatters).eslint.config.mjscomments.Does this pull request change what data or activity we track or use?
No.
Testing instructions
Requires Node 24 (repo
engineStrict).