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 60 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
39 changes: 32 additions & 7 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -8,9 +13,11 @@ import {
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
Tooltip,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { Icon, symbol } from '@wordpress/icons';

/**
* Internal dependencies
Expand Down Expand Up @@ -63,14 +70,20 @@ function BlockPattern( {
} }
>
<WithToolTip
showTooltip={ showTooltip }
showTooltip={ showTooltip && ! pattern.id }
title={ pattern.title }
>
<CompositeItem
role="option"
as="div"
{ ...composite }
className="block-editor-block-patterns-list__item"
className={ classnames(
'block-editor-block-patterns-list__item',
{
'block-editor-block-patterns-list__list-item-synced':
pattern.id && ! pattern.syncStatus,
}
) }
onClick={ () => {
onClick( pattern, blocks );
onHover?.( null );
Expand All @@ -91,11 +104,23 @@ function BlockPattern( {
blocks={ blocks }
viewportWidth={ viewportWidth }
/>
{ ! showTooltip && (
<div className="block-editor-block-patterns-list__item-title">
{ pattern.title }
</div>
) }

<HStack className="block-editor-patterns__pattern-details">
{ pattern.id && ! pattern.syncStatus && (
<div className="block-editor-patterns__pattern-icon-wrapper">
<Icon
className="block-editor-patterns__pattern-icon"
icon={ symbol }
/>
</div>
) }
{ ( ! showTooltip || pattern.id ) && (
<div className="block-editor-block-patterns-list__item-title">
{ pattern.title }
</div>
) }
</HStack>

{ !! pattern.description && (
<VisuallyHidden id={ descriptionId }>
{ pattern.description }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
min-height: 100px;
}

&[draggable="true"] .block-editor-block-preview__container {
&[draggable="true"] {
cursor: grab;
}
}
Expand All @@ -27,22 +27,39 @@
}

.block-editor-block-patterns-list__item-title {
padding-top: $grid-unit-10;
font-size: 12px;
text-align: center;
text-align: left;
flex-grow: 1;
}

&:hover .block-editor-block-preview__container {
box-shadow: 0 0 0 2px var(--wp-admin-theme-color);
box-shadow: 0 0 0 2px $gray-900;
}

&:focus .block-editor-block-preview__container {
@include button-style-outset__focus(var(--wp-admin-theme-color));
@include button-style-outset__focus($gray-900);
}

&.block-editor-block-patterns-list__list-item-synced {
&:hover,
&:focus {
.block-editor-block-preview__container {
box-shadow:
0 0 0 2px var(--wp-block-synced-color),
0 15px 25px rgb(0 0 0 / 7%);
}
}
}

.block-editor-patterns__pattern-details {
align-items: center;
margin-top: $grid-unit-10;
}

&: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-wrapper {
min-width: 24px;
height: 24px;
.block-editor-patterns__pattern-icon {
fill: var(--wp-block-synced-color);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* 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 }
className="block-editor-patterns__grid-pagination-previous"
>
<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' ) }
>
<span>«</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage - 1 ) }
disabled={ currentPage === 1 }
aria-label={ __( 'Previous page' ) }
>
<span>‹</span>
</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 }
className="block-editor-patterns__grid-pagination-next"
>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage + 1 ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Next page' ) }
>
<span>›</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( numPages ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Last page' ) }
size="default"
>
<span>»</span>
</Button>
</HStack>
</HStack>
</VStack>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.block-editor-patterns__grid-pagination {
border-top: 1px solid $gray-800;
padding: $grid-unit-05;

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

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

&:hover:not(:disabled) {
color: $white;
background-color: $gray-700;
}
}
}

.show-icon-labels {
.block-editor-patterns__grid-pagination {
flex-direction: column;
.block-editor-patterns__grid-pagination-previous,
.block-editor-patterns__grid-pagination-next {
flex-direction: column;
}
.components-button {
width: auto;
// Hide the button icons when labels are set to display...
span {
display: none;
}
// ... and display labels.
// Uses ::before as ::after is already used for active tab styling.
&::before {
content: attr(aria-label);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,69 @@
* WordPress dependencies
*/
import { Modal } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { usePrevious } from '@wordpress/compose';

/**
* Internal dependencies
*/
import PatternExplorerSidebar from './sidebar';
import PatternList from './patterns-list';
import { usePatternsCategories } from '../block-patterns-tab';
import { store as blockEditorStore } from '../../../store';

function PatternsExplorer( { initialCategory, patternCategories } ) {
const [ filterValue, setFilterValue ] = useState( '' );
function PatternsExplorer( { initialCategory, rootClientId } ) {
const [ searchValue, setSearchValue ] = useState( '' );
const [ patternSourceFilter, setPatternSourceFilter ] = useState( 'all' );
const patternSyncFilter = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const settings = getSettings();
return settings.patternsSyncFilter || 'all';
}, [] );
const [ selectedCategory, setSelectedCategory ] = useState(
initialCategory?.name
);

const previousSyncFilter = usePrevious( patternSyncFilter );

// If the sync filter changes, we need to select the "All" category to avoid
// showing a confusing no results screen.
useEffect( () => {
if ( patternSyncFilter && patternSyncFilter !== previousSyncFilter ) {
setSelectedCategory( initialCategory?.name );
}
}, [
patternSyncFilter,
previousSyncFilter,
patternSourceFilter,
initialCategory?.name,
] );
Comment on lines +32 to +43
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could we rewrite this without the useEffect? Or even better if we could pass setSelectedCategory down and call it when the sync filter changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeh it would be nice to do that, but had a look and plumbing through the onCategorySelect method from modal.js file and using that causes the whole component tree to rerender and the modal gets closed. But would be great to refactor this component tree at some point to allow away for these changes to be handled in the relevant event handlers


const patternCategories = usePatternsCategories(
rootClientId,
patternSourceFilter,
patternSyncFilter
);

return (
<div className="block-editor-block-patterns-explorer">
<PatternExplorerSidebar
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
onClickCategory={ setSelectedCategory }
filterValue={ filterValue }
setFilterValue={ setFilterValue }
searchValue={ searchValue }
setSearchValue={ setSearchValue }
patternSourceFilter={ patternSourceFilter }
setPatternSourceFilter={ setPatternSourceFilter }
/>
<PatternList
filterValue={ filterValue }
searchValue={ searchValue }
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
patternSourceFilter={ patternSourceFilter }
patternSyncFilter={ patternSyncFilter }
/>
</div>
);
Expand Down
Loading
Loading