* Add currency extension

* use wcSettings

* save

* get revenue working

* all reports

* remove error log

* better rename

* add column

* persist queries

* go back to individual hooks

* comments

* address feedback
This commit is contained in:
Paul Sealock 2019-12-06 11:38:26 +13:00 committed by GitHub
parent 6a8124ffd0
commit 8205112732
11 changed files with 447 additions and 96 deletions

View File

@ -10,8 +10,8 @@ import { applyFilters } from '@wordpress/hooks';
*/
import { getCategoryLabels } from 'lib/async-requests';
const CATEGORY_REPORT_CHARTS_FILTER = 'woocommerce_admin_category_report_charts';
const CATEGORY_REPORT_FILTERS_FILTER = 'woocommerce_admin_category_report_filters';
const CATEGORY_REPORT_CHARTS_FILTER = 'woocommerce_admin_categories_report_charts';
const CATEGORY_REPORT_FILTERS_FILTER = 'woocommerce_admin_categories_report_filters';
const CATEGORY_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_category_report_advanced_filters';

View File

@ -10,8 +10,8 @@ import { applyFilters } from '@wordpress/hooks';
*/
import { getCouponLabels } from 'lib/async-requests';
const COUPON_REPORT_CHARTS_FILTER = 'woocommerce_admin_coupon_report_charts';
const COUPON_REPORT_FILTERS_FILTER = 'woocommerce_admin_coupon_report_filters';
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';
export const charts = applyFilters( COUPON_REPORT_CHARTS_FILTER, [

View File

@ -22,6 +22,7 @@ import { formatValue } from 'lib/number-format';
import { QUERY_DEFAULTS } from 'wc-api/constants';
import ReportTable from 'analytics/components/report-table';
import withSelect from 'wc-api/with-select';
import { getReportTableQuery } from 'wc-api/reports/utils';
class RevenueReportTable extends Component {
constructor() {
@ -238,7 +239,7 @@ class RevenueReportTable extends Component {
export default compose(
withSelect( ( select, props ) => {
const { query } = props;
const { query, filters, advancedFilters } = props;
const datesFromQuery = getCurrentDates( query );
const { getReportStats, getReportStatsError, isReportStatsRequesting } = select( 'wc-api' );
@ -252,9 +253,17 @@ export default compose(
after: appendTimestamp( datesFromQuery.primary.after, 'start' ),
before: appendTimestamp( datesFromQuery.primary.before, 'end' ),
};
const revenueData = getReportStats( 'revenue', tableQuery );
const isError = Boolean( getReportStatsError( 'revenue', tableQuery ) );
const isRequesting = isReportStatsRequesting( 'revenue', tableQuery );
const filteredTableQuery = getReportTableQuery( {
endpoint: 'revenue',
query,
select,
tableQuery,
filters,
advancedFilters,
} );
const revenueData = getReportStats( 'revenue', filteredTableQuery );
const isError = Boolean( getReportStatsError( 'revenue', filteredTableQuery ) );
const isRequesting = isReportStatsRequesting( 'revenue', filteredTableQuery );
return {
tableData: {

View File

@ -8,6 +8,7 @@ import { compose } from '@wordpress/compose';
import { partial, filter, get } from 'lodash';
import { IconButton, Icon, Dropdown, Button } from '@wordpress/components';
import { withDispatch } from '@wordpress/data';
import { applyFilters } from '@wordpress/hooks';
/**
* WooCommerce dependencies
@ -28,6 +29,9 @@ import { isOnboardingEnabled } from 'dashboard/utils';
import { getCurrentDates, getDateParamsFromQuery, isoDateFormat } from 'lib/date';
import ReportFilters from 'analytics/components/report-filters';
const DASHBOARD_FILTERS_FILTER = 'woocommerce_admin_dashboard_filters';
const filters = applyFilters( DASHBOARD_FILTERS_FILTER, [] );
class CustomizableDashboard extends Component {
constructor( props ) {
super( props );
@ -233,6 +237,7 @@ class CustomizableDashboard extends Component {
path={ path }
dateQuery={ dateQuery }
isoDateFormat={ isoDateFormat }
filters={ filters }
/>
{ sections.map( ( section, index ) => {
if ( section.isVisible ) {

View File

@ -126,7 +126,9 @@ export function getQueryFromConfig( config, advancedFilters, query ) {
return {};
}
return {};
return {
[ config.param ]: queryValue,
};
}
/**

View File

@ -0,0 +1,97 @@
/** @format */
/**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
/**
* Add a dropdown to a report.
*
* @param {array} filters - set of filters in a report.
* @return {array} amended set of filters.
*/
const addCurrencyFilters = filters => {
return [
{
label: __( 'Currency', 'plugin-domain' ),
staticParams: [],
param: 'currency',
showFilters: () => true,
defaultValue: 'USD',
filters: [ ...( wcSettings.multiCurrency || [] ) ],
},
...filters,
];
};
addFilter( 'woocommerce_admin_revenue_report_filters', 'plugin-domain', addCurrencyFilters );
addFilter( 'woocommerce_admin_orders_report_filters', 'plugin-domain', addCurrencyFilters );
addFilter( 'woocommerce_admin_products_report_filters', 'plugin-domain', addCurrencyFilters );
addFilter( 'woocommerce_admin_categories_report_filters', 'plugin-domain', addCurrencyFilters );
addFilter( 'woocommerce_admin_coupons_report_filters', 'plugin-domain', addCurrencyFilters );
addFilter( 'woocommerce_admin_taxes_report_filters', 'plugin-domain', addCurrencyFilters );
addFilter( 'woocommerce_admin_dashboard_filters', 'plugin-domain', addCurrencyFilters );
/**
* Add a column to a report table. Include a header and
* manipulate each row to handle the added parameter.
*
* @param {object} reportTableData - table data.
* @return {object} - table data.
*/
const addTableColumn = reportTableData => {
const includedReports = [
'revenue',
'products',
'orders',
'products',
'categories',
'coupons',
'taxes',
];
if ( ! includedReports.includes( reportTableData.endpoint ) ) {
return reportTableData;
}
const newHeaders = [
{
label: 'Currency',
key: 'currency',
},
...reportTableData.headers,
];
const newRows = reportTableData.rows.map( ( row, index ) => {
const item = reportTableData.items.data[ index ];
const newRow = [
{
display: item.currency,
value: item.currency,
},
...row,
];
return newRow;
} );
reportTableData.headers = newHeaders;
reportTableData.rows = newRows;
return reportTableData;
};
addFilter( 'woocommerce_admin_report_table', 'plugin-domain', addTableColumn );
/**
* Add 'currency' to the list of persisted queries so that the parameter remains
* when navigating from report to report.
*
* @param {array} params - array of report slugs.
* @return {array} - array of report slugs including 'currency'.
*/
const persistQueries = params => {
params.push( 'currency' );
return params;
};
addFilter( 'woocommerce_admin_persisted_queries', 'plugin-domain', persistQueries );

View File

@ -0,0 +1,196 @@
<?php
/**
* Plugin Name: WooCommerce Admin SQL modification Example
*
* @package WC_Admin
*/
/**
* Get the currencies available.
*
* @return array
*/
function get_currencies() {
return array(
array(
'label' => __( 'United States Dollar', 'woocommerce-admin' ),
'value' => 'USD',
),
array(
'label' => __( 'New Zealand Dollar', 'woocommerce-admin' ),
'value' => 'NZD',
),
array(
'label' => __( 'South African Rand', 'woocommerce-admin' ),
'value' => 'ZAR',
),
);
}
/**
* Register the JS.
*/
function add_report_register_script() {
if ( ! class_exists( 'Automattic\WooCommerce\Admin\Loader' ) || ! \Automattic\WooCommerce\Admin\Loader::is_admin_page() ) {
return;
}
wp_register_script(
'sql-modification',
plugins_url( '/dist/index.js', __FILE__ ),
array(
'wp-hooks',
'wp-element',
'wp-i18n',
'wp-plugins',
'wc-components',
),
filemtime( dirname( __FILE__ ) . '/dist/index.js' ),
true
);
wp_enqueue_script( 'sql-modification' );
// todo: This is not the right way to interact with wcSettings. Update once WooCommerce 3.9 is available.
wp_add_inline_script(
'sql-modification',
"wcSettings.multiCurrency = JSON.parse( decodeURIComponent( '"
. esc_js( rawurlencode( wp_json_encode( get_currencies() ) ) )
. "' ) );",
'before'
);
}
add_action( 'admin_enqueue_scripts', 'add_report_register_script' );
/**
* Add the query argument `currency` for caching purposes. Otherwise, a
* change of the currency will return the previous request's data.
*
* @param array $args query arguments.
* @return array augmented query arguments.
*/
function apply_currency_arg( $args ) {
$currency = 'USD';
if ( isset( $_GET['currency'] ) ) {
$currency = sanitize_text_field( wp_unslash( $_GET['currency'] ) );
}
$args['currency'] = $currency;
return $args;
}
add_filter( 'woocommerce_reports_revenue_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_orders_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_orders_stats_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_products_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_products_stats_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_categories_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_coupons_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_coupons_stats_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_taxes_query_args', 'apply_currency_arg' );
add_filter( 'woocommerce_reports_taxes_stats_query_args', 'apply_currency_arg' );
/**
* Add a JOIN clause.
*
* @param array $clauses an array of JOIN query strings.
* @return array augmented clauses.
*/
function add_join_subquery( $clauses ) {
global $wpdb;
$clauses[] = "JOIN {$wpdb->postmeta} currency_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = currency_postmeta.post_id";
return $clauses;
}
add_filter( 'wc_admin_clauses_join_orders_subquery', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_order_stats_total', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_order_stats_interval', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_products_subquery', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_product_stats_total', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_product_stats_interval', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_categories_subquery', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_coupons_subquery', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_coupons_stats_total', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_coupons_stats_interval', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_taxes_subquery', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_tax_stats_total', 'add_join_subquery' );
add_filter( 'wc_admin_clauses_join_tax_stats_interval', 'add_join_subquery' );
/**
* Add a WHERE clause.
*
* @param array $clauses an array of WHERE query strings.
* @return array augmented clauses.
*/
function add_where_subquery( $clauses ) {
$currency = 'USD';
if ( isset( $_GET['currency'] ) ) {
$currency = sanitize_text_field( wp_unslash( $_GET['currency'] ) );
}
$clauses[] = "AND currency_postmeta.meta_key = '_order_currency' AND currency_postmeta.meta_value = '{$currency}'";
return $clauses;
}
add_filter( 'wc_admin_clauses_where_orders_subquery', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_order_stats_total', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_order_stats_interval', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_products_subquery', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_product_stats_total', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_product_stats_interval', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_categories_subquery', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_coupons_subquery', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_coupons_stats_total', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_coupons_stats_interval', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_taxes_subquery', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_tax_stats_total', 'add_where_subquery' );
add_filter( 'wc_admin_clauses_where_tax_stats_interval', 'add_where_subquery' );
/**
* Add a SELECT clause.
*
* @param array $clauses an array of WHERE query strings.
* @return array augmented clauses.
*/
function add_select_subquery( $clauses ) {
$clauses[] = ', currency_postmeta.meta_value AS currency';
return $clauses;
}
add_filter( 'wc_admin_clauses_select_orders_subquery', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_order_stats_total', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_order_stats_interval', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_products_subquery', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_product_stats_total', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_product_stats_interval', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_categories_subquery', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_coupons_subquery', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_coupons_stats_total', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_coupons_stats_interval', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_taxes_subquery', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_tax_stats_total', 'add_select_subquery' );
add_filter( 'wc_admin_clauses_select_tax_stats_interval', 'add_select_subquery' );

View File

@ -9625,24 +9625,25 @@
"dependencies": {
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"resolved": false,
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"optional": true
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
"resolved": false,
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"optional": true
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
"resolved": false,
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==",
"optional": true
},
"are-we-there-yet": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz",
"resolved": false,
"integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==",
"optional": true,
"requires": {
@ -9652,13 +9653,15 @@
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"resolved": false,
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"resolved": false,
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -9666,34 +9669,37 @@
},
"chownr": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz",
"resolved": false,
"integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==",
"optional": true
},
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
"resolved": false,
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"optional": true
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"resolved": false,
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
"resolved": false,
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
"optional": true
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"resolved": false,
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"optional": true
},
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"resolved": false,
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"optional": true,
"requires": {
@ -9702,25 +9708,25 @@
},
"deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
"resolved": false,
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==",
"optional": true
},
"delegates": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
"resolved": false,
"integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=",
"optional": true
},
"detect-libc": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz",
"resolved": false,
"integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=",
"optional": true
},
"fs-minipass": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz",
"resolved": false,
"integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==",
"optional": true,
"requires": {
@ -9729,13 +9735,13 @@
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"resolved": false,
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"optional": true
},
"gauge": {
"version": "2.7.4",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz",
"resolved": false,
"integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=",
"optional": true,
"requires": {
@ -9751,7 +9757,7 @@
},
"glob": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
"resolved": false,
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
"optional": true,
"requires": {
@ -9765,13 +9771,13 @@
},
"has-unicode": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"resolved": false,
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=",
"optional": true
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"resolved": false,
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"optional": true,
"requires": {
@ -9780,7 +9786,7 @@
},
"ignore-walk": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.1.tgz",
"resolved": false,
"integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==",
"optional": true,
"requires": {
@ -9789,7 +9795,7 @@
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"resolved": false,
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"optional": true,
"requires": {
@ -9799,46 +9805,51 @@
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
"resolved": false,
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"optional": true
},
"ini": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
"resolved": false,
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==",
"optional": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"resolved": false,
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"resolved": false,
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
"optional": true
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"resolved": false,
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
"resolved": false,
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"optional": true
},
"minipass": {
"version": "2.3.5",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz",
"resolved": false,
"integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==",
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -9846,7 +9857,7 @@
},
"minizlib": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz",
"resolved": false,
"integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==",
"optional": true,
"requires": {
@ -9855,21 +9866,22 @@
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"resolved": false,
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"optional": true,
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"resolved": false,
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==",
"optional": true
},
"needle": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/needle/-/needle-2.3.0.tgz",
"resolved": false,
"integrity": "sha512-QBZu7aAFR0522EyaXZM0FZ9GLpq6lvQ3uq8gteiDUp7wKdy0lSd2hPlgFwVuW1CBkfEs9PfDQsQzZghLs/psdg==",
"optional": true,
"requires": {
@ -9880,7 +9892,7 @@
},
"node-pre-gyp": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz",
"resolved": false,
"integrity": "sha512-4KghwV8vH5k+g2ylT+sLTjy5wmUOb9vPhnM8NHvRf9dHmnW/CndrFXy2aRPaPST6dugXSdHXfeaHQm77PIz/1A==",
"optional": true,
"requires": {
@ -9898,7 +9910,7 @@
},
"nopt": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz",
"resolved": false,
"integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=",
"optional": true,
"requires": {
@ -9908,13 +9920,13 @@
},
"npm-bundled": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.0.6.tgz",
"resolved": false,
"integrity": "sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==",
"optional": true
},
"npm-packlist": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.1.tgz",
"resolved": false,
"integrity": "sha512-+TcdO7HJJ8peiiYhvPxsEDhF3PJFGUGRcFsGve3vxvxdcpO2Z4Z7rkosRM0kWj6LfbK/P0gu3dzk5RU1ffvFcw==",
"optional": true,
"requires": {
@ -9924,7 +9936,7 @@
},
"npmlog": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"resolved": false,
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"optional": true,
"requires": {
@ -9936,38 +9948,40 @@
},
"number-is-nan": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
"resolved": false,
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
"optional": true
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"resolved": false,
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
"optional": true
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"resolved": false,
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"optional": true,
"requires": {
"wrappy": "1"
}
},
"os-homedir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
"resolved": false,
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
"optional": true
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"resolved": false,
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
"optional": true
},
"osenv": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz",
"resolved": false,
"integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==",
"optional": true,
"requires": {
@ -9977,19 +9991,19 @@
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"resolved": false,
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"optional": true
},
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
"resolved": false,
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==",
"optional": true
},
"rc": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
"resolved": false,
"integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==",
"optional": true,
"requires": {
@ -10001,7 +10015,7 @@
"dependencies": {
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"resolved": false,
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"optional": true
}
@ -10009,7 +10023,7 @@
},
"readable-stream": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"resolved": false,
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"optional": true,
"requires": {
@ -10024,7 +10038,7 @@
},
"rimraf": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
"resolved": false,
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
"optional": true,
"requires": {
@ -10033,43 +10047,45 @@
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
"resolved": false,
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"resolved": false,
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"optional": true
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"resolved": false,
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"optional": true
},
"semver": {
"version": "5.7.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
"resolved": false,
"integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==",
"optional": true
},
"set-blocking": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"resolved": false,
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=",
"optional": true
},
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"resolved": false,
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"optional": true
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"resolved": false,
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -10078,7 +10094,7 @@
},
"string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"resolved": false,
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"optional": true,
"requires": {
@ -10087,21 +10103,22 @@
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"resolved": false,
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
},
"strip-json-comments": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
"resolved": false,
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
"optional": true
},
"tar": {
"version": "4.4.8",
"resolved": "https://registry.npmjs.org/tar/-/tar-4.4.8.tgz",
"resolved": false,
"integrity": "sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ==",
"optional": true,
"requires": {
@ -10116,13 +10133,13 @@
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"resolved": false,
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"optional": true
},
"wide-align": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz",
"resolved": false,
"integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==",
"optional": true,
"requires": {
@ -10131,13 +10148,15 @@
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
"resolved": false,
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"optional": true
},
"yallist": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz",
"integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A=="
"resolved": false,
"integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==",
"optional": true
}
}
},

