Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting on a comment should scroll to the block #66873

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
912ec5a
Scroll editor blocks based on comments
karthick-murugan Nov 8, 2024
154c273
Update blockClientId
karthick-murugan Nov 8, 2024
52341d1
Update Iframe
karthick-murugan Nov 11, 2024
aef8840
Feedback Changes
karthick-murugan Nov 26, 2024
0c34d4e
Merge branch 'trunk' into feature/block-comments-scroll
karthick-murugan Nov 27, 2024
dad8215
Site Editor: Unify layout with posts dataviews (#67162)
youknowriad Nov 27, 2024
cd730bb
Scroll editor blocks based on comments
karthick-murugan Nov 8, 2024
583632d
Feedback Changes
karthick-murugan Nov 26, 2024
499cfd8
Feedback Changes
karthick-murugan Nov 27, 2024
d71c1c6
Remove unnecessary changes
karthick-murugan Nov 28, 2024
07c85f6
Feedback Changes
karthick-murugan Nov 28, 2024
a7693d4
Merge branch 'trunk' of github.com:karthick-murugan/gutenberg into fe…
karthick-murugan Nov 28, 2024
8367a44
Linting issues fixed
karthick-murugan Nov 28, 2024
9d60b44
Feedback Changes updated
karthick-murugan Dec 4, 2024
e5d379b
Feedback updates
karthick-murugan Dec 5, 2024
939f2f5
Feedback updates
karthick-murugan Dec 5, 2024
68568d9
Feedback updates
karthick-murugan Dec 5, 2024
13194c1
Feedback and site editor updates
karthick-murugan Dec 5, 2024
e9b0e4b
Updating feedback changes
karthick-murugan Dec 5, 2024
cc4c27a
Merge branch 'trunk' into feature/block-comments-scroll
karthick-murugan Dec 5, 2024
de2c602
Reverting comment header
karthick-murugan Dec 5, 2024
07453a5
Merge branch 'feature/block-comments-scroll' of github.com:karthick-m…
karthick-murugan Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import {
} from '@wordpress/components';
import { Icon, check, published, moreVertical } from '@wordpress/icons';
import { __, _x } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { useEntityBlockEditor } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import CommentAuthorInfo from './comment-author-info';
import CommentForm from './comment-form';
import { getBlockByCommentId } from './utils';

/**
* Renders the Comments component.
Expand All @@ -35,6 +37,8 @@ import CommentForm from './comment-form';
* @param {Function} props.onAddReply - The function to add a reply to a comment.
* @param {Function} props.onCommentDelete - The function to delete a comment.
* @param {Function} props.onCommentResolve - The function to mark a comment as resolved.
* @param {string} props.postType - The post type.
* @param {number} props.postId - The post ID.
* @return {React.ReactNode} The rendered Comments component.
*/
export function Comments( {
Expand All @@ -43,6 +47,8 @@ export function Comments( {
onAddReply,
onCommentDelete,
onCommentResolve,
postType, // Ensure postType is passed as a prop
postId, // Ensure postId is passed as a prop
} ) {
const [ actionState, setActionState ] = useState( false );
const [ isConfirmDialogOpen, setIsConfirmDialogOpen ] = useState( false );
Expand Down Expand Up @@ -72,6 +78,18 @@ export function Comments( {
);
}, [] );

const [ blocks ] = useEntityBlockEditor( 'postType', postType, {
id: postId,
} );
Comment on lines +86 to +88
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for switching to useEntityBlockEditor? This reverts the suggestion from #66873 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mamaduka - used useEntityBlockEditor for the functionality to work in Site Editor. Before it was not.


const { selectBlock } = useDispatch( blockEditorStore );
const handleThreadClick = ( thread ) => {
const block = getBlockByCommentId( blocks, thread.id );
if ( block ) {
selectBlock( block.clientId ); // Use the action to select the block
}
};

const CommentBoard = ( { thread, parentThread } ) => {
return (
<>
Expand Down Expand Up @@ -202,6 +220,7 @@ export function Comments( {
) }
id={ thread.id }
spacing="3"
onClick={ () => handleThreadClick( thread ) }
>
<CommentBoard thread={ thread } />
{ 0 < thread?.reply?.length &&
Expand Down Expand Up @@ -270,7 +289,7 @@ export function Comments( {
* @param {Function} props.onDelete - The function to delete the comment.
* @param {Function} props.onReply - The function to reply to the comment.
* @param {string} props.status - The status of the comment.
* @return {React.ReactNode} The rendered comment header.
* @return {JSX.Element} The rendered comment header.
*/
function CommentHeader( {
thread,
Expand Down
7 changes: 7 additions & 0 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ function CollabSidebarContent( { showCommentBoard, setShowCommentBoard } ) {
);
};

const postType = useSelect(
( select ) => select( editorStore ).getCurrentPostType(),
[]
);

return (
<div className="editor-collab-sidebar-panel">
<AddComment
Expand All @@ -234,6 +239,8 @@ function CollabSidebarContent( { showCommentBoard, setShowCommentBoard } ) {
onAddReply={ addNewComment }
onCommentDelete={ onCommentDelete }
onCommentResolve={ onCommentResolve }
postId={ postId }
postType={ postType }
/>
</div>
);
Expand Down
18 changes: 18 additions & 0 deletions packages/editor/src/components/collab-sidebar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,21 @@
export function sanitizeCommentString( str ) {
return str.trim();
}

export const getBlockByCommentId = ( blocks, commentId ) => {
for ( const block of blocks ) {
if ( block.attributes.blockCommentId === commentId ) {
return block;
}
if ( block.innerBlocks && block.innerBlocks.length > 0 ) {
const foundBlock = getBlockByCommentId(
block.innerBlocks,
commentId
);
if ( foundBlock ) {
return foundBlock;
}
}
}
return blocks ? getBlockByCommentId( blocks, commentId ) : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this fallback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mamaduka - I have updated the condition now.

};
Loading