Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jan 11, 2024
1 parent 3ce5184 commit 0cf861c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 79 deletions.
9 changes: 8 additions & 1 deletion packages/dataviews/src/view-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,14 @@ function ViewTable( {
<tbody>
{ hasData &&
usedData.map( ( item, index ) => (
<tr key={ getItemId( item ) } className={ classnames({'is-selected': selection.includes( getItemId( item ) || index ) })}>
<tr
key={ getItemId( item ) }
className={ classnames( {
'is-selected': selection.includes(
getItemId( item ) || index
),
} ) }
>
{ hasBulkActions && (
<td
style={ {
Expand Down
161 changes: 83 additions & 78 deletions packages/edit-site/src/store/private-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,88 +62,93 @@ export const setEditorCanvasContainerView =
export const removeTemplates =
( templates ) =>
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' } );
}
};

0 comments on commit 0cf861c

Please sign in to comment.