From 63f81c1e9cbb3b0513abca2b8cb579fef374ed7b Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Tue, 3 Dec 2024 19:25:14 +0530 Subject: [PATCH 1/5] Image size fix in lightbox --- lib/block-supports/layout.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index ddbd1917c30547..ca75f479dd67b5 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -1106,15 +1106,14 @@ function gutenberg_restore_image_outer_container( $block_content, $block ) { $wrapper_classnames = array( 'wp-block-image' ); - // If the block has a classNames attribute these classnames need to be removed from the content and added back + // If the block has a classNames attribute these classnames need to be added back // to the new wrapper div also. if ( ! empty( $block['attrs']['className'] ) ) { $wrapper_classnames = array_merge( $wrapper_classnames, explode( ' ', $block['attrs']['className'] ) ); } - $content_classnames = explode( ' ', $matches[2] ); - $filtered_content_classnames = array_diff( $content_classnames, $wrapper_classnames ); - return '
' . $matches[1] . implode( ' ', $filtered_content_classnames ) . $matches[3] . '
'; + // Wrap the existing content with the new wrapper div. + return '
' . $block_content . '
'; } if ( function_exists( 'wp_restore_image_outer_container' ) ) { From 0e19583c619fda88a7db00352e2813357281f3ef Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Tue, 3 Dec 2024 19:56:00 +0530 Subject: [PATCH 2/5] Revert "Image size fix in lightbox" This reverts commit 63f81c1e9cbb3b0513abca2b8cb579fef374ed7b. --- lib/block-supports/layout.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index ca75f479dd67b5..ddbd1917c30547 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -1106,14 +1106,15 @@ function gutenberg_restore_image_outer_container( $block_content, $block ) { $wrapper_classnames = array( 'wp-block-image' ); - // If the block has a classNames attribute these classnames need to be added back + // If the block has a classNames attribute these classnames need to be removed from the content and added back // to the new wrapper div also. if ( ! empty( $block['attrs']['className'] ) ) { $wrapper_classnames = array_merge( $wrapper_classnames, explode( ' ', $block['attrs']['className'] ) ); } + $content_classnames = explode( ' ', $matches[2] ); + $filtered_content_classnames = array_diff( $content_classnames, $wrapper_classnames ); - // Wrap the existing content with the new wrapper div. - return '
' . $block_content . '
'; + return '
' . $matches[1] . implode( ' ', $filtered_content_classnames ) . $matches[3] . '
'; } if ( function_exists( 'wp_restore_image_outer_container' ) ) { From 9dc20d15f7cb62274a2fa4cac77901737519f937 Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Wed, 11 Dec 2024 16:44:56 +0530 Subject: [PATCH 3/5] Add confirm box to site editor trash delete --- .../src/actions/permanently-delete-post.tsx | 244 ++++++++++++------ 1 file changed, 165 insertions(+), 79 deletions(-) diff --git a/packages/fields/src/actions/permanently-delete-post.tsx b/packages/fields/src/actions/permanently-delete-post.tsx index 688ba5b9918df8..8aadbaaa6b9de7 100644 --- a/packages/fields/src/actions/permanently-delete-post.tsx +++ b/packages/fields/src/actions/permanently-delete-post.tsx @@ -6,6 +6,8 @@ import { __, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import type { Action } from '@wordpress/dataviews'; import { trash } from '@wordpress/icons'; +import { Modal, Button, ButtonGroup } from '@wordpress/components'; +import { createRoot } from '@wordpress/element'; /** * Internal dependencies @@ -13,6 +15,53 @@ import { trash } from '@wordpress/icons'; import { getItemTitle, isTemplateOrTemplatePart } from './utils'; import type { CoreDataError, PostWithPermissions } from '../types'; +interface ConfirmModalProps { + posts: PostWithPermissions[]; + onConfirm: () => void; + onCancel: () => void; +} + +const ConfirmModal = ( { posts, onConfirm, onCancel }: ConfirmModalProps ) => ( + +

+ { posts.length === 1 + ? sprintf( + /* translators: The post's title. */ + __( + 'Are you sure you want to permanently delete "%s"?' + ), + getItemTitle( posts[ 0 ] ) + ) + : __( + 'Are you sure you want to permanently delete these items?' + ) } +

+ + + + + +
+); + const permanentlyDeletePost: Action< PostWithPermissions > = { id: 'permanently-delete', label: __( 'Permanently delete' ), @@ -29,89 +78,126 @@ const permanentlyDeletePost: Action< PostWithPermissions > = { const { createSuccessNotice, createErrorNotice } = registry.dispatch( noticesStore ); const { deleteEntityRecord } = registry.dispatch( coreStore ); - const promiseResult = await Promise.allSettled( - posts.map( ( post ) => { - return deleteEntityRecord( - 'postType', - post.type, - post.id, - { force: true }, - { throwOnError: true } - ); - } ) - ); - // If all the promises were fulfilled with success. - if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) { - let successMessage; - if ( promiseResult.length === 1 ) { - successMessage = sprintf( - /* translators: The posts's title. */ - __( '"%s" permanently deleted.' ), - getItemTitle( posts[ 0 ] ) - ); - } else { - successMessage = __( 'The items were permanently deleted.' ); - } - createSuccessNotice( successMessage, { - type: 'snackbar', - id: 'permanently-delete-post-action', - } ); - onActionPerformed?.( posts ); - } else { - // If there was at lease one failure. - let errorMessage; - // If we were trying to permanently delete a single post. - if ( promiseResult.length === 1 ) { - const typedError = promiseResult[ 0 ] as { - reason?: CoreDataError; - }; - if ( typedError.reason?.message ) { - errorMessage = typedError.reason.message; - } else { - errorMessage = __( - 'An error occurred while permanently deleting the item.' - ); - } - // If we were trying to permanently delete multiple posts - } else { - const errorMessages = new Set(); - const failedPromises = promiseResult.filter( - ( { status } ) => status === 'rejected' + + // Wrap logic in a Promise resolved by modal interaction + return new Promise< void >( ( resolve ) => { + // Setup modal container + const container = document.createElement( 'div' ); + document.body.appendChild( container ); + const root = createRoot( container ); + const cleanup = () => { + root.unmount(); + document.body.removeChild( container ); + }; + + const handleConfirm = async () => { + cleanup(); + const promiseResult = await Promise.allSettled( + posts.map( ( post ) => + deleteEntityRecord( + 'postType', + post.type, + post.id, + { force: true }, + { throwOnError: true } + ) + ) ); - for ( const failedPromise of failedPromises ) { - const typedError = failedPromise as { - reason?: CoreDataError; - }; - if ( typedError.reason?.message ) { - errorMessages.add( typedError.reason.message ); + + // If all the promises were fulfilled with success. + if ( + promiseResult.every( + ( { status } ) => status === 'fulfilled' + ) + ) { + let successMessage; + if ( promiseResult.length === 1 ) { + successMessage = sprintf( + /* translators: The posts's title. */ + __( '"%s" permanently deleted.' ), + getItemTitle( posts[ 0 ] ) + ); + } else { + successMessage = __( + 'The items were permanently deleted.' + ); } - } - if ( errorMessages.size === 0 ) { - errorMessage = __( - 'An error occurred while permanently deleting the items.' - ); - } else if ( errorMessages.size === 1 ) { - errorMessage = sprintf( - /* translators: %s: an error message */ - __( - 'An error occurred while permanently deleting the items: %s' - ), - [ ...errorMessages ][ 0 ] - ); + createSuccessNotice( successMessage, { + type: 'snackbar', + id: 'permanently-delete-post-action', + } ); + onActionPerformed?.( posts ); } else { - errorMessage = sprintf( - /* translators: %s: a list of comma separated error messages */ - __( - 'Some errors occurred while permanently deleting the items: %s' - ), - [ ...errorMessages ].join( ',' ) - ); + // If there was at lease one failure. + let errorMessage; + // If we were trying to permanently delete a single post. + if ( promiseResult.length === 1 ) { + const typedError = promiseResult[ 0 ] as { + reason?: CoreDataError; + }; + if ( typedError.reason?.message ) { + errorMessage = typedError.reason.message; + } else { + errorMessage = __( + 'An error occurred while permanently deleting the item.' + ); + } + // If we were trying to permanently delete multiple posts + } else { + const errorMessages = new Set(); + const failedPromises = promiseResult.filter( + ( { status } ) => status === 'rejected' + ); + for ( const failedPromise of failedPromises ) { + const typedError = failedPromise as { + reason?: CoreDataError; + }; + if ( typedError.reason?.message ) { + errorMessages.add( typedError.reason.message ); + } + } + if ( errorMessages.size === 0 ) { + errorMessage = __( + 'An error occurred while permanently deleting the items.' + ); + } else if ( errorMessages.size === 1 ) { + errorMessage = sprintf( + /* translators: %s: an error message */ + __( + 'An error occurred while permanently deleting the items: %s' + ), + [ ...errorMessages ][ 0 ] + ); + } else { + errorMessage = sprintf( + /* translators: %s: a list of comma separated error messages */ + __( + 'Some errors occurred while permanently deleting the items: %s' + ), + [ ...errorMessages ].join( ',' ) + ); + } + } + createErrorNotice( errorMessage, { + type: 'snackbar', + } ); } - } - createErrorNotice( errorMessage, { - type: 'snackbar', - } ); - } + }; + + const handleCancel = () => { + cleanup(); + resolve(); + }; + + // Render the modal + root.render( + + ); + } ); }, }; From 6a928ea697478372b3f3d012d770707765967099 Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Thu, 12 Dec 2024 12:13:43 +0530 Subject: [PATCH 4/5] Feedback updates --- .../src/actions/permanently-delete-post.tsx | 319 +++++++++--------- 1 file changed, 151 insertions(+), 168 deletions(-) diff --git a/packages/fields/src/actions/permanently-delete-post.tsx b/packages/fields/src/actions/permanently-delete-post.tsx index 8aadbaaa6b9de7..cdd22efc06fbef 100644 --- a/packages/fields/src/actions/permanently-delete-post.tsx +++ b/packages/fields/src/actions/permanently-delete-post.tsx @@ -2,12 +2,19 @@ * WordPress dependencies */ import { store as coreStore } from '@wordpress/core-data'; -import { __, sprintf } from '@wordpress/i18n'; +import { __, _n, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; import type { Action } from '@wordpress/dataviews'; import { trash } from '@wordpress/icons'; -import { Modal, Button, ButtonGroup } from '@wordpress/components'; -import { createRoot } from '@wordpress/element'; +import { useState } from '@wordpress/element'; +import { useDispatch } from '@wordpress/data'; +import { + Button, + __experimentalText as Text, + __experimentalHStack as HStack, + __experimentalVStack as VStack, +} from '@wordpress/components'; +import { decodeEntities } from '@wordpress/html-entities'; /** * Internal dependencies @@ -15,53 +22,6 @@ import { createRoot } from '@wordpress/element'; import { getItemTitle, isTemplateOrTemplatePart } from './utils'; import type { CoreDataError, PostWithPermissions } from '../types'; -interface ConfirmModalProps { - posts: PostWithPermissions[]; - onConfirm: () => void; - onCancel: () => void; -} - -const ConfirmModal = ( { posts, onConfirm, onCancel }: ConfirmModalProps ) => ( - -

- { posts.length === 1 - ? sprintf( - /* translators: The post's title. */ - __( - 'Are you sure you want to permanently delete "%s"?' - ), - getItemTitle( posts[ 0 ] ) - ) - : __( - 'Are you sure you want to permanently delete these items?' - ) } -

- - - - - -
-); - const permanentlyDeletePost: Action< PostWithPermissions > = { id: 'permanently-delete', label: __( 'Permanently delete' ), @@ -74,130 +34,153 @@ const permanentlyDeletePost: Action< PostWithPermissions > = { const { status, permissions } = item; return status === 'trash' && permissions?.delete; }, - async callback( posts, { registry, onActionPerformed } ) { + hideModalHeader: true, + RenderModal: ( { items, closeModal, onActionPerformed } ) => { + const [ isBusy, setIsBusy ] = useState( false ); const { createSuccessNotice, createErrorNotice } = - registry.dispatch( noticesStore ); - const { deleteEntityRecord } = registry.dispatch( coreStore ); + useDispatch( noticesStore ); + const { deleteEntityRecord } = useDispatch( coreStore ); - // Wrap logic in a Promise resolved by modal interaction - return new Promise< void >( ( resolve ) => { - // Setup modal container - const container = document.createElement( 'div' ); - document.body.appendChild( container ); - const root = createRoot( container ); - const cleanup = () => { - root.unmount(); - document.body.removeChild( container ); - }; - - const handleConfirm = async () => { - cleanup(); - const promiseResult = await Promise.allSettled( - posts.map( ( post ) => - deleteEntityRecord( - 'postType', - post.type, - post.id, - { force: true }, - { throwOnError: true } - ) - ) - ); - - // If all the promises were fulfilled with success. - if ( - promiseResult.every( - ( { status } ) => status === 'fulfilled' - ) - ) { - let successMessage; - if ( promiseResult.length === 1 ) { - successMessage = sprintf( - /* translators: The posts's title. */ - __( '"%s" permanently deleted.' ), - getItemTitle( posts[ 0 ] ) - ); - } else { - successMessage = __( - 'The items were permanently deleted.' - ); - } - createSuccessNotice( successMessage, { - type: 'snackbar', - id: 'permanently-delete-post-action', - } ); - onActionPerformed?.( posts ); - } else { - // If there was at lease one failure. - let errorMessage; - // If we were trying to permanently delete a single post. - if ( promiseResult.length === 1 ) { - const typedError = promiseResult[ 0 ] as { - reason?: CoreDataError; - }; - if ( typedError.reason?.message ) { - errorMessage = typedError.reason.message; - } else { - errorMessage = __( - 'An error occurred while permanently deleting the item.' - ); - } - // If we were trying to permanently delete multiple posts - } else { - const errorMessages = new Set(); - const failedPromises = promiseResult.filter( - ( { status } ) => status === 'rejected' - ); - for ( const failedPromise of failedPromises ) { - const typedError = failedPromise as { - reason?: CoreDataError; - }; - if ( typedError.reason?.message ) { - errorMessages.add( typedError.reason.message ); - } - } - if ( errorMessages.size === 0 ) { - errorMessage = __( - 'An error occurred while permanently deleting the items.' - ); - } else if ( errorMessages.size === 1 ) { - errorMessage = sprintf( - /* translators: %s: an error message */ - __( - 'An error occurred while permanently deleting the items: %s' + return ( + + + { items.length > 1 + ? sprintf( + // translators: %d: number of items to delete. + _n( + 'Permanently delete %d item?', + 'Permanently delete %d items?', + items.length ), - [ ...errorMessages ][ 0 ] + items.length + ) + : sprintf( + // translators: %s: The post's title + __( 'Permanently delete "%s"?' ), + decodeEntities( getItemTitle( items[ 0 ] ) ) + ) } + + + + + + + ); }, }; From 0c595382a5c88b8413867a7cba0f1f4c83e917e8 Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Fri, 20 Dec 2024 14:47:17 +0530 Subject: [PATCH 5/5] Feedback changes --- packages/fields/src/actions/permanently-delete-post.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/fields/src/actions/permanently-delete-post.tsx b/packages/fields/src/actions/permanently-delete-post.tsx index cdd22efc06fbef..136fcdda9a3e68 100644 --- a/packages/fields/src/actions/permanently-delete-post.tsx +++ b/packages/fields/src/actions/permanently-delete-post.tsx @@ -48,15 +48,17 @@ const permanentlyDeletePost: Action< PostWithPermissions > = { ? sprintf( // translators: %d: number of items to delete. _n( - 'Permanently delete %d item?', - 'Permanently delete %d items?', + 'Are you sure you want to permanently delete %d item?', + 'Are you sure you want to permanently delete %d items?', items.length ), items.length ) : sprintf( // translators: %s: The post's title - __( 'Permanently delete "%s"?' ), + __( + 'Are you sure you want to permanently delete "%s"?' + ), decodeEntities( getItemTitle( items[ 0 ] ) ) ) }