From 0a1cec3d4e3d2d58a4e552d0662977929df5a3fe Mon Sep 17 00:00:00 2001 From: Bec Scott Date: Mon, 2 Nov 2020 16:08:17 +1000 Subject: [PATCH] Only show CES survey on correct page (https://github.com/woocommerce/woocommerce-admin/pull/5511) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Spike out customer effort score * Refactor CustomerEffortScore as Package (https://github.com/woocommerce/woocommerce-admin/pull/5342) * Tidy up _webpack.config.js * Fix linter issues * refactor setting up CES tracking, add try..catch around loading from localStorage * Add CES feature toggle (https://github.com/woocommerce/woocommerce-admin/pull/5387) * Add feature toggle to only enable the customer effort score in development * Move check into Loader * fix logic 🙄 Co-authored-by: Rebecca Scott * Add client-side check of the feature flag * fix tabs in config * Fix comment * Use product lifecycle and options * Add product count to tracks props * Use Loader::load_features instead of DIY * Only show the CES survey in the correct screen Co-authored-by: Rebecca Scott Co-authored-by: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com> --- .../customer-effort-score-tracks-container.js | 15 ++++++-- .../Features/CustomerEffortScoreTracks.php | 37 +++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/plugins/woocommerce-admin/client/customer-effort-score-tracks/customer-effort-score-tracks-container.js b/plugins/woocommerce-admin/client/customer-effort-score-tracks/customer-effort-score-tracks-container.js index 788979f1301..54b8ecac639 100644 --- a/plugins/woocommerce-admin/client/customer-effort-score-tracks/customer-effort-score-tracks-container.js +++ b/plugins/woocommerce-admin/client/customer-effort-score-tracks/customer-effort-score-tracks-container.js @@ -31,13 +31,19 @@ function CustomerEffortScoreTracksContainer( { return null; } - if ( queue.length ) { + const queueForPage = queue.filter( + ( item ) => + item.pagenow === window.pagenow && + item.adminpage === window.adminpage + ); + + if ( queueForPage.length ) { clearQueue(); } return ( <> - { queue.map( ( item, index ) => ( + { queueForPage.map( ( item, index ) => ( 'product', + 'adminpage' => 'post-php', 'props' => array( 'product_count' => $this->get_product_count(), ), @@ -118,6 +122,8 @@ class CustomerEffortScoreTracks { 'How easy was it to edit your product?', 'woocommerce-admin' ), + 'pagenow' => 'product', + 'adminpage' => 'post-php', 'props' => array( 'product_count' => $this->get_product_count(), ), @@ -133,14 +139,31 @@ class CustomerEffortScoreTracks { * sets the clear option. */ public function maybe_clear_ces_tracks_queue() { - $clear_ces_tracks_queue = get_option( - self::CLEAR_CES_TRACKS_QUEUE_OPTION_NAME, + $clear_ces_tracks_queue_for_page = get_option( + self::CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME, false ); - if ( $clear_ces_tracks_queue ) { - update_option( self::CES_TRACKS_QUEUE_OPTION_NAME, array() ); - update_option( self::CLEAR_CES_TRACKS_QUEUE_OPTION_NAME, false ); + if ( ! $clear_ces_tracks_queue_for_page ) { + return; } + + $queue = get_option( + self::CES_TRACKS_QUEUE_OPTION_NAME, + array() + ); + $remaining_items = array_filter( + $queue, + function( $item ) use ( $clear_ces_tracks_queue_for_page ) { + return $clear_ces_tracks_queue_for_page['pagenow'] !== $item['pagenow'] + || $clear_ces_tracks_queue_for_page['adminpage'] !== $item['adminpage']; + } + ); + + update_option( + self::CES_TRACKS_QUEUE_OPTION_NAME, + array_values( $remaining_items ) + ); + update_option( self::CLEAR_CES_TRACKS_QUEUE_FOR_PAGE_OPTION_NAME, false ); } }