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 all 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
26 changes: 25 additions & 1 deletion packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ 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';
import { store as editorStore } from '../../store';

/**
* Renders the Comments component.
Expand Down Expand Up @@ -72,6 +75,26 @@ export function Comments( {
);
}, [] );

const { postId, postType } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPostType } = select( editorStore );
return {
postId: getCurrentPostId(),
postType: getCurrentPostType(),
};
}, [] );

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 +225,7 @@ export function Comments( {
) }
id={ thread.id }
spacing="3"
onClick={ () => handleThreadClick( thread ) }
>
<CommentBoard thread={ thread } />
{ 0 < thread?.reply?.length &&
Expand Down
21 changes: 21 additions & 0 deletions packages/editor/src/components/collab-sidebar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ export function getCommentIdsFromBlocks( blocks ) {
// Extract all comment IDs recursively
return extractCommentIds( blocks );
}

export const getBlockByCommentId = ( blocks, commentId ) => {
const extractClientId = ( blocksArray, commentID ) => {
for ( const block of blocksArray ) {
if ( block.attributes.blockCommentId === commentID ) {
return block;
}
if ( block.innerBlocks && block.innerBlocks.length > 0 ) {
const foundBlock = extractClientId(
block.innerBlocks,
commentID
);
if ( foundBlock ) {
return foundBlock;
}
}
}
};

return blocks ? extractClientId( blocks, commentId ) : null;
};
Loading