-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Inline Commenting: Re-order the comments in sidebar in which blocks are listed #66927
Conversation
Size Change: +179 B (+0.01%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
@@ -96,7 +97,20 @@ function CollabSidebarContent( { showCommentBoard, setShowCommentBoard } ) { | |||
} | |||
} ); | |||
|
|||
return result; | |||
const blockCommentIds = getBlocks() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work for comments in posts with a template, such as Site Editor > Pages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated PR, it should be working fine now on post/page with template.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…nt/inline-commenting-comments-order
Flaky tests detected in 5574c5e. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11910868493
|
Based on the new design of #66377, we will need to show these comments at the height of the blocks. And for the secondary sidebar, we'll want to keep the chronological order. Maybe the sidebar with this new order needs to be a duplicated sidebar? |
That is being worked on; we can position comments at block height, but we also need to sync the editor scroll with the sidebar. There's where I got stuck. Will handle that in a separate PR.
Yes, you are correct. This PR is for a sidebar containing comments in the order that the blocks appear. Another sidebar will have comments displayed chronologically, Where i think we include Resolved comments too. |
I have synced PR with latest code and updated PR description, Could use your review here @ellatrix |
id: postId, | ||
} ); | ||
|
||
const getCommentIdsFromBlocks = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use named functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can't this function be moved out of the component? It doesn't seem to depend on other variables.
@@ -262,8 +265,37 @@ export default function CollabSidebar() { | |||
}; | |||
}, [] ); | |||
|
|||
const [ blocks ] = useEntityBlockEditor( 'postType', postType, { | |||
id: postId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there be a case where there is no current post ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does, Ill put condition there to avoid errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some finding, Undefined postId is already being handled under useEntityBlockEditor
for cases like templates and patterns.
return result; | ||
const blockCommentIds = getCommentIdsFromBlocks(); | ||
|
||
const uniqueIds = [ ...new Set( blockCommentIds.values() ) ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the values call really needed her? Set accepts the array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you need unique IDs, maybe getCommentIdsFromBlocks
can already check if it's been added before?
const uniqueIds = [ ...new Set( blockCommentIds.values() ) ]; | ||
|
||
const threadIdMap = new Map( | ||
result?.map( ( thread ) => [ thread.id, thread ] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's possible for result
to not be an array, we should probably just return early?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, would love to see the nits addressed. I'd also love if we could align the comments with the blocks, but let's do that in a follow-up.
// Process comments to build the tree structure | ||
const resultComments = useMemo( () => { | ||
const { resultComments, sortedThreads } = useMemo( () => { | ||
// Create a compare to store the references to all objects by id | ||
const compare = {}; | ||
const result = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this always an array? Why guard with result?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i'll update that.
); | ||
|
||
const sortedComments = blockCommentIds | ||
.map( ( id ) => threadIdMap.get( id ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, I see above that a thread can be { ...item, reply: [] }
, which will cause this component to constantly re-render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow, we are re-arranging comments here so reply comments will go under the parent comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed that this is within useMemo
instead of useSelect
…nt/inline-commenting-comments-order
…re listed (WordPress#66927) Co-authored-by: akasunil <sunil25393@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
…re listed (#66927) Co-authored-by: akasunil <sunil25393@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Part of - #66377
What? & Why?
In inline commenting functionality, Comments are loaded randomly in comments sidebar. Comments should be listed in order in which blocks are listed in editor. It helps navigate to the specific block comment.
How?
This PR re-order the comments in which blocks are appear in editor only in sidebar that present in canvas. History sidebar will have comments in chronological order. See attached video for more info.
Testing Instructions
Gutenberg
->Experiments
Screenshots or screencast
Edit-Post-.Hello-World-.-.-gutenberg-.-WordPress.5.webm