diff --git a/plugins/woocommerce-admin/client/analytics/report/downloads/config.js b/plugins/woocommerce-admin/client/analytics/report/downloads/config.js index 12a86982a6e..a9694e358f3 100644 --- a/plugins/woocommerce-admin/client/analytics/report/downloads/config.js +++ b/plugins/woocommerce-admin/client/analytics/report/downloads/config.js @@ -12,7 +12,7 @@ import { NAMESPACE } from 'store/constants'; export const charts = [ { - key: 'downloads_count', + key: 'download_count', label: __( 'Downloads', 'wc-admin' ), type: 'number', }, @@ -70,7 +70,7 @@ export const advancedFilters = { } ) ), }, }, - username: { + user: { labels: { add: __( 'Username', 'wc-admin' ), placeholder: __( 'Search customer username', 'wc-admin' ), diff --git a/plugins/woocommerce-admin/client/analytics/report/downloads/index.js b/plugins/woocommerce-admin/client/analytics/report/downloads/index.js index 6f6518544af..0a274981034 100644 --- a/plugins/woocommerce-admin/client/analytics/report/downloads/index.js +++ b/plugins/woocommerce-admin/client/analytics/report/downloads/index.js @@ -29,7 +29,6 @@ export default class DownloadsReport extends Component { query={ query } path={ path } filters={ filters } - showDatePicker={ false } advancedFilters={ advancedFilters } /> { - const { date, file_name, ip_address, order_id, product_id, user_id } = download; + const { _embedded, date, file_name, ip_address, order_id, product_id } = download; + const { name: productName } = _embedded.product[ 0 ]; + const { name: userName } = _embedded.user[ 0 ]; const productLink = getNewPath( persistedQuery, 'products', { filter: 'single_product', @@ -86,10 +89,10 @@ export default class CouponsReportTable extends Component { { display: ( - { product_id } + { productName } ), - value: product_id, + value: productName, }, { display: file_name, @@ -104,8 +107,8 @@ export default class CouponsReportTable extends Component { value: order_id, }, { - display: user_id, - value: user_id, + display: userName, + value: userName, }, { display: ip_address, @@ -119,14 +122,20 @@ export default class CouponsReportTable extends Component { if ( ! totals ) { return []; } + const { query } = this.props; + const dates = getCurrentDates( query ); + const after = moment( dates.primary.after ); + const before = moment( dates.primary.before ); + const days = before.diff( after, 'days' ) + 1; + return [ { - label: _n( 'day', 'days', totals.days, 'wc-admin' ), - value: numberFormat( totals.days ), // @TODO it's not defined + label: _n( 'day', 'days', days, 'wc-admin' ), + value: numberFormat( days ), }, { - label: _n( 'download', 'downloads', totals.downloads_count, 'wc-admin' ), - value: numberFormat( totals.downloads_count ), + label: _n( 'download', 'downloads', totals.download_count, 'wc-admin' ), + value: numberFormat( totals.download_count ), }, ]; } @@ -141,6 +150,9 @@ export default class CouponsReportTable extends Component { getRowsContent={ this.getRowsContent } getSummary={ this.getSummary } query={ query } + tableQuery={ { + _embed: true, + } } title={ __( 'Downloads', 'wc-admin' ) } columnPrefsKey="downloads_report_columns" /> diff --git a/plugins/woocommerce-admin/client/store/reports/utils.js b/plugins/woocommerce-admin/client/store/reports/utils.js index fb1ff9379f9..0cb56aecd1e 100644 --- a/plugins/woocommerce-admin/client/store/reports/utils.js +++ b/plugins/woocommerce-admin/client/store/reports/utils.js @@ -19,19 +19,21 @@ import { formatCurrency } from '@woocommerce/currency'; import { MAX_PER_PAGE, QUERY_DEFAULTS } from 'store/constants'; import * as categoriesConfig from 'analytics/report/categories/config'; import * as couponsConfig from 'analytics/report/coupons/config'; +import * as customersConfig from 'analytics/report/customers/config'; +import * as downloadsConfig from 'analytics/report/downloads/config'; import * as ordersConfig from 'analytics/report/orders/config'; import * as productsConfig from 'analytics/report/products/config'; import * as taxesConfig from 'analytics/report/taxes/config'; -import * as customersConfig from 'analytics/report/customers/config'; import * as reportsUtils from './utils'; const reportConfigs = { categories: categoriesConfig, coupons: couponsConfig, + customers: customersConfig, + downloads: downloadsConfig, orders: ordersConfig, products: productsConfig, taxes: taxesConfig, - customers: customersConfig, }; export function getFilterQuery( endpoint, query ) { diff --git a/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js b/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js index 9ec07af3caa..5acd23fd22e 100644 --- a/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js +++ b/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js @@ -17,7 +17,7 @@ import { NAMESPACE } from '../../constants'; import { SWAGGERNAMESPACE } from 'store/constants'; // TODO: Remove once swagger endpoints are phased out. -const swaggerEndpoints = [ 'customers', 'downloads' ]; +const swaggerEndpoints = [ 'customers' ]; const typeEndpointMap = { 'report-items-query-orders': 'orders', diff --git a/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js b/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js index 133fff60eac..5d0d8876be3 100644 --- a/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js +++ b/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js @@ -16,9 +16,9 @@ import { getResourceIdentifier, getResourcePrefix } from '../../utils'; import { NAMESPACE } from '../../constants'; import { SWAGGERNAMESPACE } from 'store/constants'; -const statEndpoints = [ 'orders', 'revenue', 'products', 'taxes', 'coupons' ]; +const statEndpoints = [ 'coupons', 'downloads', 'orders', 'products', 'revenue', 'taxes' ]; // TODO: Remove once swagger endpoints are phased out. -const swaggerEndpoints = [ 'categories', 'downloads' ]; +const swaggerEndpoints = [ 'categories' ]; const typeEndpointMap = { 'report-stats-query-orders': 'orders', diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php index a998d73d0ad..45092d0d4e7 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-downloads-stats-data-store.php @@ -12,6 +12,15 @@ defined( 'ABSPATH' ) || exit; */ class WC_Admin_Reports_Downloads_Stats_Data_Store extends WC_Admin_Reports_Downloads_Data_Store implements WC_Admin_Reports_Data_Store_Interface { + /** + * Mapping columns to data type to return correct response types. + * + * @var array + */ + protected $column_types = array( + 'download_count' => 'intval', + ); + /** * SQL columns to select in the db query and their mapping to SQL code. * diff --git a/plugins/woocommerce-admin/packages/date/src/index.js b/plugins/woocommerce-admin/packages/date/src/index.js index 06bae8d80c6..06614b44aea 100644 --- a/plugins/woocommerce-admin/packages/date/src/index.js +++ b/plugins/woocommerce-admin/packages/date/src/index.js @@ -262,9 +262,9 @@ function getDateValue( period, compare, after, before ) { * Add default date-related parameters to a query object * * @param {string} [period] - period value, ie `last_week` - * @param {string} [compare] - compare valuer, ie previous_year - * @param {string} [after] - date in iso date format, ie 2018-07-03 - * @param {string} [before] - date in iso date format, ie 2018-07-03 + * @param {string} [compare] - compare value, ie `previous_year` + * @param {string} [after] - date in iso date format, ie `2018-07-03` + * @param {string} [before] - date in iso date format, ie `2018-07-03` * @return {DateParams} - date parameters derived from query parameters with added defaults */ export const getDateParamsFromQuery = ( { period, compare, after, before } ) => { @@ -281,9 +281,9 @@ export const getDateParamsFromQuery = ( { period, compare, after, before } ) => * * @param {Object} query - date parameters derived from query parameters * @property {string} [period] - period value, ie `last_week` - * @property {string} [compare] - compare valuer, ie previous_year - * @property {string} [after] - date in iso date format, ie 2018-07-03 - * @property {string} [before] - date in iso date format, ie 2018-07-03 + * @property {string} [compare] - compare value, ie `previous_year` + * @property {string} [after] - date in iso date format, ie `2018-07-03` + * @property {string} [before] - date in iso date format, ie `2018-07-03` * @return {{primary: DateValue, secondary: DateValue}} - Primary and secondary DateValue objects */ export const getCurrentDates = query => {