Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Button } from '@wordpress/components';
// eslint-disable-next-line @wordpress/use-recommended-components -- Intentional early adoption of the new Menu, pending WordPress/gutenberg#76135.
import { Menu } from '@wordpress/ui';
import { __ } from '@wordpress/i18n';
import { cog } from '@wordpress/icons';
import {
NOTES_FILTER_ALL,
NOTES_FILTER_UNRESOLVED,
NOTES_FILTER_RESOLVED,
} from './constants';

/**
* Menu in the "All notes" sidebar header for choosing which notes the list shows.
*
* @param {Object} props
* @param {string} props.notesFilter Active filter, one of the `NOTES_FILTER_*` constants.
* @param {(filter: string) => void} props.setNotesFilter Sets the active filter.
*/
export function NotesAppearancePopover( { notesFilter, setNotesFilter } ) {
return (
<Menu.Root

Check failure on line 21 in packages/editor/src/components/collab-sidebar/appearance-popover.jsx

View workflow job for this annotation

GitHub Actions / All

JSX not allowed in files with extension '.jsx'
// Let outside interactions reach the note thread's focus-out
// handling so it can clear the selection.
modal={ false }
>
<Menu.Trigger
render={
<Button
size="compact"
icon={ cog }
label={ __( 'Appearance' ) }
className="editor-collab-sidebar__appearance-button"
/>
}
/>
<Menu.Popup
positioner={ <Menu.Positioner side="bottom" align="end" /> }
>
<Menu.RadioGroup
value={ notesFilter }
onValueChange={ setNotesFilter }
>
<Menu.GroupLabel>{ __( 'Notes' ) }</Menu.GroupLabel>
<Menu.RadioItem value={ NOTES_FILTER_ALL }>
<Menu.ItemLabel>{ __( 'All' ) }</Menu.ItemLabel>
</Menu.RadioItem>
<Menu.RadioItem value={ NOTES_FILTER_UNRESOLVED }>
<Menu.ItemLabel>{ __( 'Unresolved' ) }</Menu.ItemLabel>
</Menu.RadioItem>
<Menu.RadioItem value={ NOTES_FILTER_RESOLVED }>
<Menu.ItemLabel>{ __( 'Resolved' ) }</Menu.ItemLabel>
</Menu.RadioItem>
</Menu.RadioGroup>
</Menu.Popup>
</Menu.Root>
);
}
4 changes: 4 additions & 0 deletions packages/editor/src/components/collab-sidebar/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export const ALL_NOTES_SIDEBAR = 'edit-post/collab-history-sidebar';
export const FLOATING_NOTES_SIDEBAR = 'edit-post/collab-sidebar';
export const SIDEBARS = [ ALL_NOTES_SIDEBAR, FLOATING_NOTES_SIDEBAR ];

