Skip to content

Commit fecf6e2

Browse files
nerradchihsuan
andauthored
Premium Analytics: port the Top performing products widget (#49726)
* Premium Analytics: port top performing products widget # Conflicts: # projects/packages/premium-analytics/eslint.config.mjs # projects/packages/premium-analytics/widgets/stories/widget-dashboard-with-widget.tsx * Fix Premium Analytics widget lockfile * Fix top performing products Storybook stories * fix: conform top-performing-products port to widget contract --------- Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
1 parent 64d4e2d commit fecf6e2

6 files changed

Lines changed: 438 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: added
3+
4+
Widgets: Add top performing products widget.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@automattic/jetpack-premium-analytics-widget-top-performing-products",
3+
"version": "0.1.0-alpha",
4+
"private": true,
5+
"type": "module",
6+
"dependencies": {
7+
"@jetpack-premium-analytics/widgets-toolkit": "link:../../packages/widgets-toolkit",
8+
"@wordpress/i18n": "^6.9.0",
9+
"@wordpress/icons": "^13.0.0",
10+
"@wordpress/widget-primitives": "next",
11+
"react": "18.3.1"
12+
}
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import {
5+
TopPerformingProductsWidget,
6+
WidgetRoot,
7+
type ReportParamsFieldAttributes,
8+
} from '@jetpack-premium-analytics/widgets-toolkit';
9+
/**
10+
* Internal dependencies
11+
*/
12+
import type { TopPerformingProductsAttributes } from './widget';
13+
import type { WidgetRenderProps } from '@wordpress/widget-primitives';
14+
import type { ComponentProps } from 'react';
15+
16+
// Report params are usually URL-driven (WidgetRoot's fallback), but callers may
17+
// also pass them via `attributes`. Compose the render-only shape to cover both.
18+
type TopPerformingProductsRenderAttributes = TopPerformingProductsAttributes &
19+
Partial< ReportParamsFieldAttributes >;
20+
21+
type TopPerformingProductsRenderProps =
22+
WidgetRenderProps< TopPerformingProductsRenderAttributes > & {
23+
setError?: ComponentProps< typeof WidgetRoot >[ 'setError' ];
24+
};
25+
26+
/**
27+
* Top performing products widget.
28+
*
29+
* Thin composition over the widgets-toolkit: WidgetRoot provides the query
30+
* client, chart theme, and resolved report params; TopPerformingProductsWidget
31+
* fetches physical product data and renders a revenue leaderboard.
32+
*/
33+
export default function TopPerformingProductsRender( {
34+
attributes = {},
35+
setError,
36+
}: TopPerformingProductsRenderProps ) {
37+
return (
38+
<WidgetRoot attributes={ attributes } setError={ setError } options={ { from: '/' } }>
39+
<TopPerformingProductsWidget limit={ 5 } />
40+
</WidgetRoot>
41+
);
42+
}

0 commit comments

Comments
 (0)