From b7acbd9b2f0d14a23c918236810e23cf8f7ee863 Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Mon, 12 Nov 2018 16:38:58 +1300 Subject: [PATCH] Add Product Detail link in table --- .../client/analytics/report/products/config.js | 2 +- .../client/analytics/report/products/table.js | 11 +++++++++-- .../components/src/filters/filter/index.js | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/report/products/config.js b/plugins/woocommerce-admin/client/analytics/report/products/config.js index a71127e56dc..1093531afa6 100644 --- a/plugins/woocommerce-admin/client/analytics/report/products/config.js +++ b/plugins/woocommerce-admin/client/analytics/report/products/config.js @@ -115,7 +115,7 @@ const variationsConfig = { { label: __( 'All Variations', 'wc-admin' ), value: 'all' }, { label: __( 'Comparison', 'wc-admin' ), - value: 'compare', + value: 'compare-variations', settings: { type: 'variations', param: 'variations', diff --git a/plugins/woocommerce-admin/client/analytics/report/products/table.js b/plugins/woocommerce-admin/client/analytics/report/products/table.js index a4bf5b894b9..1fa5c66576f 100644 --- a/plugins/woocommerce-admin/client/analytics/report/products/table.js +++ b/plugins/woocommerce-admin/client/analytics/report/products/table.js @@ -99,11 +99,18 @@ class ProductsReportTable extends Component { filter: 'advanced', product_includes: product_id, } ); + const productDetailLink = getNewPath( timeRelatedQuery, 'products', { + filter: 'single_product', + products: product_id, + } ); return [ { - // @TODO Must link to the product detail report. - display: name, + display: ( + + { name } + + ), value: name, }, { diff --git a/plugins/woocommerce-admin/packages/components/src/filters/filter/index.js b/plugins/woocommerce-admin/packages/components/src/filters/filter/index.js index a955cf0bf92..096270180d2 100644 --- a/plugins/woocommerce-admin/packages/components/src/filters/filter/index.js +++ b/plugins/woocommerce-admin/packages/components/src/filters/filter/index.js @@ -51,6 +51,20 @@ class FilterPicker extends Component { } } + componentDidUpdate( { query: prevQuery } ) { + const { query: nextQuery, config } = this.props; + if ( prevQuery[ config.param ] !== nextQuery[ [ config.param ] ] ) { + const selectedFilter = this.getFilter(); + if ( selectedFilter && 'Search' === selectedFilter.component ) { + /* eslint-disable react/no-did-update-set-state */ + this.setState( { nav: selectedFilter.path || [] } ); + /* eslint-enable react/no-did-update-set-state */ + const { param: filterParam, getLabels } = selectedFilter.settings; + getLabels( nextQuery[ filterParam ], nextQuery ).then( this.updateSelectedTag ); + } + } + } + updateSelectedTag( tags ) { this.setState( { selectedTag: tags[ 0 ] } ); }