export const NOTES_FILTER_ALL = 'all';
export const NOTES_FILTER_UNRESOLVED = 'unresolved';
export const NOTES_FILTER_RESOLVED = 'resolved';
44 changes: 39 additions & 5 deletions packages/editor/src/components/collab-sidebar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { useRef } from '@wordpress/element';
import { useMemo, useRef, useState } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { comment as commentIcon } from '@wordpress/icons';
Expand All @@ -12,7 +12,10 @@ import {
ALL_NOTES_SIDEBAR,
FLOATING_NOTES_SIDEBAR,
SIDEBARS,
NOTES_FILTER_ALL,
NOTES_FILTER_RESOLVED,
} from './constants';
import { NotesAppearancePopover } from './appearance-popover';
import { Notes } from './notes';
import { store as editorStore } from '../../store';
import { AddNoteMenuItem } from './add-note-menu-item';
Expand All @@ -33,6 +36,7 @@ function NotesSidebar( { postId } ) {
const { selectNote } = unlock( useDispatch( editorStore ) );
const isLargeViewport = useViewportMatch( 'medium' );
const sidebarRef = useRef( null );
const [ notesFilter, setNotesFilter ] = useState( NOTES_FILTER_ALL );

const { clientId, noteId, isClassicBlock } = useSelect( ( select ) => {
const { getBlockAttributes, getSelectedBlockClientId, getBlockName } =
Expand Down Expand Up @@ -63,6 +67,26 @@ function NotesSidebar( { postId } ) {

const { notes, unresolvedNotes } = useNoteThreads( postId );

/*
* A note counts as resolved once it is approved and still anchored to a
* block, matching the boundary the "Resolved" separator is drawn at.
* Orphans stay with the active notes, so they survive the "Unresolved"
* filter. The filter is deliberately not persisted: a filter left on from
* a previous session would hide notes without explaining why.
*/
const filteredNotes = useMemo( () => {
if ( notesFilter === NOTES_FILTER_ALL ) {
return notes;
}
const isResolved = ( note ) =>
note.status === 'approved' && !! note.blockClientId;
return notes.filter( ( note ) =>
notesFilter === NOTES_FILTER_RESOLVED
? isResolved( note )
: ! isResolved( note )
);
}, [ notes, notesFilter ] );

// Only enable the floating sidebar for large viewports.
const showFloatingSidebar = isLargeViewport;
// Fallback to "All notes" sidebar on smaller viewports.
Expand Down Expand Up @@ -174,14 +198,24 @@ function NotesSidebar( { postId } ) {
name={ ALL_NOTES_SIDEBAR }
title={ __( 'All notes' ) }
header={
<h2 className="interface-complementary-area-header__title">
{ __( 'All notes' ) }
</h2>
<>
<h2 className="interface-complementary-area-header__title">
{ __( 'All notes' ) }
</h2>
<NotesAppearancePopover
notesFilter={ notesFilter }
setNotesFilter={ setNotesFilter }
/>
</>
}
icon={ commentIcon }
closeLabel={ __( 'Close Notes' ) }
>
<Notes notes={ notes } sidebarRef={ sidebarRef } />
<Notes
notes={ filteredNotes }
sidebarRef={ sidebarRef }
isFiltered={ notesFilter !== NOTES_FILTER_ALL }
/>
</PluginSidebar>
) }
{ isLargeViewport && (
Expand Down
43 changes: 30 additions & 13 deletions packages/editor/src/components/collab-sidebar/notes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import { store as editorStore } from '../../store';

const { useBlockElement } = unlock( blockEditorPrivateApis );

export function Notes( { notes, sidebarRef, isFloating = false, styles } ) {
export function Notes( {
notes,
sidebarRef,
isFloating = false,
isFiltered = false,
styles,
} ) {
const {
onCreate: onAddReply,
onEdit: onEditNote,
Expand Down Expand Up @@ -235,17 +241,19 @@ export function Notes( { notes, sidebarRef, isFloating = false, styles } ) {
}
};

// In the "All notes" view, find where the resolved notes begin so a
// "Resolved" divider can be rendered above them. Resolved notes (status
// 'approved' with a still-present block) always sort after the active
// ones, so the first match marks the boundary. The floating view only
// lists unresolved notes, so it needs no divider.
const firstResolvedIndex = isFloating
? -1
: threads.findIndex(
( thread ) =>
thread.status === 'approved' && !! thread.blockClientId
);
// In the unfiltered "All notes" view, find where the resolved notes begin
// so a "Resolved" divider can be rendered above them. Resolved notes
// (status 'approved' with a still-present block) always sort after the
// active ones, so the first match marks the boundary. The floating view
// only lists unresolved notes, and a filtered list is already all one
// status, so neither needs a divider.
const firstResolvedIndex =
isFloating || isFiltered
? -1
: threads.findIndex(
( thread ) =>
thread.status === 'approved' && !! thread.blockClientId
);

return (
<Stack
Expand All @@ -266,7 +274,16 @@ export function Notes( { notes, sidebarRef, isFloating = false, styles } ) {
isFloating ? __( 'Unresolved notes' ) : __( 'All notes' )
}
>
{ ! hasThreads && ! isFloating ? (
{ ! hasThreads && ! isFloating && isFiltered && (
<Text
variant="body-sm"
render={ <p /> }
className="editor-collab-sidebar-panel__empty-message"
>
{ __( 'No notes match this filter.' ) }
</Text>
) }
{ ! hasThreads && ! isFloating && ! isFiltered ? (
<AddNote onSubmit={ onAddReply } sidebarRef={ sidebarRef } />
) : (
<>
Expand Down
13 changes: 13 additions & 0 deletions packages/editor/src/components/collab-sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,16 @@ mark.wp-note {
.editor-collab-sidebar-panel__mention-suggestion .editor-autocompleters__user-avatar {
border-radius: $radius-round;
}

// Appearance menu trigger in the "All notes" sidebar header.
.editor-collab-sidebar__appearance-button {
color: var(--wp-admin-theme-color);
flex-shrink: 0;
}

// Shown in place of the note composer when a filter matches nothing.
.editor-collab-sidebar-panel__empty-message {
margin: 0;
color: $gray-700;
text-align: center;
}
Loading