Skip to content

Commit 9ad1717

Browse files
Mamadukaadamsilversteint-hamanoyouknowriadjasmussen
authored
Notes: Hide pinned sidebar when there are no notes (#72872)
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: jeryj <jeryj@git.wordpress.org> Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org> Co-authored-by: desrosj <desrosj@git.wordpress.org>
1 parent 1cd180a commit 9ad1717

File tree

5 files changed

+50
-41
lines changed

5 files changed

+50
-41
lines changed

packages/editor/src/components/collab-sidebar/comments.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,9 @@ export function Comments( {
308308
] );
309309

310310
const hasThreads = Array.isArray( threads ) && threads.length > 0;
311+
// This should no longer happen since https://github.com/WordPress/gutenberg/pull/72872.
311312
if ( ! hasThreads && ! isFloating ) {
312-
return (
313-
<>
314-
<AddComment
315-
onSubmit={ onAddReply }
316-
showCommentBoard={ showCommentBoard }
317-
setShowCommentBoard={ setShowCommentBoard }
318-
commentSidebarRef={ commentSidebarRef }
319-
/>
320-
<Text as="p">{ __( 'No notes available.' ) }</Text>
321-
<Text as="p" variant="muted">
322-
{ __( 'Only logged in users can see Notes.' ) }
323-
</Text>
324-
</>
325-
);
313+
return null;
326314
}
327315

328316
return (

packages/editor/src/components/collab-sidebar/index.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ function NotesSidebar( { postId, mode } ) {
128128
const currentThread = blockCommentId
129129
? resultComments.find( ( thread ) => thread.id === blockCommentId )
130130
: null;
131+
const showAllNotesSidebar =
132+
resultComments.length > 0 || ! showFloatingSidebar;
131133

132134
async function openTheSidebar() {
133135
const prevArea = await getActiveComplementaryArea( 'core' );
@@ -173,27 +175,29 @@ function NotesSidebar( { postId, mode } ) {
173175
/>
174176
) }
175177
<AddCommentMenuItem onClick={ openTheSidebar } />
176-
<PluginSidebar
177-
identifier={ collabHistorySidebarName }
178-
name={ collabHistorySidebarName }
179-
title={ __( 'All notes' ) }
180-
header={
181-
<h2 className="interface-complementary-area-header__title">
182-
{ __( 'All notes' ) }
183-
</h2>
184-
}
185-
icon={ commentIcon }
186-
closeLabel={ __( 'Close Notes' ) }
187-
>
188-
<NotesSidebarContent
189-
comments={ resultComments }
190-
showCommentBoard={ showCommentBoard }
191-
setShowCommentBoard={ setShowCommentBoard }
192-
commentSidebarRef={ commentSidebarRef }
193-
reflowComments={ reflowComments }
194-
commentLastUpdated={ commentLastUpdated }
195-
/>
196-
</PluginSidebar>
178+
{ showAllNotesSidebar && (
179+
<PluginSidebar
180+
identifier={ collabHistorySidebarName }
181+
name={ collabHistorySidebarName }
182+
title={ __( 'All notes' ) }
183+
header={
184+
<h2 className="interface-complementary-area-header__title">
185+
{ __( 'All notes' ) }
186+
</h2>
187+
}
188+
icon={ commentIcon }
189+
closeLabel={ __( 'Close Notes' ) }
190+
>
191+
<NotesSidebarContent
192+
comments={ resultComments }
193+
showCommentBoard={ showCommentBoard }
194+
setShowCommentBoard={ setShowCommentBoard }
195+
commentSidebarRef={ commentSidebarRef }
196+
reflowComments={ reflowComments }
197+
commentLastUpdated={ commentLastUpdated }
198+
/>
199+
</PluginSidebar>
200+
) }
197201
{ isLargeViewport && (
198202
<PluginSidebar
199203
isPinnable={ false }

packages/editor/src/components/collab-sidebar/utils.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ export function getCommentExcerpt( text, excerptLength = 10 ) {
9999
* @typedef {import('@wordpress/element').RefObject} RefObject
100100
*
101101
* @param {string} commentId The ID of the comment thread to focus.
102-
* @param {?HTMLElement} container The container element to search within.
102+
* @param {?HTMLElement} threadContainer The container element to search within.
103103
* @param {string} additionalSelector The additional selector to focus on.
104104
*/
105-
export function focusCommentThread( commentId, container, additionalSelector ) {
106-
if ( ! container ) {
105+
export function focusCommentThread(
106+
commentId,
107+
threadContainer,
108+
additionalSelector
109+
) {
110+
if ( ! threadContainer ) {
107111
return;
108112
}
109113

@@ -116,6 +120,11 @@ export function focusCommentThread( commentId, container, additionalSelector ) {
116120
: threadSelector;
117121

118122
return new Promise( ( resolve ) => {
123+
// Watch the sidebar skeleton in case the sidebar disappears and re-appears.
124+
const container = threadContainer.closest(
125+
'.interface-interface-skeleton__sidebar'
126+
);
127+
119128
if ( container.querySelector( selector ) ) {
120129
return resolve( container.querySelector( selector ) );
121130
}
@@ -129,6 +138,7 @@ export function focusCommentThread( commentId, container, additionalSelector ) {
129138
resolve( container.querySelector( selector ) );
130139
}
131140
} );
141+
132142
observer.observe( container, {
133143
childList: true,
134144
subtree: true,

packages/editor/src/components/editor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ function Editor( {
109109
{ extraContent }
110110
</EditorInterface>
111111
{ children }
112-
<NotesSidebar />
113112
<Sidebar
114113
onActionPerformed={ onActionPerformed }
115114
extraPanels={ extraSidebarPanels }
116115
/>
116+
<NotesSidebar />
117117
{ isBlockTheme && <GlobalStylesRenderer /> }
118118
{ showGlobalStyles && <GlobalStylesSidebar /> }
119119
</ExperimentalEditorProvider>

test/e2e/specs/editor/various/block-comments.spec.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ test.use( {
1010
} );
1111

1212
test.describe( 'Block Comments', () => {
13-
test.beforeEach( async ( { admin, blockCommentUtils } ) => {
13+
test.beforeEach( async ( { admin } ) => {
1414
await admin.createNewPost();
15-
await blockCommentUtils.openBlockCommentSidebar();
1615
} );
1716

1817
test.afterAll( async ( { requestUtils } ) => {
@@ -22,7 +21,13 @@ test.describe( 'Block Comments', () => {
2221
test( 'should move focus to add a new note form', async ( {
2322
editor,
2423
page,
24+
blockCommentUtils,
2525
} ) => {
26+
await blockCommentUtils.addBlockWithComment( {
27+
type: 'core/paragraph',
28+
attributes: { content: 'Howdy!' },
29+
comment: 'Test comment',
30+
} );
2631
await editor.insertBlock( {
2732
name: 'core/paragraph',
2833
attributes: { content: 'Testing block comments' },
@@ -157,6 +162,7 @@ test.describe( 'Block Comments', () => {
157162
attributes: { content: 'Testing block comments' },
158163
comment: 'Test comment to resolve.',
159164
} );
165+
await blockCommentUtils.openBlockCommentSidebar();
160166

161167
const thread = page
162168
.getByRole( 'region', { name: 'Editor settings' } )
@@ -206,6 +212,7 @@ test.describe( 'Block Comments', () => {
206212
.filter( { hasText: 'Note marked as resolved.' } )
207213
).toBeVisible();
208214

215+
await blockCommentUtils.openBlockCommentSidebar();
209216
await page.locator( '.editor-collab-sidebar-panel__thread' ).click();
210217
await expect( resolveButton ).toBeDisabled();
211218
const commentForm = page.getByRole( 'textbox', { name: 'Reply to' } );

0 commit comments

Comments
 (0)