-
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
Changes from 7 commits
1d42175
67441de
5574c5e
5a43c16
eb4e907
e47abac
b5c41f7
7da59a0
809ebc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import { useState, useMemo } from '@wordpress/element'; | |
import { comment as commentIcon } from '@wordpress/icons'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { store as noticesStore } from '@wordpress/notices'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { store as interfaceStore } from '@wordpress/interface'; | ||
|
||
|
@@ -27,6 +27,7 @@ import { store as editorStore } from '../../store'; | |
import AddCommentButton from './comment-button'; | ||
import AddCommentToolbarButton from './comment-button-toolbar'; | ||
import { useGlobalStylesContext } from '../global-styles-provider'; | ||
import { getCommentIdsFromBlocks } from './utils'; | ||
|
||
const isBlockCommentExperimentEnabled = | ||
window?.__experimentalEnableBlockComment; | ||
|
@@ -220,8 +221,11 @@ export default function CollabSidebar() { | |
const { enableComplementaryArea } = useDispatch( interfaceStore ); | ||
const { getActiveComplementaryArea } = useSelect( interfaceStore ); | ||
|
||
const { postStatus } = useSelect( ( select ) => { | ||
const { postId, postType, postStatus } = useSelect( ( select ) => { | ||
const { getCurrentPostId, getCurrentPostType } = select( editorStore ); | ||
return { | ||
postId: getCurrentPostId(), | ||
postType: getCurrentPostType(), | ||
postStatus: | ||
select( editorStore ).getEditedPostAttribute( 'status' ), | ||
}; | ||
|
@@ -262,8 +266,12 @@ export default function CollabSidebar() { | |
}; | ||
}, [] ); | ||
|
||
const [ blocks ] = useEntityBlockEditor( 'postType', postType, { | ||
id: postId, | ||
} ); | ||
|
||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this always an array? Why guard with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, i'll update that. |
||
|
@@ -288,8 +296,22 @@ export default function CollabSidebar() { | |
} | ||
} ); | ||
|
||
return result; | ||
}, [ threads ] ); | ||
if ( 0 === result?.length ) { | ||
return { resultComments: [], sortedThreads: [] }; | ||
} | ||
|
||
const blockCommentIds = getCommentIdsFromBlocks( blocks ); | ||
|
||
const threadIdMap = new Map( | ||
result?.map( ( thread ) => [ thread.id, thread ] ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's possible for |
||
); | ||
|
||
const sortedComments = blockCommentIds | ||
.map( ( id ) => threadIdMap.get( id ) ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, I see above that a thread can be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed that this is within |
||
.filter( ( thread ) => thread !== undefined ); | ||
|
||
return { resultComments: result, sortedThreads: sortedComments }; | ||
}, [ threads, blocks ] ); | ||
|
||
// Get the global styles to set the background color of the sidebar. | ||
const { merged: GlobalStyles } = useGlobalStylesContext(); | ||
|
@@ -338,7 +360,7 @@ export default function CollabSidebar() { | |
headerClassName="editor-collab-sidebar__header" | ||
> | ||
<CollabSidebarContent | ||
comments={ resultComments } | ||
comments={ sortedThreads } | ||
showCommentBoard={ showCommentBoard } | ||
setShowCommentBoard={ setShowCommentBoard } | ||
styles={ { | ||
|
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.