Skip to content
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

Patterns: merge unsynced into inserter patterns tab and add paging and filtering #54007

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
fc921a7
merge synced patterns into patterns tab and add paging
glendaviesnz Sep 3, 2023
8ca644b
Add sync status back
glendaviesnz Aug 29, 2023
9be8084
Add back pattern id
glendaviesnz Aug 29, 2023
a098a7b
Add my patterns toggle
glendaviesnz Aug 29, 2023
fda3f16
Remove sync toggle for now
glendaviesnz Aug 29, 2023
59a2e0c
Make sort order same as site editor
glendaviesnz Sep 3, 2023
f99c31d
Fix bug with paging
glendaviesnz Sep 3, 2023
516341c
Reset to page one if search filter changes
glendaviesnz Sep 4, 2023
d4705b7
Update e2e tests
glendaviesnz Sep 4, 2023
39f33b2
rename snapshot file
glendaviesnz Sep 5, 2023
4aa0623
Add pattern type filters to insert patterns tab
glendaviesnz Sep 6, 2023
81165ec
Add screen reader announcement to indicate number of categories when …
glendaviesnz Sep 6, 2023
476ef8f
Add aria label to filter select
glendaviesnz Sep 6, 2023
ce2aae9
Add filtering to patterns explorer
glendaviesnz Sep 7, 2023
f64f043
Simplify filter
glendaviesnz Sep 7, 2023
a8c0785
Fix test snapshots
glendaviesnz Sep 7, 2023
684e57e
Extract filtering logic into a separate method
glendaviesnz Sep 7, 2023
2ad6587
Remove redundant fragment
glendaviesnz Sep 7, 2023
a9c4ae7
Improve readability of pattern filter
glendaviesnz Sep 7, 2023
f60beb8
Spread paging props instead of destructuring
glendaviesnz Sep 7, 2023
71271f3
Switch back to all category when changing filters
glendaviesnz Sep 7, 2023
c62b4fd
Remove duplicate items from inserter and fix icon alignmen
glendaviesnz Sep 8, 2023
de814a6
Pattern title layout
glendaviesnz Sep 8, 2023
48dcd35
Fix unit tests
glendaviesnz Sep 8, 2023
bb6cec5
Switch icon to center alignment
glendaviesnz Sep 8, 2023
cec2b9a
Make the removal of reusable blocks more targeted to keep selector ba…
glendaviesnz Sep 8, 2023
96b9459
Revert "Fix unit tests"
glendaviesnz Sep 8, 2023
26f486b
Add show icon labels support to pagination
glendaviesnz Sep 8, 2023
e2292a1
Add the show-icons-label to the body element so it also gets applied …
glendaviesnz Sep 10, 2023
2f53ea2
Switch to using a ref and getScrollContainer to find scroll container
glendaviesnz Sep 10, 2023
bf74886
remove the synced icon and instead use synced colored border on hover
glendaviesnz Sep 10, 2023
b8eadf5
Fix issues with category counts being announced more than once by scr…
glendaviesnz Sep 11, 2023
2153343
Revert "remove the synced icon and instead use synced colored border …
glendaviesnz Sep 11, 2023
1b4f30a
Put the icon back
glendaviesnz Sep 11, 2023
39e5f82
split out the sync toggle to pattern list page
glendaviesnz Sep 11, 2023
48c36e5
Tidy up naming
glendaviesnz Sep 11, 2023
351204d
Set height of select filter
glendaviesnz Sep 11, 2023
fc40fe7
Reset categories if changing sync filter
glendaviesnz Sep 11, 2023
5199163
Reset category when changing sync filter in patterns explorer
glendaviesnz Sep 12, 2023
6fbc699
remove sync filter when searching
glendaviesnz Sep 12, 2023
4487351
constrain width of sync toggle in pattern explorer
glendaviesnz Sep 12, 2023
616066d
Also set filter height in patterns explorer
glendaviesnz Sep 12, 2023
f845d66
Switch to select for sync filter temporarily
glendaviesnz Sep 12, 2023
720d3cb
Fix filter width
glendaviesnz Sep 12, 2023
0ee4b81
Reset sync filter setting to all each time it is mounted
glendaviesnz Sep 12, 2023
8839f7a
Revert "Reset sync filter setting to all each time it is mounted"
glendaviesnz Sep 12, 2023
5951dad
Fix issue with all category auto opening when tab first opened
glendaviesnz Sep 12, 2023
3a920f9
Suggesting wording changes from design review
glendaviesnz Sep 12, 2023
546026f
Revert "Fix issue with all category auto opening when tab first opened"
glendaviesnz Sep 12, 2023
389285f
Remove the all category and have all panel open by default
glendaviesnz Sep 12, 2023
5fd5edc
Remove spoken announcement of category count from hook as currently t…
glendaviesnz Sep 12, 2023
2cb5cfc
Move filter above category list
glendaviesnz Sep 12, 2023
f69a88f
map to new array in resolver rather than selector to prevent pointles…
glendaviesnz Sep 13, 2023
57d54db
Revert "Remove spoken announcement of category count from hook as cur…
glendaviesnz Sep 13, 2023
275e01e
Simplify styling
jameskoster Sep 13, 2023
f1f4edc
Add the All categories option back so there is an easy way back to li…
glendaviesnz Sep 13, 2023
a37cdd3
Remove onUnmount category reset
glendaviesnz Sep 13, 2023
da77818
Fix sync filter reset check
glendaviesnz Sep 13, 2023
8b94003
Add no results message
glendaviesnz Sep 13, 2023
8458d29
Reset the category when leaving patterns tab
glendaviesnz Sep 14, 2023
c293dc7
make sure pattern type filters are applied to search results
glendaviesnz Sep 14, 2023
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
16 changes: 16 additions & 0 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, symbolFilled } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -101,6 +102,21 @@ function BlockPattern( {
{ pattern.description }
</VisuallyHidden>
) }
{ pattern.id && ! pattern.syncStatus && (
<Tooltip
position="top center"
text={ __(
'Editing this pattern will also update anywhere it is used'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This icon is not tabbable and thus won't announce this text for screen readers. Maybe we should merge this into the description above? (And yep probably it's also an issue in the patterns page in the site editor? 😅 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be more annoying than useful to hit that for every pattern, especially if tabbing through a filtered list of just synced patterns? Do you think we could look at this as a follow up and cover site editor and post inserter together?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I meant as a follow-up to look into in the future!

) }
>
<span>
<Icon
className="block-editor-patterns__pattern-icon"
icon={ symbolFilled }
/>
</span>
</Tooltip>
) }
</CompositeItem>
</WithToolTip>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@
@include button-style-outset__focus(var(--wp-admin-theme-color));
}


