Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `PostAuthor`: The field renders with the `SearchableSelect` component of `@wordpress/ui` instead of `ComboboxControl` and `SelectControl` ([#83323](https://github.com/WordPress/gutenberg/pull/83323)).
- `DocumentOutline`: Show the outline items' focus ring with the design system's outline instead of a legacy box-shadow ([#83755](https://github.com/WordPress/gutenberg/pull/83755)).
- Notes: Add a "Notes" submenu to the View group of the Options menu ([#83768](https://github.com/WordPress/gutenberg/pull/83768)).

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/collab-sidebar/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ export function useEnableFloatingSidebar( enabled = false ) {
const { disableComplementaryArea, enableComplementaryArea } =
registry.dispatch( interfaceStore );

// Hiding the complementary area only changes the preferences store.
const unsubscribe = registry.subscribe( () => {
// Return `null` to indicate the user hid the complementary area.
if ( getActiveComplementaryArea( 'core' ) === null ) {
Expand Down
22 changes: 17 additions & 5 deletions packages/editor/src/components/collab-sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SIDEBARS,
} from './constants';
import { Notes } from './notes';
import { NotesDisplayModeMenu } from './notes-display-mode-menu';
import { store as editorStore } from '../../store';
import { AddNoteMenuItem } from './add-note-menu-item';
import { NoteAvatarIndicator } from './note-indicator-toolbar';
Expand Down Expand Up @@ -50,12 +51,14 @@ function NotesSidebar( { postId } ) {
}, [] );

const blockNoteIds = getNoteIdsFromMetadata( { noteId } );
const { isDistractionFree } = useSelect( ( select ) => {
const { isDistractionFree, areNotesHidden } = useSelect( ( select ) => {
const { get } = select( preferencesStore );
return {
isDistractionFree: get( 'core', 'distractionFree' ),
areNotesHidden: get( 'core', 'notesDisplayMode' ) === 'hidden',
};
}, [] );
const { set: setPreference } = useDispatch( preferencesStore );
const selectedNoteId = useSelect(
( select ) => unlock( select( editorStore ) ).getSelectedNote(),
[]
Expand All @@ -67,10 +70,10 @@ function NotesSidebar( { postId } ) {
const showFloatingSidebar = isLargeViewport;
// Fallback to "All notes" sidebar on smaller viewports.
const showAllNotesSidebar = notes.length > 0 || ! showFloatingSidebar;
useEnableFloatingSidebar(
const hasFloatingNotes =
showFloatingSidebar &&
( unresolvedNotes.length > 0 || selectedNoteId !== undefined )
);
( unresolvedNotes.length > 0 || selectedNoteId !== undefined );
useEnableFloatingSidebar( hasFloatingNotes && ! areNotesHidden );

async function focusNote( {
targetClientId,
Expand All @@ -85,6 +88,10 @@ function NotesSidebar( { postId } ) {
if ( isApproved ) {
enableComplementaryArea( 'core', ALL_NOTES_SIDEBAR );
} else if ( ! SIDEBARS.includes( prevArea ) || ! showAllNotesSidebar ) {
// Acting on a note brings hidden notes back.
if ( showFloatingSidebar && areNotesHidden ) {
setPreference( 'core', 'notesDisplayMode', 'full' );
}
enableComplementaryArea(
'core',
showFloatingSidebar ? FLOATING_NOTES_SIDEBAR : ALL_NOTES_SIDEBAR
Expand Down Expand Up @@ -168,10 +175,15 @@ function NotesSidebar( { postId } ) {
addNewNoteForBlock( menuClientId )
}
/>
<NotesDisplayModeMenu
hasFloatingNotes={ hasFloatingNotes }
hasAllNotes={ showAllNotesSidebar }
Comment thread
Mamaduka marked this conversation as resolved.
Resolved
/>
{ showAllNotesSidebar && (
// No `name`, so the sidebar doesn't add itself to the "Panels"
// menu; the "Notes" submenu toggles it instead.
<PluginSidebar
identifier={ ALL_NOTES_SIDEBAR }
name={ ALL_NOTES_SIDEBAR }
title={ __( 'All notes' ) }
header={
<h2 className="interface-complementary-area-header__title">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { speak } from '@wordpress/a11y';
import { useViewportMatch } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { store as interfaceStore } from '@wordpress/interface';
import { store as preferencesStore } from '@wordpress/preferences';
// eslint-disable-next-line @wordpress/use-recommended-components
import { Menu } from '@wordpress/ui';
import NotesMoreMenuGroup from '../more-menu/notes-more-menu-group';
import MoreMenuSubmenu from '../more-menu/more-menu-submenu';
import { ALL_NOTES_SIDEBAR, FLOATING_NOTES_SIDEBAR } from './constants';

type NotesDisplayMode = 'full' | 'hidden';
Comment thread
Mamaduka marked this conversation as resolved.
Resolved

type NotesDisplayModeMenuProps = {
/**
* Whether there are floating notes to show.
*/
hasFloatingNotes: boolean;

/**
* Whether the "All notes" sidebar is available.
*/
hasAllNotes: boolean;
};

/**
* Renders the "Notes" submenu of the editor's Options menu, which shows or
* hides the floating notes and toggles the "All notes" sidebar.
*
* @param props Component props.
* @param props.hasFloatingNotes Whether there are floating notes to show.
* @param props.hasAllNotes Whether the "All notes" sidebar is available.
*/
export function NotesDisplayModeMenu( {
hasFloatingNotes,
hasAllNotes,
}: NotesDisplayModeMenuProps ) {
const isLargeViewport = useViewportMatch( 'medium' );
const { displayMode, isAllNotesOpen } = useSelect( ( select ) => {
return {
displayMode:
select( preferencesStore ).get( 'core', 'notesDisplayMode' ) ===
'hidden'
? 'hidden'
: 'full',
isAllNotesOpen:
select( interfaceStore ).getActiveComplementaryArea(
'core'
) === ALL_NOTES_SIDEBAR,
};
}, [] );
const { set: setPreference } = useDispatch( preferencesStore );
const { enableComplementaryArea, disableComplementaryArea } =
useDispatch( interfaceStore );

if ( ! isLargeViewport && ! hasAllNotes ) {
return null;
}

function setDisplayMode( mode: NotesDisplayMode ) {
setPreference( 'core', 'notesDisplayMode', mode );
// Showing notes is an explicit request, so it replaces any open sidebar.
if ( mode === 'full' && hasFloatingNotes ) {
enableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );
}
speak(
mode === 'hidden' ? __( 'Notes hidden.' ) : __( 'Notes shown.' )
);
}

function toggleAllNotes() {
if ( isAllNotesOpen ) {
disableComplementaryArea( 'core' );
} else {
enableComplementaryArea( 'core', ALL_NOTES_SIDEBAR );
}
}

return (
<NotesMoreMenuGroup.Fill>
<MoreMenuSubmenu label={ __( 'Notes' ) }>
{ isLargeViewport && (
<Menu.RadioGroup
value={ displayMode }
onValueChange={ setDisplayMode }
>
<Menu.RadioItem value="full" closeOnClick>
<Menu.ItemLabel>
{ __( 'Show notes' ) }
</Menu.ItemLabel>
</Menu.RadioItem>
<Menu.RadioItem value="hidden" closeOnClick>
<Menu.ItemLabel>
{ __( 'Hide notes' ) }
</Menu.ItemLabel>
</Menu.RadioItem>
</Menu.RadioGroup>
) }
{ isLargeViewport && hasAllNotes && <Menu.Separator /> }
{ hasAllNotes && (
<Menu.CheckboxItem
checked={ isAllNotesOpen }
onCheckedChange={ toggleAllNotes }
>
<Menu.ItemLabel>
{ __( 'Show all notes' ) }
</Menu.ItemLabel>
</Menu.CheckboxItem>
) }
</MoreMenuSubmenu>
</NotesMoreMenuGroup.Fill>
);
}
2 changes: 2 additions & 0 deletions packages/editor/src/components/more-menu/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MoreMenuItem from './more-menu-item';
import ModeSwitcher from '../mode-switcher';
import MoreMenuPreferenceItem from './more-menu-preference-item';
import MoreMenuSubmenu, { toMenuItems } from './more-menu-submenu';
import NotesMoreMenuGroup from './notes-more-menu-group';
import ToolsMoreMenuGroup from './tools-more-menu-group';
import ViewMoreMenuGroup from './view-more-menu-group';
import { store as editorStore } from '../../store';
Expand Down Expand Up @@ -114,6 +115,7 @@ export default function MoreMenu( { isRevisionMode = false } ) {
/>
<ViewMoreMenuGroup.Slot />
</MoreMenuSubmenu>
<NotesMoreMenuGroup.Slot />
<ActionItem.Slot
name="core/plugin-more-menu"
fillProps={ { as: MoreMenuItem } }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createSlotFill } from '@wordpress/components';

/**
* Slot in the View group of the editor's Options menu, before Panels, that the
* Notes feature fills with its submenu.
*/
const NotesMoreMenuGroup = createSlotFill( Symbol( 'NotesMoreMenuGroup' ) );

export default NotesMoreMenuGroup;
69 changes: 69 additions & 0 deletions test/e2e/specs/editor/various/block-notes-floating.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,73 @@ test.describe( 'Block Notes: floating sidebar', () => {
await expectAligned( form, () => getSelectionTop( editor ) );
} );
} );

test.describe( 'Display mode', () => {
test.afterAll( async ( { requestUtils } ) => {
await requestUtils.resetPreferences();
} );

test( 'hides and shows floating notes', async ( {
editor,
page,
blockNoteUtils,
} ) => {
await blockNoteUtils.addBlockWithNote( {
type: 'core/paragraph',
attributes: { content: 'Testing block notes' },
comment: 'A floating note',
} );
const thread = getThread( page, 'A floating note' );
const settingsToggle = page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Settings', exact: true } );

await blockNoteUtils.clickNotesMenuItem( 'Hide notes' );
await expect( thread ).toBeHidden();

// Closing another sidebar doesn't bring hidden notes back.
await editor.openDocumentSettingsSidebar();
await settingsToggle.click();
await expect( thread ).toBeHidden();

// Showing notes replaces the open sidebar.
await editor.openDocumentSettingsSidebar();
await blockNoteUtils.clickNotesMenuItem( 'Show notes' );
await expect( thread ).toBeVisible();

// Closing another sidebar brings shown notes back.
await editor.openDocumentSettingsSidebar();
await expect( thread ).toBeHidden();
await settingsToggle.click();
await expect( thread ).toBeVisible();

await blockNoteUtils.clickNotesMenuItem( 'Show all notes' );
await expect(
getSidebar( page ).getByRole( 'heading', { name: 'All notes' } )
).toBeVisible();
} );

test( 'shows hidden notes when adding a note', async ( {
editor,
page,
blockNoteUtils,
} ) => {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Testing block notes' },
} );
await blockNoteUtils.clickNotesMenuItem( 'Hide notes' );

await editor.clickBlockOptionsMenuItem( 'Add note' );
await expect(
page.getByRole( 'textbox', { name: 'New note', exact: true } )
).toBeFocused();
await expect(
getSidebar( page ).getByRole( 'treeitem', {
name: 'New note',
exact: true,
} )
).toHaveClass( /is-floating/ );
} );
} );
} );
19 changes: 19 additions & 0 deletions test/e2e/specs/editor/various/block-notes-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ class BlockNoteUtils {
return toggleButton;
}

/**
* Clicks an item in the "Notes" submenu of the editor's Options menu.
*
* @param {string} name Name of the item.
*/
async clickNotesMenuItem( name ) {
await this.#page
.getByRole( 'region', { name: 'Editor top bar' } )
.getByRole( 'button', { name: 'Options' } )
.click();
await this.#page
.getByRole( 'menuitem', { name: 'Notes', exact: true } )
.click();
await this.#page
.getByRole( 'menuitemradio', { name } )
.or( this.#page.getByRole( 'menuitemcheckbox', { name } ) )
.click();
}

async addBlockWithNote( { type, attributes = {}, comment } ) {
await test.step(
`Insert a ${ type } block with a note`,
Expand Down
Loading