View File

@ -1,3 +1,7 @@
# (unreleased)
- `getPersistedQuery` Add a filter for extensions to add a persisted query, `woocommerce_admin_persisted_queries`.
# 4.0.0
## Breaking Changes
@ -5,6 +9,7 @@
- decouples `wcSettings` from the package (#3294)
- `getAdminLink` is no longer available from this package. It is exported on the `wcSettings` global via the woo-blocks plugin (v2.5 or WC 3.9) when enqueued via the `wc-settings` handle.
# 3.0.0
- `getHistory` updated to reflect path parameters in url query.

View File

@ -5,6 +5,7 @@
import { addQueryArgs } from '@wordpress/url';
import { parse } from 'qs';
import { pick, uniq } from 'lodash';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
@ -37,8 +38,17 @@ export const getPath = () => getHistory().location.pathname;
* @param {Object} query Query containing the parameters.
* @return {Object} Object containing the persisted queries.
*/
export const getPersistedQuery = ( query = navUtils.getQuery() ) =>
pick( query, [ 'period', 'compare', 'before', 'after', 'interval', 'type' ] );
export const getPersistedQuery = ( query = navUtils.getQuery() ) => {
const params = applyFilters( 'woocommerce_admin_persisted_queries', [
'period',
'compare',
'before',
'after',
'interval',
'type',
] );
return pick( query, params );
};
/**
* Get an array of IDs from a comma-separated query parameter.
@ -63,14 +73,18 @@ export function getIdsFromQuery( queryString = '' ) {
*/
export function getSearchWords( query = navUtils.getQuery() ) {
if ( typeof query !== 'object' ) {
throw new Error( 'Invalid parameter passed to getSearchWords, it expects an object or no parameters.' );
throw new Error(
'Invalid parameter passed to getSearchWords, it expects an object or no parameters.'
);
}
const { search } = query;
if ( ! search ) {
return [];
}
if ( typeof search !== 'string' ) {
throw new Error( 'Invalid \'search\' type. getSearchWords expects query\'s \'search\' property to be a string.' );
throw new Error(
"Invalid 'search' type. getSearchWords expects query's 'search' property to be a string."
);
}
return search.split( ',' ).map( searchWord => searchWord.replace( '%2C', ',' ) );
}
@ -118,11 +132,15 @@ export function onQueryChange( param, path = getPath(), query = getQuery() ) {
return ( key, dir ) => updateQueryString( { orderby: key, order: dir }, path, query );
case 'compare':
return ( key, queryParam, ids ) =>
updateQueryString( {
[ queryParam ]: `compare-${ key }`,
[ key ]: ids,
search: undefined,
}, path, query );
updateQueryString(
{
[ queryParam ]: `compare-${ key }`,
[ key ]: ids,
search: undefined,
},
path,
query
);
default:
return value => updateQueryString( { [ param ]: value }, path, query );
}

View File

@ -41,7 +41,7 @@ class Query extends ReportsQuery {
* @return array
*/
public function get_data() {
$args = apply_filters( 'woocommerce_reports_coupons_query_args', $this->get_query_vars() );
$args = apply_filters( 'woocommerce_reports_coupons_stats_query_args', $this->get_query_vars() );
$data_store = \WC_Data_Store::load( 'report-coupons-stats' );
$results = $data_store->get_data( $args );