Move CES action dispatch to report filter configs. (https://github.com/woocommerce/woocommerce-admin/pull/6847)

* Move CES action dispatch to report filter configs.

Makes the click handler attachment more resilient to 3PD filter usage.

* Add changelog entry.
This commit is contained in:
Jeff Stieler 2021-04-22 14:06:46 -06:00 committed by GitHub
parent af888f5b0b
commit ad67df0658
11 changed files with 35 additions and 76 deletions

View File

@ -3,11 +3,13 @@
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { getCategoryLabels } from '../../../lib/async-requests';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
const CATEGORY_REPORT_CHARTS_FILTER =
'woocommerce_admin_categories_report_charts';
@ -16,6 +18,8 @@ const CATEGORY_REPORT_FILTERS_FILTER =
const CATEGORY_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_category_report_advanced_filters';
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
export const charts = applyFilters( CATEGORY_REPORT_CHARTS_FILTER, [
{
key: 'items_sold',
@ -99,6 +103,7 @@ export const filters = applyFilters( CATEGORY_REPORT_FILTERS_FILTER, [
title: __( 'Compare Categories', 'woocommerce-admin' ),
update: __( 'Compare', 'woocommerce-admin' ),
},
onClick: addCesSurveyForAnalytics,
},
},
],

View File

@ -4,7 +4,6 @@
import { Component, Fragment } from '@wordpress/element';
import PropTypes from 'prop-types';
import { __ } from '@wordpress/i18n';
import { withDispatch } from '@wordpress/data';
/**
* Internal dependencies
@ -16,7 +15,6 @@ import ReportChart from '../../components/report-chart';
import ReportSummary from '../../components/report-summary';
import ProductsReportTable from '../products/table';
import ReportFilters from '../../components/report-filters';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
class CategoriesReport extends Component {
getChartMeta() {
@ -44,12 +42,7 @@ class CategoriesReport extends Component {
}
render() {
const {
isRequesting,
query,
path,
addCesSurveyForAnalytics,
} = this.props;
const { isRequesting, query, path } = this.props;
const { mode, itemsLabel, isSingleCategoryView } = this.getChartMeta();
const chartQuery = {
@ -62,10 +55,6 @@ class CategoriesReport extends Component {
: 'category';
}
filters[ 0 ].filters.find(
( item ) => item.value === 'compare-categories'
).settings.onClick = addCesSurveyForAnalytics;
return (
<Fragment>
<ReportFilters
@ -134,7 +123,4 @@ CategoriesReport.propTypes = {
path: PropTypes.string.isRequired,
};
export default withDispatch( ( dispatch ) => {
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
return { addCesSurveyForAnalytics };
} )( CategoriesReport );
export default CategoriesReport;

View File

@ -3,17 +3,21 @@
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { getCouponLabels } from '../../../lib/async-requests';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
const COUPON_REPORT_CHARTS_FILTER = 'woocommerce_admin_coupons_report_charts';
const COUPON_REPORT_FILTERS_FILTER = 'woocommerce_admin_coupons_report_filters';
const COUPON_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_coupon_report_advanced_filters';
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
export const charts = applyFilters( COUPON_REPORT_CHARTS_FILTER, [
{
key: 'orders_count',
@ -85,6 +89,7 @@ export const filters = applyFilters( COUPON_REPORT_FILTERS_FILTER, [
'woocommerce-admin'
),
},
onClick: addCesSurveyForAnalytics,
},
},
],

View File

@ -4,7 +4,6 @@
import { Component, Fragment } from '@wordpress/element';
import PropTypes from 'prop-types';
import { __ } from '@wordpress/i18n';
import { withDispatch } from '@wordpress/data';
/**
* Internal dependencies
@ -15,7 +14,6 @@ import getSelectedChart from '../../../lib/get-selected-chart';
import ReportChart from '../../components/report-chart';
import ReportSummary from '../../components/report-summary';
import ReportFilters from '../../components/report-filters';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
class CouponsReport extends Component {
getChartMeta() {
@ -35,18 +33,9 @@ class CouponsReport extends Component {
}
render() {
const {
isRequesting,
query,
path,
addCesSurveyForAnalytics,
} = this.props;
const { isRequesting, query, path } = this.props;
const { mode, itemsLabel } = this.getChartMeta();
filters[ 0 ].filters.find(
( item ) => item.value === 'compare-coupons'
).settings.onClick = addCesSurveyForAnalytics;
const chartQuery = {
...query,
};
@ -100,7 +89,4 @@ CouponsReport.propTypes = {
query: PropTypes.object.isRequired,
};
export default withDispatch( ( dispatch ) => {
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
return { addCesSurveyForAnalytics };
} )( CouponsReport );
export default CouponsReport;

View File

@ -3,6 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies
@ -11,6 +12,7 @@ import {
getProductLabels,
getVariationLabels,
} from '../../../lib/async-requests';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
const PRODUCTS_REPORT_CHARTS_FILTER =
'woocommerce_admin_products_report_charts';
@ -19,6 +21,8 @@ const PRODUCTS_REPORT_FILTERS_FILTER =
const PRODUCTS_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_products_report_advanced_filters';
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
export const charts = applyFilters( PRODUCTS_REPORT_CHARTS_FILTER, [
{
key: 'items_sold',
@ -95,6 +99,7 @@ const filterConfig = {
title: __( 'Compare Products', 'woocommerce-admin' ),
update: __( 'Compare', 'woocommerce-admin' ),
},
onClick: addCesSurveyForAnalytics,
},
},
],

View File

@ -6,7 +6,7 @@ import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import PropTypes from 'prop-types';
import { ITEMS_STORE_NAME } from '@woocommerce/data';
import { withSelect, withDispatch } from '@wordpress/data';
import { withSelect } from '@wordpress/data';
/**
* Internal dependencies
@ -19,7 +19,6 @@ import ReportError from '../../components/report-error';
import ReportSummary from '../../components/report-summary';
import VariationsReportTable from '../variations/table';
import ReportFilters from '../../components/report-filters';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
class ProductsReport extends Component {
getChartMeta() {
@ -61,7 +60,6 @@ class ProductsReport extends Component {
isError,
isRequesting,
isSingleProductVariable,
addCesSurveyForAnalytics,
} = this.props;
if ( isError ) {
@ -77,10 +75,6 @@ class ProductsReport extends Component {
compareObject === 'products' ? 'product' : 'variation';
}
filters[ 0 ].filters.find(
( item ) => item.value === 'compare-products'
).settings.onClick = addCesSurveyForAnalytics;
return (
<Fragment>
<ReportFilters
@ -193,9 +187,5 @@ export default compose(
query,
isSingleProductView,
};
} ),
withDispatch( ( dispatch ) => {
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
return { addCesSurveyForAnalytics };
} )
)( ProductsReport );

View File

@ -4,18 +4,22 @@
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { NAMESPACE } from '@woocommerce/data';
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { getRequestByIdString } from '../../../lib/async-requests';
import { getTaxCode } from './utils';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
const TAXES_REPORT_CHARTS_FILTER = 'woocommerce_admin_taxes_report_charts';
const TAXES_REPORT_FILTERS_FILTER = 'woocommerce_admin_taxes_report_filters';
const TAXES_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_taxes_report_advanced_filters';
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
export const charts = applyFilters( TAXES_REPORT_CHARTS_FILTER, [
{
key: 'total_tax',
@ -82,6 +86,7 @@ export const filters = applyFilters( TAXES_REPORT_FILTERS_FILTER, [
title: __( 'Compare Tax Codes', 'woocommerce-admin' ),
update: __( 'Compare', 'woocommerce-admin' ),
},
onClick: addCesSurveyForAnalytics,
},
},
],

View File

@ -4,7 +4,6 @@
import { Component, Fragment } from '@wordpress/element';
import PropTypes from 'prop-types';
import { __ } from '@wordpress/i18n';
import { withDispatch } from '@wordpress/data';
/**
* Internal dependencies
@ -15,7 +14,6 @@ import ReportChart from '../../components/report-chart';
import ReportSummary from '../../components/report-summary';
import TaxesReportTable from './table';
import ReportFilters from '../../components/report-filters';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
class TaxesReport extends Component {
getChartMeta() {
@ -31,18 +29,9 @@ class TaxesReport extends Component {
}
render() {
const {
isRequesting,
query,
path,
addCesSurveyForAnalytics,
} = this.props;
const { isRequesting, query, path } = this.props;
const { mode, itemsLabel } = this.getChartMeta();
filters[ 0 ].filters.find(
( item ) => item.value === 'compare-taxes'
).settings.onClick = addCesSurveyForAnalytics;
const chartQuery = {
...query,
};
@ -94,7 +83,4 @@ TaxesReport.propTypes = {
query: PropTypes.object.isRequired,
};
export default withDispatch( ( dispatch ) => {
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
return { addCesSurveyForAnalytics };
} )( TaxesReport );
export default TaxesReport;

View File

@ -3,6 +3,7 @@
*/
import { __, _x } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { dispatch } from '@wordpress/data';
/**
* Internal dependencies
@ -12,6 +13,7 @@ import {
getProductLabels,
getVariationLabels,
} from '../../../lib/async-requests';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
const VARIATIONS_REPORT_CHARTS_FILTER =
'woocommerce_admin_variations_report_charts';
@ -20,6 +22,8 @@ const VARIATIONS_REPORT_FILTERS_FILTER =
const VARIATIONS_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_variations_report_advanced_filters';
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
export const charts = applyFilters( VARIATIONS_REPORT_CHARTS_FILTER, [
{
key: 'items_sold',
@ -102,6 +106,7 @@ export const filters = applyFilters( VARIATIONS_REPORT_FILTERS_FILTER, [
title: __( 'Compare Variations', 'woocommerce-admin' ),
update: __( 'Compare', 'woocommerce-admin' ),
},
onClick: addCesSurveyForAnalytics,
},
},
{

View File

@ -4,7 +4,6 @@
import { __ } from '@wordpress/i18n';
import { Fragment } from '@wordpress/element';
import PropTypes from 'prop-types';
import { withDispatch } from '@wordpress/data';
/**
* Internal dependencies
@ -16,7 +15,6 @@ import ReportError from '../../components/report-error';
import ReportSummary from '../../components/report-summary';
import VariationsReportTable from './table';
import ReportFilters from '../../components/report-filters';
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
const getChartMeta = ( { query } ) => {
const isCompareView =
@ -33,13 +31,7 @@ const getChartMeta = ( { query } ) => {
const VariationsReport = ( props ) => {
const { itemsLabel, mode } = getChartMeta( props );
const {
path,
query,
isError,
isRequesting,
addCesSurveyForAnalytics,
} = props;
const { path, query, isError, isRequesting } = props;
if ( isError ) {
return <ReportError isError />;
@ -53,10 +45,6 @@ const VariationsReport = ( props ) => {
chartQuery.segmentby = 'variation';
}
filters[ 0 ].filters.find(
( item ) => item.value === 'compare-variations'
).settings.onClick = addCesSurveyForAnalytics;
return (
<Fragment>
<ReportFilters
@ -103,7 +91,4 @@ VariationsReport.propTypes = {
query: PropTypes.object.isRequired,
};
export default withDispatch( ( dispatch ) => {
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
return { addCesSurveyForAnalytics };
} )( VariationsReport );
export default VariationsReport;

View File

@ -101,6 +101,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Fix: Missed DB version number updates causing unnecessary upgrades. #6818
- Fix: Parsing bad JSON string data from user WooCommerce meta. #6819
- Fix: Remove PayPal for India #6828
- Fix: Report filters expecting specific ordering. #6847
- Performance: Avoid updating customer info synchronously from the front end. #6765
- Tweak: Add settings_section event prop for CES #6762
- Tweak: Refactor payments to allow management of methods #6786