From 0cf861c8c50336c9b5e6bba0186e1992c02e7fdc Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Thu, 11 Jan 2024 15:47:35 +0000 Subject: [PATCH] lint fixes --- packages/dataviews/src/view-table.js | 9 +- .../edit-site/src/store/private-actions.js | 161 +++++++++--------- 2 files changed, 91 insertions(+), 79 deletions(-) diff --git a/packages/dataviews/src/view-table.js b/packages/dataviews/src/view-table.js index 90bbf9872407f5..5775f5736ec62a 100644 --- a/packages/dataviews/src/view-table.js +++ b/packages/dataviews/src/view-table.js @@ -516,7 +516,14 @@ function ViewTable( { { hasData && usedData.map( ( item, index ) => ( - + { hasBulkActions && ( async ( { registry } ) => { - const promiseResult = await Promise.allSettled( - templates.map( ( template ) => { - return registry - .dispatch( coreStore ) - .deleteEntityRecord( - 'postType', - template.type, - template.id, - { force: true }, - { throwOnError: true } - ); - } ) - ); - - // If all the promises were fulfilled with sucess. - if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) { - let successMessage; - - if ( templates.length === 1 ) { - // Depending on how the entity was retrieved its title might be - // an object or simple string. - const templateTitle = - typeof templates[ 0 ].title === 'string' - ? templates[ 0 ].title - : templates[ 0 ].title?.rendered; - successMessage = sprintf( - /* translators: The template/part's name. */ - __( '"%s" deleted.' ), - decodeEntities( templateTitle ) + const promiseResult = await Promise.allSettled( + templates.map( ( template ) => { + return registry + .dispatch( coreStore ) + .deleteEntityRecord( + 'postType', + template.type, + template.id, + { force: true }, + { throwOnError: true } ); + } ) + ); + + // If all the promises were fulfilled with sucess. + if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) { + let successMessage; + + if ( templates.length === 1 ) { + // Depending on how the entity was retrieved its title might be + // an object or simple string. + const templateTitle = + typeof templates[ 0 ].title === 'string' + ? templates[ 0 ].title + : templates[ 0 ].title?.rendered; + successMessage = sprintf( + /* translators: The template/part's name. */ + __( '"%s" deleted.' ), + decodeEntities( templateTitle ) + ); + } else { + successMessage = __( 'Templates deleted.' ); + } + + registry + .dispatch( noticesStore ) + .createSuccessNotice( successMessage, { + type: 'snackbar', + id: 'site-editor-template-deleted-success', + } ); + } else { + // If there was at lease one failure. + let errorMessage; + // If we were trying to delete a single template. + if ( promiseResult.length === 1 ) { + if ( promiseResult[ 0 ].reason?.message ) { + errorMessage = promiseResult[ 0 ].reason.message; } else { - successMessage = __( 'Templates deleted.' ); + errorMessage = __( + 'An error occurred while deleting the template.' + ); } - - registry - .dispatch( noticesStore ) - .createSuccessNotice( successMessage, { - type: 'snackbar', - id: 'site-editor-template-deleted-success', - } ); + // If we were trying to delete a multiple templates } else { - // If there was at lease one failure. - let errorMessage; - // If we were trying to delete a single template. - if ( promiseResult.length === 1 ) { - if( promiseResult[0].reason?.message ) { - errorMessage = promiseResult[0].reason.message; - } else { - errorMessage = __( - 'An error occurred while deleting the template.' - ); + const errorMessages = new Set(); + const failedPromises = promiseResult.filter( + ( { status } ) => status === 'rejected' + ); + for ( const failedPromise of failedPromises ) { + if ( failedPromise.reason?.message ) { + errorMessages.add( failedPromise.reason.message ); } - // If we were trying to delete a multiple templates + } + if ( errorMessages.size === 0 ) { + errorMessage = __( + 'An error occurred while deleting the templates.' + ); + } else if ( errorMessages.size === 1 ) { + errorMessage = sprintf( + /* translators: %s: an error message */ + __( + 'An error occurred while deleting the templates: %s' + ), + [ ...errorMessages ][ 0 ] + ); } else { - const errorMessages = new Set(); - const failedPromises = promiseResult.filter( ( { status } ) => status === 'rejected' ); - console.error({failedPromises}); - for( const failedPromise of failedPromises ) { - if( failedPromise.reason?.message ) { - errorMessages.add( failedPromise.reason.message ) - } - } - if( errorMessages.size === 0 ) { - errorMessage = __( - 'An error occurred while deleting the templates.' - ); - } else if ( errorMessages.size === 1 ) { - errorMessage = sprintf( - /* translators: %s: an error message */ - __( 'An error occurred while deleting the templates: %s'), - [ ...errorMessages][0] - ) - } else { - errorMessage = sprintf( - /* translators: %s: a list of comma separated error messages */ - __( 'Some errors occurred while deleting the templates: %s'), - [ ...errorMessages].join( ',' ) - ) - } - } - registry - .dispatch( noticesStore ) - .createErrorNotice( errorMessage, { type: 'snackbar' } ); + errorMessage = sprintf( + /* translators: %s: a list of comma separated error messages */ + __( + 'Some errors occurred while deleting the templates: %s' + ), + [ ...errorMessages ].join( ',' ) + ); + } } - }; + registry + .dispatch( noticesStore ) + .createErrorNotice( errorMessage, { type: 'snackbar' } ); + } + };