2018-11-22 23:12:12 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
import { dispatch } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { stringifyQuery } from '@woocommerce/navigation';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-31 06:42:46 +00:00
|
|
|
import { NAMESPACE } from 'store/constants';
|
2018-11-22 23:12:12 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
async getReportItems( ...args ) {
|
|
|
|
const [ endpoint, query ] = args.slice( -2 );
|
|
|
|
|
|
|
|
try {
|
2018-11-29 14:03:04 +00:00
|
|
|
const response = await apiFetch( {
|
|
|
|
parse: false,
|
2018-11-22 23:12:12 +00:00
|
|
|
path: NAMESPACE + 'reports/' + endpoint + stringifyQuery( query ),
|
|
|
|
} );
|
|
|
|
|
2018-11-29 14:03:04 +00:00
|
|
|
const itemsData = await response.json();
|
|
|
|
const totalCount = parseInt( response.headers.get( 'x-wp-total' ) );
|
|
|
|
dispatch( 'wc-admin' ).setReportItems( endpoint, query, itemsData, totalCount );
|
2018-11-22 23:12:12 +00:00
|
|
|
} catch ( error ) {
|
|
|
|
dispatch( 'wc-admin' ).setReportItemsError( endpoint, query );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|