Skip to content

Commit ac1f2ed

Browse files
committed
fix: conform average-order-value widget port to widget contract
1 parent 14c92f6 commit ac1f2ed

5 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎projects/js-packages/storybook/changelog/add-average-order-value-widget-story‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎projects/packages/premium-analytics/packages/widgets-toolkit/src/components/chart-comparative-line/comparative-line-chart.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* External dependencies
33
*/
4+
import { LineChart } from '@automattic/charts';
45
import { formatDate, formatMetricValue } from '@jetpack-premium-analytics/formatters';
56
import { Stack } from '@wordpress/ui';
67
import clsx from 'clsx';
@@ -9,7 +10,6 @@ import { type ComponentProps } from 'react';
910
/**
1011
* Internal dependencies
1112
*/
12-
import { LineChart } from '../../../../../../../js-packages/charts/src/charts/line-chart';
1313
import { RESIZE_DEBOUNCE_MS } from '../../constants';
1414
import { isEmptyChartData, getEmptyChartDomain } from '../../helpers';
1515
import { ChartTooltip } from '../chart-tooltip';

‎projects/packages/premium-analytics/widgets/average-order-value/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@jetpack-premium-analytics/widgets-toolkit": "link:../../packages/widgets-toolkit",
88
"@wordpress/i18n": "^6.9.0",
99
"@wordpress/icons": "^13.0.0",
10-
"@wordpress/ui": "0.13.0",
10+
"@wordpress/widget-primitives": "next",
1111
"react": "18.3.1"
1212
}
1313
}

‎projects/packages/premium-analytics/widgets/average-order-value/render.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ import {
66
WidgetRoot,
77
type ReportParamsFieldAttributes,
88
} from '@jetpack-premium-analytics/widgets-toolkit';
9+
import type { AverageOrderValueAttributes } from './widget';
10+
import type { WidgetRenderProps } from '@wordpress/widget-primitives';
11+
import type { ComponentProps } from 'react';
912

10-
type AverageOrderValueRenderProps = {
11-
attributes?: Partial< ReportParamsFieldAttributes >;
12-
setError?: Parameters< typeof WidgetRoot >[ 0 ][ 'setError' ];
13+
// Report params are usually URL-driven (WidgetRoot's fallback), but callers may
14+
// also pass them via `attributes`. Compose the render-only shape to cover both.
15+
type AverageOrderValueRenderAttributes = AverageOrderValueAttributes &
16+
Partial< ReportParamsFieldAttributes >;
17+
18+
type AverageOrderValueRenderProps = WidgetRenderProps< AverageOrderValueRenderAttributes > & {
19+
setError?: ComponentProps< typeof WidgetRoot >[ 'setError' ];
1320
};
1421

1522
/**
@@ -21,7 +28,7 @@ type AverageOrderValueRenderProps = {
2128
* comparison delta and sparkline.
2229
*/
2330
export default function AverageOrderValueRender( {
24-
attributes,
31+
attributes = {},
2532
setError,
2633
}: AverageOrderValueRenderProps ) {
2734
return (

‎projects/packages/premium-analytics/widgets/average-order-value/widget.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
import { __ } from '@wordpress/i18n';
55
import { chartBar } from '@wordpress/icons';
66

7+
/**
8+
* The widget has no user-configurable attributes. Report params still reach it
9+
* through WidgetRoot: the dashboard date range, or `attributes.reportParams`
10+
* when a host injects them (e.g. Storybook and dashboard previews).
11+
*/
12+
export type AverageOrderValueAttributes = Record< never, never >;
13+
714
/**
815
* Widget type definition.
916
*

0 commit comments

Comments
 (0)