&:hover .block-editor-block-patterns-list__item-title,
&:focus .block-editor-block-patterns-list__item-title {
color: var(--wp-admin-theme-color);
}

.block-editor-patterns__pattern-icon {
fill: #fff;
background: var(--wp-block-synced-color);
border-radius: 4px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* WordPress dependencies
*/
import {
__experimentalVStack as VStack,
__experimentalHStack as HStack,
__experimentalText as Text,
Button,
} from '@wordpress/components';
import { __, _x, _n, sprintf } from '@wordpress/i18n';

export default function Pagination( {
currentPage,
numPages,
changePage,
totalItems,
} ) {
return (
<VStack>
<Text variant="muted">
{
// translators: %s: Total number of patterns.
sprintf(
// translators: %s: Total number of patterns.
_n( '%s item', '%s items', totalItems ),
totalItems
)
}
</Text>
<HStack
expanded={ false }
spacing={ 3 }
justify="flex-start"
className="block-editor-patterns__grid-pagination"
>
<HStack expanded={ false } spacing={ 1 }>
<Button
variant="tertiary"
onClick={ () => changePage( 1 ) }
disabled={ currentPage === 1 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder where we should move the focus after navigating to a different page. Should we retain the focus on the prev/next button? Or should we move the focus to the first pattern to match the visual jump? If we decide to retain the focus then we probably want to change this to aria-disabled to prevent focus lost when pressing this button for instance. This can all be reviewed by an accessibility expert though, I'm just tossing out some questions 😅 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to look at this as a follow-up combined with the site editor pagination - ideally we should finalise the pattern we should use for this and see if we can have a generic pagination component that can be shared between site/post editor.

aria-label={ __( 'First page' ) }
>
«
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage - 1 ) }
disabled={ currentPage === 1 }
aria-label={ __( 'Previous page' ) }
>
</Button>
</HStack>
<Text variant="muted">
{ sprintf(
// translators: %1$s: Current page number, %2$s: Total number of pages.
_x( '%1$s of %2$s', 'paging' ),
currentPage,
numPages
) }
</Text>
<HStack expanded={ false } spacing={ 1 }>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage + 1 ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Next page' ) }
>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( numPages ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Last page' ) }
>
»
</Button>
</HStack>
</HStack>
</VStack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.block-editor-patterns__grid-pagination {
border-top: 1px solid $gray-800;
padding: $grid-unit-05;

.components-button.is-tertiary {
width: $button-size-compact;
height: $button-size-compact;
justify-content: center;

&:disabled {
color: $gray-600;
background: none;
}

&:hover:not(:disabled) {
background-color: $gray-700;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,33 @@ import { __ } from '@wordpress/i18n';
*/
import PatternExplorerSidebar from './sidebar';
import PatternList from './patterns-list';
import { SYNC_FILTERS } from '../block-patterns-filter';
import { usePatternsCategories } from '../block-patterns-tab';

function PatternsExplorer( { initialCategory, patternCategories } ) {
const [ filterValue, setFilterValue ] = useState( '' );
function PatternsExplorer( { initialCategory, rootClientId } ) {
const [ searchValue, setSearchValue ] = useState( '' );
const [ filterValue, setFilterValue ] = useState( SYNC_FILTERS.all );
const [ selectedCategory, setSelectedCategory ] = useState(
initialCategory?.name
);
const patternCategories = usePatternsCategories(
rootClientId,
filterValue
);

return (
<div className="block-editor-block-patterns-explorer">
<PatternExplorerSidebar
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
onClickCategory={ setSelectedCategory }
searchValue={ searchValue }
setSearchValue={ setSearchValue }
filterValue={ filterValue }
setFilterValue={ setFilterValue }
/>
<PatternList
searchValue={ searchValue }
filterValue={ filterValue }
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { useMemo, useEffect } from '@wordpress/element';
import { _n, sprintf } from '@wordpress/i18n';
import { useDebounce, useAsyncList } from '@wordpress/compose';
import { useDebounce } from '@wordpress/compose';
import { __experimentalHeading as Heading } from '@wordpress/components';
import { speak } from '@wordpress/a11y';

Expand All @@ -16,8 +16,10 @@ import useInsertionPoint from '../hooks/use-insertion-point';
import usePatternsState from '../hooks/use-patterns-state';
import InserterListbox from '../../inserter-listbox';
import { searchItems } from '../search-items';

const INITIAL_INSERTER_RESULTS = 2;
import BlockPatternsPaging from '../../block-patterns-paging';
import usePatternsPaging from '../hooks/use-patterns-paging';
import { allPatternsCategory } from '../block-patterns-tab';
import { PATTERN_TYPES } from '../block-patterns-filter';

function PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {
if ( ! filterValue ) {
Expand All @@ -43,7 +45,12 @@ function PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {
);
}

function PatternList( { filterValue, selectedCategory, patternCategories } ) {
function PatternList( {
searchValue,
filterValue,
selectedCategory,
patternCategories,
} ) {
const debouncedSpeak = useDebounce( speak, 500 );
const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {
shouldFocusBlock: true,
Expand All @@ -62,21 +69,36 @@ function PatternList( { filterValue, selectedCategory, patternCategories } ) {
);

const filteredBlockPatterns = useMemo( () => {
if ( ! filterValue ) {
return allPatterns.filter( ( pattern ) =>
selectedCategory === 'uncategorized'
if ( ! searchValue ) {
return allPatterns.filter( ( pattern ) => {
if (
( filterValue === PATTERN_TYPES.theme &&
pattern.name.startsWith( 'core/block' ) ) ||
( filterValue === PATTERN_TYPES.synced &&
pattern.syncStatus !== '' ) ||
( filterValue === PATTERN_TYPES.unsynced &&
pattern.syncStatus !== PATTERN_TYPES.unsynced )
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
) {
return false;
}

if ( selectedCategory === allPatternsCategory.name ) {
return true;
}
return selectedCategory === 'uncategorized'
? ! pattern.categories?.length ||
pattern.categories.every(
( category ) =>
! registeredPatternCategories.includes(
category
)
)
: pattern.categories?.includes( selectedCategory )
);
pattern.categories.every(
( category ) =>
! registeredPatternCategories.includes(
category
)
)
: pattern.categories?.includes( selectedCategory );
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
} );
}
return searchItems( allPatterns, filterValue );
return searchItems( allPatterns, searchValue );
}, [
searchValue,
filterValue,
allPatterns,
selectedCategory,
Expand All @@ -97,9 +119,19 @@ function PatternList( { filterValue, selectedCategory, patternCategories } ) {
debouncedSpeak( resultsFoundMessage );
}, [ filterValue, debouncedSpeak, filteredBlockPatterns.length ] );

const currentShownPatterns = useAsyncList( filteredBlockPatterns, {
step: INITIAL_INSERTER_RESULTS,
} );
const {
totalItems,
categoryPatterns,
categoryPatternsAsyncList,
numPages,
changePage,
currentPage,
} = usePatternsPaging(
filteredBlockPatterns,
selectedCategory,
'.components-modal__content.is-scrollable',
filterValue
);

const hasItems = !! filteredBlockPatterns?.length;
return (
Expand All @@ -114,12 +146,20 @@ function PatternList( { filterValue, selectedCategory, patternCategories } ) {
{ ! hasItems && <InserterNoResults /> }
{ hasItems && (
<BlockPatternsList
shownPatterns={ currentShownPatterns }
blockPatterns={ filteredBlockPatterns }
shownPatterns={ categoryPatternsAsyncList }
blockPatterns={ categoryPatterns }
onClickPattern={ onClickPattern }
isDraggable={ false }
/>
) }
{ numPages > 1 && (
<BlockPatternsPaging
currentPage={ currentPage }
numPages={ numPages }
changePage={ changePage }
totalItems={ totalItems }
/>
) }
</InserterListbox>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import { Button, SearchControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { default as BlockPatternsFilter } from '../block-patterns-filter';

function PatternCategoriesList( {
selectedCategory,
patternCategories,
Expand Down Expand Up @@ -31,14 +36,14 @@ function PatternCategoriesList( {
);
}

function PatternsExplorerSearch( { filterValue, setFilterValue } ) {
function PatternsExplorerSearch( { searchValue, setSearchValue } ) {
const baseClassName = 'block-editor-block-patterns-explorer__search';
return (
<div className={ baseClassName }>
<SearchControl
__nextHasNoMarginBottom
onChange={ setFilterValue }
value={ filterValue }
onChange={ setSearchValue }
value={ searchValue }
label={ __( 'Search for patterns' ) }
placeholder={ __( 'Search' ) }
/>
Expand All @@ -52,15 +57,21 @@ function PatternExplorerSidebar( {
onClickCategory,
filterValue,
setFilterValue,
searchValue,
setSearchValue,
} ) {
const baseClassName = 'block-editor-block-patterns-explorer__sidebar';
return (
<div className={ baseClassName }>
<PatternsExplorerSearch
filterValue={ filterValue }
setFilterValue={ setFilterValue }
searchValue={ searchValue }
setSearchValue={ setSearchValue }
/>
<BlockPatternsFilter
value={ filterValue }
onChange={ setFilterValue }
/>
{ ! filterValue && (
{ ! searchValue && (
<PatternCategoriesList
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
Expand Down
Loading
Loading