Skip to content

Commit

Permalink
Privacy: Give progress indication for export and erasure.
Browse files Browse the repository at this point in the history
This adds a progress indicator for "Download Personal Data" and "Erase Personal Data" row actions, which can take a while with a lot of data.

Props garrett-eclipse, allendav, dominic_ks, xkon, karmatosed, birgire.
Fixes #44264.

git-svn-id: https://develop.svn.wordpress.org/trunk@47246 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Feb 10, 2020
1 parent c0c2fd3 commit a6a02ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
20 changes: 19 additions & 1 deletion src/js/_enqueues/admin/privacy-tools.js
Expand Up @@ -59,6 +59,7 @@ jQuery( document ).ready( function( $ ) {
var $this = $( this ),
$action = $this.parents( '.export-personal-data' ),
$requestRow = $this.parents( 'tr' ),
$progress = $requestRow.find( '.export-progress' );
requestID = $action.data( 'request-id' ),
nonce = $action.data( 'nonce' ),
exportersCount = $action.data( 'exporters-count' ),
Expand All @@ -69,6 +70,7 @@ jQuery( document ).ready( function( $ ) {

$action.blur();
clearResultsAfterRow( $requestRow );
setExportProgress( 0 );

function onExportDoneSuccess( zipUrl ) {
var summaryMessage = strings.emailSent;
Expand All @@ -77,7 +79,7 @@ jQuery( document ).ready( function( $ ) {

appendResultsAfterRow( $requestRow, 'notice-success', summaryMessage, [] );
$this.hide();

if ( 'undefined' !== typeof zipUrl ) {
window.location = zipUrl;
} else if ( ! sendAsEmail ) {
Expand All @@ -92,6 +94,12 @@ jQuery( document ).ready( function( $ ) {
}
}

function setExportProgress( exporterIndex ) {
var progress = ( exportersCount > 0 ? exporterIndex / exportersCount : 0 );
var progressString = Math.round( progress * 100 ).toString() + '%';
$progress.html( progressString );
}

function doNextExport( exporterIndex, pageIndex ) {
$.ajax(
{
Expand Down Expand Up @@ -120,6 +128,7 @@ jQuery( document ).ready( function( $ ) {
setTimeout( doNextExport( exporterIndex, pageIndex + 1 ) );
} else {
if ( exporterIndex < exportersCount ) {
setExportProgress( exporterIndex );
setTimeout( doNextExport( exporterIndex + 1, 1 ) );
} else {
onExportDoneSuccess( responseData.url );
Expand All @@ -141,6 +150,7 @@ jQuery( document ).ready( function( $ ) {
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' ),
Expand All @@ -152,6 +162,7 @@ jQuery( document ).ready( function( $ ) {

$action.blur();
clearResultsAfterRow( $requestRow );
setErasureProgress( 0 );

function onErasureDoneSuccess() {
var summaryMessage = strings.noDataFound;
Expand Down Expand Up @@ -183,6 +194,12 @@ jQuery( document ).ready( function( $ ) {
appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] );
}

function setErasureProgress( eraserIndex ) {
var progress = ( erasersCount > 0 ? eraserIndex / erasersCount : 0 );
var progressString = Math.round( progress * 100 ).toString() + '%';
$progress.html( progressString );
}

function doNextErasure( eraserIndex, pageIndex ) {
$.ajax({
url: window.ajaxurl,
Expand Down Expand Up @@ -214,6 +231,7 @@ jQuery( document ).ready( function( $ ) {
setTimeout( doNextErasure( eraserIndex, pageIndex + 1 ) );
} else {
if ( eraserIndex < erasersCount ) {
setErasureProgress( eraserIndex );
setTimeout( doNextErasure( eraserIndex + 1, 1 ) );
} else {
onErasureDoneSuccess();
Expand Down
Expand Up @@ -57,7 +57,7 @@ public function column_email( $item ) {
'">';

$download_data_markup .= '<span class="export-personal-data-idle"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data' ) . '</button></span>' .
'<span class="export-personal-data-processing hidden">' . __( 'Downloading Data...' ) . '</span>' .
'<span class="export-personal-data-processing hidden">' . __( 'Downloading Data...' ) . ' <span class="export-progress"></span></span>' .
'<span class="export-personal-data-success hidden"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download Personal Data Again' ) . '</button></span>' .
'<span class="export-personal-data-failed hidden">' . __( 'Download failed.' ) . ' <button type="button" class="button-link">' . __( 'Retry' ) . '</button></span>';

Expand Down Expand Up @@ -100,7 +100,7 @@ public function column_next_steps( $item ) {

?>
<span class="export-personal-data-idle"><button type="button" class="button export-personal-data-handle"><?php _e( 'Send Export Link' ); ?></button></span>
<span class="export-personal-data-processing button updating-message hidden"><?php _e( 'Sending Email...' ); ?></span>
<span class="export-personal-data-processing button updating-message hidden"><?php _e( 'Sending Email...' ); ?> <span class="export-progress"></span></span>
<span class="export-personal-data-success success-message hidden"><?php _e( 'Email sent.' ); ?></span>
<span class="export-personal-data-failed hidden"><?php _e( 'Email could not be sent.' ); ?> <button type="button" class="button export-personal-data-handle"><?php _e( 'Retry' ); ?></button></span>
<?php
Expand Down
Expand Up @@ -62,7 +62,7 @@ public function column_email( $item ) {
'">';

$remove_data_markup .= '<span class="remove-personal-data-idle"><button type="button" class="button-link remove-personal-data-handle">' . __( 'Force Erase Personal Data' ) . '</button></span>' .
'<span class="remove-personal-data-processing hidden">' . __( 'Erasing Data...' ) . '</span>' .
'<span class="remove-personal-data-processing hidden">' . __( 'Erasing Data...' ) . ' <span class="erasure-progress"></span></span>' .
'<span class="remove-personal-data-success hidden">' . __( 'Erasure completed.' ) . '</span>' .
'<span class="remove-personal-data-failed hidden">' . __( 'Force Erasure has failed.' ) . ' <button type="button" class="button-link remove-personal-data-handle">' . __( 'Retry' ) . '</button></span>';

Expand Down Expand Up @@ -106,7 +106,7 @@ public function column_next_steps( $item ) {

?>
<span class="remove-personal-data-idle"><button type="button" class="button remove-personal-data-handle"><?php _e( 'Erase Personal Data' ); ?></button></span>
<span class="remove-personal-data-processing button updating-message hidden"><?php _e( 'Erasing Data...' ); ?></span>
<span class="remove-personal-data-processing button updating-message hidden"><?php _e( 'Erasing Data...' ); ?> <span class="erasure-progress"></span></span>
<span class="remove-personal-data-success success-message hidden" ><?php _e( 'Erasure completed.' ); ?></span>
<span class="remove-personal-data-failed hidden"><?php _e( 'Data Erasure has failed.' ); ?> <button type="button" class="button remove-personal-data-handle"><?php _e( 'Retry' ); ?></button></span>
<?php
Expand Down
Expand Up @@ -156,8 +156,8 @@ public function test_email_address_should_be_filterable() {
*
* @since 4.9.8
*
* @param string $admin_email The email address of the notification recipient.
* @param WP_User_Request $request The request that is initiating the notification.
* @param string $admin_email The email address of the notification recipient.
* @param WP_User_Request $request The request that is initiating the notification.
* @return string Admin email address.
*/
public function modify_email_address( $admin_email, $request ) {
Expand Down

0 comments on commit a6a02ea

Please sign in to comment.