-
Notifications
You must be signed in to change notification settings - Fork 882
feat(premium-analytics): port components package from next-woocommerce-analytics #49360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chihsuan
merged 12 commits into
trunk
from
wooa7s-1318-integrate-components-package-into-analytics
Jun 10, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
604a8c1
feat(premium-analytics): add ui package from next-woocommerce-analyti…
chihsuan 4becf55
refactor(premium-analytics): adapt ui package imports and manifest fo…
chihsuan e144150
refactor(premium-analytics): decouple ui package from admin-toolkit u…
chihsuan 78eb626
refactor(premium-analytics): cast comparison presets passed to DateRa…
chihsuan f411473
refactor(premium-analytics): use current wpds typography token names
chihsuan 2c0fc06
refactor(premium-analytics): extract story render hooks into named co…
chihsuan cd23fb7
style(premium-analytics): align ported ui package with jetpack format…
chihsuan a414d08
chore(premium-analytics): wire ui package deps and relax lint for the…
chihsuan ce8c516
feat(storybook): resolve @jetpack-premium-analytics imports in vite
chihsuan 09d0ff3
Merge branch 'trunk' into wooa7s-1318-integrate-components-package-in…
chihsuan bf3248b
refactor(premium-analytics): rename view-transition ids from next-adm…
chihsuan 78de2dc
Merge remote-tracking branch 'origin/trunk' into wooa7s-1318-integrat…
chihsuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/js-packages/storybook/changelog/add-premium-analytics-internal-package-alias
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: changed | ||
|
|
||
| Add a Vite alias resolving `@jetpack-premium-analytics/*` internal package imports so Premium Analytics ui package stories build. |
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
4 changes: 4 additions & 0 deletions
4
...kages/premium-analytics/changelog/wooa7s-1318-integrate-components-package-into-analytics
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: added | ||
|
|
||
| Port the components package (date range/comparison filter UI components and SCSS) from next-woocommerce-analytics as the internal `ui` package. |
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
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
28 changes: 28 additions & 0 deletions
28
projects/packages/premium-analytics/packages/ui/package.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "@automattic/jetpack-premium-analytics-ui", | ||
| "version": "0.1.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "main": "src/index.ts", | ||
| "types": "src/index.ts", | ||
| "sideEffects": [ | ||
| "*.scss" | ||
| ], | ||
| "dependencies": { | ||
| "@automattic/ui": "1.0.2", | ||
| "@jetpack-premium-analytics/datetime": "workspace:*", | ||
| "@jetpack-premium-analytics/formatters": "workspace:*", | ||
| "@wordpress/components": "33.1.0", | ||
| "@wordpress/compose": "7.46.0", | ||
| "@wordpress/i18n": "^6.9.0", | ||
| "@wordpress/icons": "^13.0.0", | ||
| "@wordpress/private-apis": "1.46.0", | ||
| "@wordpress/ui": "0.13.0", | ||
| "clsx": "2.1.1", | ||
| "react": "18.3.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@storybook/react": "10.3.6", | ||
| "date-fns": "4.1.0" | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
.../premium-analytics/packages/ui/src/date-comparison-dropdown/date-comparison-dropdown.scss
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| .date-comparison-dropdown { | ||
|
|
||
| &__button { | ||
| background-color: var(--wpds-color-bg-surface-neutral-strong); | ||
| } | ||
| } | ||
|
|
||
| .date-filters-panel-button { | ||
| background-color: var(--wpds-color-bg-surface-neutral-strong); | ||
| } | ||
|
|
||
| .date-comparison-dropdown__popover { | ||
| width: 235px; | ||
| } | ||
|
|
||
| /* disable animation for the date range popover */ | ||
| /* stylelint-disable property-no-unknown, selector-pseudo-element-no-unknown */ | ||
| @media not ( prefers-reduced-motion: reduce ) { | ||
|
|
||
| .date-comparison-dropdown__popover { | ||
| view-transition-name: jp-premium-analytics--date-comparison-dropdown; | ||
| transition: none !important; | ||
| } | ||
| } | ||
|
|
||
| /* ensure it's above the canvas/stage during the transition */ | ||
| ::view-transition-group(jp-premium-analytics--date-comparison-dropdown) { | ||
| z-index: 3000; | ||
| } | ||
|
|
||
| /* no animation for the snapshot (avoid "flashing") */ | ||
| ::view-transition-new(jp-premium-analytics--date-comparison-dropdown), | ||
| ::view-transition-old(jp-premium-analytics--date-comparison-dropdown) { | ||
| animation: none; | ||
| } | ||
| /* stylelint-enable property-no-unknown, selector-pseudo-element-no-unknown */ |
168 changes: 168 additions & 0 deletions
168
...s/premium-analytics/packages/ui/src/date-comparison-dropdown/date-comparison-dropdown.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { formatDateRange } from '@jetpack-premium-analytics/formatters'; | ||
| import { privateApis as componentsPrivateApis } from '@wordpress/components'; | ||
| import { sprintf, __ } from '@wordpress/i18n'; | ||
| import { Button } from '@wordpress/ui'; | ||
| import { useMemo } from 'react'; | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { DateRangePresets } from '../date-range-presets'; | ||
| import { unlock } from '../lock/unlock'; | ||
| import type { ComparisonDateRangePreset } from '../use-comparison-date-presets'; | ||
| import type { | ||
| ComparisonPresetId, | ||
| DateRangePreset, | ||
| PrimaryPresetId, | ||
| } from '@jetpack-premium-analytics/datetime'; | ||
| import './date-comparison-dropdown.scss'; | ||
|
|
||
| const { Menu } = unlock( componentsPrivateApis ); | ||
|
|
||
| type DateComparisonDropdownProps = { | ||
| /** | ||
| * Available comparison presets (e.g., previous-period, previous-month) | ||
| */ | ||
| presets: ComparisonDateRangePreset[]; | ||
| /** | ||
| * Whether comparison is enabled | ||
| */ | ||
| enabled: boolean; | ||
| /** | ||
| * Currently selected comparison preset ID | ||
| */ | ||
| presetId?: ComparisonPresetId; | ||
| /** | ||
| * Whether to remove "Compare to:" prefix from button label | ||
| */ | ||
| removeCompareToPrefix?: boolean; | ||
| /** | ||
| * Callback when comparison is enabled | ||
| */ | ||
| onEnable: () => void; | ||
| /** | ||
| * Callback when a comparison preset is selected | ||
| */ | ||
| onPresetChange: ( id: ComparisonPresetId ) => void; | ||
| /** | ||
| * Callback when comparison is cleared | ||
| */ | ||
| onClear: () => void; | ||
| }; | ||
|
|
||
| export function DateComparisonDropdown( { | ||
| presets, | ||
| enabled, | ||
| presetId, | ||
| removeCompareToPrefix = false, | ||
| onEnable, | ||
| onPresetChange, | ||
| onClear, | ||
| }: DateComparisonDropdownProps ) { | ||
| const selectedPreset = useMemo( | ||
| () => ( presetId ? presets.find( p => p.id === presetId ) : undefined ), | ||
| [ presets, presetId ] | ||
| ); | ||
|
|
||
| const comparisonRange = selectedPreset?.range; | ||
| const hasValidPreset = !! comparisonRange; | ||
| const hasPresets = presets.length > 0; | ||
|
|
||
| if ( ! enabled ) { | ||
| return ( | ||
| <Menu> | ||
| <Menu.TriggerButton | ||
| render={ | ||
| <Button | ||
| className="date-filters-panel-button" | ||
| variant="outline" | ||
| tone="neutral" | ||
| size="compact" | ||
| id="date-comparison-dropdown-button" | ||
| > | ||
| { __( 'No comparison', 'jetpack-premium-analytics' ) } | ||
| </Button> | ||
| } | ||
| /> | ||
| <Menu.Popover className="date-comparison-dropdown__popover"> | ||
| <Menu.Group> | ||
| <Menu.CheckboxItem name="comparison-toggle" value="no-comparison" checked={ true }> | ||
| <Menu.ItemLabel> | ||
| { __( 'No comparison', 'jetpack-premium-analytics' ) } | ||
| </Menu.ItemLabel> | ||
| </Menu.CheckboxItem> | ||
|
|
||
| <Menu.CheckboxItem | ||
| name="comparison-toggle" | ||
| value="comparison-to-past" | ||
| checked={ false } | ||
| onChange={ onEnable } | ||
| hideOnClick | ||
| > | ||
| <Menu.ItemLabel> | ||
| { __( 'Comparison to past', 'jetpack-premium-analytics' ) } | ||
| </Menu.ItemLabel> | ||
| </Menu.CheckboxItem> | ||
| </Menu.Group> | ||
| </Menu.Popover> | ||
| </Menu> | ||
| ); | ||
| } | ||
|
|
||
| let label: string = __( 'Select comparison', 'jetpack-premium-analytics' ); | ||
| if ( hasValidPreset ) { | ||
| if ( removeCompareToPrefix ) { | ||
| label = formatDateRange( comparisonRange ); | ||
| } else { | ||
| label = sprintf( | ||
| // translators: %s is the comparison range label | ||
| __( 'Compare to: %s', 'jetpack-premium-analytics' ), | ||
| formatDateRange( comparisonRange ) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Menu> | ||
| <Menu.TriggerButton | ||
| render={ | ||
| <Button | ||
| className="date-comparison-dropdown__button" | ||
| variant="outline" | ||
| tone="neutral" | ||
| size="compact" | ||
| > | ||
| { label } | ||
| </Button> | ||
| } | ||
| /> | ||
| <Menu.Popover className="date-comparison-dropdown__popover"> | ||
| { hasPresets && ( | ||
| <DateRangePresets | ||
| /* | ||
| * DateRangePresets is typed for primary presets, but it only | ||
| * reads `id`/`label`/`range` to render each row, so it renders | ||
| * comparison presets identically. Cast to the primary-preset | ||
| * prop types; the runtime shape matches. | ||
| */ | ||
| value={ ( presetId ?? null ) as PrimaryPresetId | null } | ||
| presets={ presets as unknown as DateRangePreset[] } | ||
| hideOnClick | ||
| onRangeChange={ ( _range, id ) => { | ||
| /* | ||
| * Type assertion is safe here because: | ||
| * 1. presets is ComparisonDateRangePreset[] (strongly typed) | ||
| * 2. DateRangePresets picks id from our presets array | ||
| * 3. Therefore id must be ComparisonPresetId | ||
| */ | ||
| onPresetChange( id as ComparisonPresetId ); | ||
| } } | ||
| onClear={ onClear } | ||
| /> | ||
| ) } | ||
| </Menu.Popover> | ||
| </Menu> | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
projects/packages/premium-analytics/packages/ui/src/date-comparison-dropdown/index.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { DateComparisonDropdown } from './date-comparison-dropdown'; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion] These three pins (
@wordpress/components 33.1.0,@wordpress/compose 7.46.0,@wordpress/private-apis 1.46.0) are older than what the parent manifest resolves (35.0.0/8.1.0/1.48.0), and the siblingdataleaf matches the parent exactly — so the PR description's "versions match siblings" doesn't hold for these.No runtime impact today since the leaf isn't a pnpm workspace member, but when it becomes load-bearing in the first-consumer PR, pnpm would install a second, older
@wordpress/componentsalongside the parent's. Theprivate-apisskew is the riskiest one: its lock/unlock is version-coupled to@wordpress/components, so a mismatched pair can throw at runtime.Suggest bumping the three specifiers to match the parent (
35.0.0/8.1.0/1.48.0).