From a3af7d96b9418ec15b66e35afb71278a02de1aab Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Fri, 14 Feb 2020 16:25:48 -0700
Subject: [PATCH] Keep the progress indicator in the row-actions visible while
 the export/erase is happening, even when that cell isn't hovered over.

---
 src/js/_enqueues/admin/privacy-tools.js | 53 ++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 10 deletions(-)

diff --git a/src/js/_enqueues/admin/privacy-tools.js b/src/js/_enqueues/admin/privacy-tools.js
index 5d5a2067a4..6a9f93b4c8 100644
--- a/src/js/_enqueues/admin/privacy-tools.js
+++ b/src/js/_enqueues/admin/privacy-tools.js
@@ -55,11 +55,27 @@ jQuery( document ).ready( function( $ ) {
 		});
 	}
 
+	function showRowActions( $rowActions, $hasRowActions ) {
+		if ( $rowActions.length > 0 ) {
+			$( $rowActions ).addClass( 'visible' );
+			$( $hasRowActions ).removeClass( 'has-row-actions' );
+		}
+	}
+
+	function hideRowActions( $rowActions, $hasRowActions ) {
+		if ( $rowActions.length > 0 ) {
+			$( $rowActions ).removeClass( 'visible' );
+			$( $hasRowActions ).addClass( 'has-row-actions' );
+		}
+	}
+
 	$( '.export-personal-data-handle' ).click( function( event ) {
 		var $this          = $( this ),
 			$action        = $this.parents( '.export-personal-data' ),
 			$requestRow    = $this.parents( 'tr' ),
 			$progress      = $requestRow.find( '.export-progress' ),
+			$rowActions    = $this.parents( '.row-actions' ),
+			$hasRowActions = $( '.has-row-actions' ),
 			requestID      = $action.data( 'request-id' ),
 			nonce          = $action.data( 'nonce' ),
 			exportersCount = $action.data( 'exporters-count' ),
@@ -68,6 +84,9 @@ jQuery( document ).ready( function( $ ) {
 		event.preventDefault();
 		event.stopPropagation();
 
+		// have to do this before the `$action.blur()`.
+		showRowActions( $rowActions, $hasRowActions );
+
 		$action.blur();
 		clearResultsAfterRow( $requestRow );
 		setExportProgress( 0 );
@@ -77,6 +96,8 @@ jQuery( document ).ready( function( $ ) {
 
 			setActionState( $action, 'export-personal-data-success' );
 
+			hideRowActions( $rowActions, $hasRowActions );
+
 			appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
 			$this.hide();
 
@@ -92,6 +113,8 @@ jQuery( document ).ready( function( $ ) {
 			if ( errorMessage ) {
 				appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] );
 			}
+
+			hideRowActions( $rowActions, $hasRowActions );
 		}
 
 		function setExportProgress( exporterIndex ) {
@@ -147,19 +170,24 @@ jQuery( document ).ready( function( $ ) {
 	});
 
 	$( '.remove-personal-data-handle' ).click( function( event ) {
-		var $this         = $( this ),
-			$action       = $this.parents( '.remove-personal-data' ),
-			$requestRow   = $this.parents( 'tr' ),
-			$progress     = $requestRow.find( '.erasure-progress' ),
-			requestID     = $action.data( 'request-id' ),
-			nonce         = $action.data( 'nonce' ),
-			erasersCount  = $action.data( 'erasers-count' ),
-			hasRemoved    = false,
-			hasRetained   = false,
-			messages      = [];
+		var $this          = $( this ),
+			$action        = $this.parents( '.remove-personal-data' ),
+			$requestRow    = $this.parents( 'tr' ),
+			$progress      = $requestRow.find( '.erasure-progress' ),
+			requestID      = $action.data( 'request-id' ),
+			$rowActions    = $this.parents( '.row-actions' ),
+			$hasRowActions = $( '.has-row-actions' ),
+			nonce          = $action.data( 'nonce' ),
+			erasersCount   = $action.data( 'erasers-count' ),
+			hasRemoved     = false,
+			hasRetained    = false,
+			messages       = [];
 
 		event.stopPropagation();
 
+		// have to do this before the `$action.blur()`.
+		showRowActions( $rowActions, $hasRowActions );
+
 		$action.blur();
 		clearResultsAfterRow( $requestRow );
 		setErasureProgress( 0 );
@@ -170,6 +198,8 @@ jQuery( document ).ready( function( $ ) {
 
 			setActionState( $action, 'remove-personal-data-success' );
 
+			hideRowActions( $rowActions, $hasRowActions );
+
 			if ( false === hasRemoved ) {
 				if ( false === hasRetained ) {
 					summaryMessage = strings.noDataFound;
@@ -191,6 +221,9 @@ jQuery( document ).ready( function( $ ) {
 
 		function onErasureFailure() {
 			setActionState( $action, 'remove-personal-data-failed' );
+
+			hideRowActions( $rowActions, $hasRowActions );
+
 			appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] );
 		}
 
-- 
2.19.0.windows.1

