From 0d36a58c6742ec6345b635fb02219b615456cf27 Mon Sep 17 00:00:00 2001 From: rishishah-multidots Date: Tue, 15 Oct 2024 19:00:59 +0530 Subject: [PATCH 1/2] feedback changes --- lib/compat/wordpress-6.7/rest-api.php | 2 +- lib/compat/wordpress-6.8/rest-api.php | 51 +++++++++++++++++++ lib/load.php | 3 ++ .../block-settings-dropdown.js | 6 +-- ...onToolbar.js => comment-button-toolbar.js} | 0 .../{commentButton.js => comment-button.js} | 0 .../src/components/collab-sidebar/index.js | 29 ++++++----- 7 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 lib/compat/wordpress-6.8/rest-api.php rename packages/editor/src/components/collab-sidebar/{commentButtonToolbar.js => comment-button-toolbar.js} (100%) rename packages/editor/src/components/collab-sidebar/{commentButton.js => comment-button.js} (100%) diff --git a/lib/compat/wordpress-6.7/rest-api.php b/lib/compat/wordpress-6.7/rest-api.php index aa0ab92278b4b0..701c8569428b18 100644 --- a/lib/compat/wordpress-6.7/rest-api.php +++ b/lib/compat/wordpress-6.7/rest-api.php @@ -152,7 +152,7 @@ function update_get_avatar_comment_type( $comment_type ) { $comment_type[] = 'block_comment'; return $comment_type; } - add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type', 10, 1 ); + add_filter( 'get_avatar_comment_types', 'update_get_avatar_comment_type' ); } /** diff --git a/lib/compat/wordpress-6.8/rest-api.php b/lib/compat/wordpress-6.8/rest-api.php new file mode 100644 index 00000000000000..c9e146c869d83d --- /dev/null +++ b/lib/compat/wordpress-6.8/rest-api.php @@ -0,0 +1,51 @@ + ) } + <__unstableCommentIconFill.Slot + fillProps={ { onClose } } + /> - <__unstableCommentIconFill.Slot - fillProps={ { onClose } } - /> { canCopyStyles && ! isContentOnly && ( { - if ( name?.includes( 'core/' ) && ! settings.attributes.blockCommentId ) { + if ( ! settings.attributes.blockCommentId ) { settings.attributes = { ...settings.attributes, blockCommentId: { @@ -66,13 +66,13 @@ export default function CollabSidebar() { const clientId = useSelect( ( select ) => { const { getSelectedBlockClientId } = select( blockEditorStore ); - setBlockCommentID( - select( blockEditorStore ).getBlock( getSelectedBlockClientId() ) - ?.attributes.blockCommentId - ); return getSelectedBlockClientId(); }, [] ); + const blockDetails = useSelect( ( select ) => { + return clientId ? select( blockEditorStore ).getBlock( clientId ) : null; + }, [clientId] ); + // Get the dispatch functions to save the comment and update the block attributes. const { updateBlockAttributes } = useDispatch( blockEditorStore ); @@ -90,11 +90,13 @@ export default function CollabSidebar() { comment_approved: 0, }; - if ( parentCommentId ) { - args.parent = parentCommentId; - } + // Create a new object, conditionally including the parent property + const updatedArgs = { + ...args, + ...(parentCommentId ? { parent: parentCommentId } : {}), + }; - const savedRecord = await saveEntityRecord( 'root', 'comment', args ); + const savedRecord = await saveEntityRecord( 'root', 'comment', updatedArgs ); if ( savedRecord ) { // If it's a main comment, update the block attributes with the comment id. @@ -212,8 +214,11 @@ export default function CollabSidebar() { }, [ postId, getEntityRecords ] ); useEffect( () => { + if ( blockDetails ) { + setBlockCommentID( blockDetails?.attributes.blockCommentId ); + } fetchComments(); - }, [ postId, fetchComments ] ); + }, [ postId, fetchComments, clientId ] ); const allBlocks = useSelect( ( select ) => { return select( blockEditorStore ).getBlocks(); From 9a6556f00e6601f795b6216e45267bb995966ff1 Mon Sep 17 00:00:00 2001 From: rishishah-multidots Date: Tue, 15 Oct 2024 19:16:39 +0530 Subject: [PATCH 2/2] linting error fixes --- .../src/components/collab-sidebar/comments.js | 10 ++-------- .../src/components/collab-sidebar/index.js | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/editor/src/components/collab-sidebar/comments.js b/packages/editor/src/components/collab-sidebar/comments.js index e2c07c9968d840..836340af393105 100644 --- a/packages/editor/src/components/collab-sidebar/comments.js +++ b/packages/editor/src/components/collab-sidebar/comments.js @@ -269,10 +269,7 @@ function CommentForm( { onSubmit, onCancel, thread } ) { ? _x( 'Update', 'verb' ) : _x( 'Reply', 'Add reply comment' ) } - @@ -312,10 +309,7 @@ function ConfirmNotice( { confirmMessage, confirmAction, discardAction } ) { > { __( 'Yes' ) } - diff --git a/packages/editor/src/components/collab-sidebar/index.js b/packages/editor/src/components/collab-sidebar/index.js index dc3f62d1c03b6f..e71f896aa18cef 100644 --- a/packages/editor/src/components/collab-sidebar/index.js +++ b/packages/editor/src/components/collab-sidebar/index.js @@ -69,9 +69,14 @@ export default function CollabSidebar() { return getSelectedBlockClientId(); }, [] ); - const blockDetails = useSelect( ( select ) => { - return clientId ? select( blockEditorStore ).getBlock( clientId ) : null; - }, [clientId] ); + const blockDetails = useSelect( + ( select ) => { + return clientId + ? select( blockEditorStore ).getBlock( clientId ) + : null; + }, + [ clientId ] + ); // Get the dispatch functions to save the comment and update the block attributes. const { updateBlockAttributes } = useDispatch( blockEditorStore ); @@ -93,10 +98,14 @@ export default function CollabSidebar() { // Create a new object, conditionally including the parent property const updatedArgs = { ...args, - ...(parentCommentId ? { parent: parentCommentId } : {}), + ...( parentCommentId ? { parent: parentCommentId } : {} ), }; - const savedRecord = await saveEntityRecord( 'root', 'comment', updatedArgs ); + const savedRecord = await saveEntityRecord( + 'root', + 'comment', + updatedArgs + ); if ( savedRecord ) { // If it's a main comment, update the block attributes with the comment id.