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

Site Editor: Add Library for Template Parts & Patterns Management #51078

Merged
merged 73 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
d3731da
Add placeholder Library page
aaronrobertshaw May 25, 2023
a46d4b5
Add placeholder Library nav screen
aaronrobertshaw May 25, 2023
6c2a135
Use placeholder library page and nav screen
aaronrobertshaw May 25, 2023
01b56ae
Add dodgy placeholder display for patterns or template parts
aaronrobertshaw May 25, 2023
e59b587
Temporarily add category type and name to query params
aaronrobertshaw May 28, 2023
3221044
Try displaying patterns and template parts
aaronrobertshaw May 28, 2023
b617274
Highlight active category nav item
aaronrobertshaw May 29, 2023
4f15ff1
Add placeholder dropdown for deleting patterns
aaronrobertshaw May 30, 2023
330cee3
Try making pattern previews clickable
aaronrobertshaw May 30, 2023
7514f83
Add placeholder create pattern modal and action
aaronrobertshaw May 30, 2023
2fa73e0
Add category select to create pattern modal
aaronrobertshaw May 31, 2023
99f540b
Remove the library url params when existing library
glendaviesnz May 31, 2023
32a8f6d
Fix pattern styles not loading on fresh reload of Library page (#51114)
talldan May 31, 2023
1ef2c8b
Hook up template part preview to existing edit page
aaronrobertshaw Jun 1, 2023
0123b0b
Fix template part pattern display in library
aaronrobertshaw Jun 1, 2023
0b6737d
Try retrieving user created patterns from wp_block CPT
aaronrobertshaw Jun 1, 2023
dc0d64f
Update now user created patterns have category arrays
aaronrobertshaw Jun 2, 2023
aa30958
Update user created patterns based of new meta wp_block property
aaronrobertshaw Jun 2, 2023
0be9c45
Remove new template part screen as it was covered by pattern screen
aaronrobertshaw Jun 2, 2023
46d8130
Allow user created patterns to be clicked on
aaronrobertshaw Jun 2, 2023
8348699
Fix typos
aaronrobertshaw Jun 2, 2023
4860faf
Fix classnames
aaronrobertshaw Jun 2, 2023
1bc7c91
Hook up reusable block editing
aaronrobertshaw Jun 2, 2023
96c9e55
Try adding delete for user patterns
aaronrobertshaw Jun 5, 2023
bd53f4c
Add snackbar notices for user-created pattern deletion
aaronrobertshaw Jun 6, 2023
f1ba5ac
Hook up pattern creation modal
aaronrobertshaw Jun 6, 2023
6675328
Make new patterns return to correct category
aaronrobertshaw Jun 6, 2023
0046f1d
Try updating the Library to use pattern category taxonomy
aaronrobertshaw Jun 6, 2023
ce25de7
Fix theme pattern display in Grid
aaronrobertshaw Jun 7, 2023
ea3a45f
Fix selected pattern category detection
aaronrobertshaw Jun 7, 2023
2117805
Use invalidateResolution to clear taxonomy cache
aaronrobertshaw Jun 8, 2023
027296c
Include uncategorized reusable block patterns in Library
aaronrobertshaw Jun 8, 2023
53bcb37
Make pattern category selection option and add sync toggle
aaronrobertshaw Jun 8, 2023
4950429
Separate display of synced/unsynced patterns
aaronrobertshaw Jun 13, 2023
a3bc282
Add placeholder search control.
aaronrobertshaw Jun 13, 2023
50a084a
Update to use new Page components added along with Table
aaronrobertshaw Jun 13, 2023
a1acfc0
Fix private apis imports
aaronrobertshaw Jun 14, 2023
d0830f5
style changes to library
SaxonF Jun 14, 2023
cc5ee06
copy change
SaxonF Jun 14, 2023
9da0092
svg colour
SaxonF Jun 14, 2023
a5cc78d
add template part and pattern dialog
SaxonF Jun 14, 2023
5ffe5e3
fix template part modal close
SaxonF Jun 15, 2023
c55ad6f
Try filtering of patterns in library
aaronrobertshaw Jun 15, 2023
c90f2c3
search input patterns style
SaxonF Jun 15, 2023
c404b3f
responsive pattern grid
SaxonF Jun 15, 2023
bf13603
Use only default block pattern categories
aaronrobertshaw Jun 15, 2023
d5c8b58
Fix Library routing in mobile (#51558)
kevin940726 Jun 16, 2023
425759b
Remove obselete TODO comments
aaronrobertshaw Jun 16, 2023
e54aa4b
Use extracted useDebouncedInput hook
aaronrobertshaw Jun 16, 2023
051b749
Fix clicking browser's back button in edit mode from the Library (#51…
kevin940726 Jun 18, 2023
e4c997b
Rename Your Patterns to Custom patterns
aaronrobertshaw Jun 20, 2023
c227bb5
Remove arrow functions for internal Grid components
aaronrobertshaw Jun 20, 2023
c1c087c
Fix linting error
aaronrobertshaw Jun 20, 2023
df6177a
Add dependencies to package-lock.json
aaronrobertshaw Jun 20, 2023
8fd05d0
Update core pattern filtering
aaronrobertshaw Jun 20, 2023
eab0181
Consolidate and reuse constants
aaronrobertshaw Jun 20, 2023
b7b9881
Clean up comments and unused styles
aaronrobertshaw Jun 21, 2023
00f1623
Rename manage all link for custom patterns
aaronrobertshaw Jun 21, 2023
0137777
Remove `wp_block` property from post meta for patterns
talldan Jun 21, 2023
59b4b0c
Update conversion of reusable block to pattern after sync_status moved
aaronrobertshaw Jun 21, 2023
17ec997
Rename setReusableBlock to setEditedEntity
aaronrobertshaw Jun 21, 2023
51c9d7e
Improve wording
aaronrobertshaw Jun 21, 2023
e2f672a
Add aria description for pattern action menu
talldan Jun 21, 2023
a263e16
Refactor filtering out duplicate patterns by name
aaronrobertshaw Jun 21, 2023
df1c567
Add focus style for patterns
talldan Jun 21, 2023
5d94265
Add empty pattern placeholder
aaronrobertshaw Jun 21, 2023
c496134
Fix tests and converter flow
kevin940726 Jun 21, 2023
5bdd114
Tweak focused placeholder styles
aaronrobertshaw Jun 21, 2023
6d7b0d6
Make the action menu unfocusable and use a keyboard shortcut for dele…
talldan Jun 21, 2023
4aa656a
Add confirm step for deleting
talldan Jun 21, 2023
fa179de
Add a more descriptive aria-description
talldan Jun 21, 2023
50a1383
Ensure pattern lists are announced with the correct number of items
talldan Jun 21, 2023
ea08bb0
Improve labelling of pattern lists
talldan Jun 21, 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
12 changes: 12 additions & 0 deletions docs/reference-guides/data/data-core-edit-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@ _Returns_

- `number`: The resolved template ID for the page route.

### setReusableBlock
talldan marked this conversation as resolved.
Show resolved Hide resolved

Action that sets a reusable block.

_Parameters_

- _reusableBlockId_ `string`: The reusable block ID.

_Returns_

- `Object`: Action object.

### setTemplate

Action that sets a template, optionally fetching it from REST API.
Expand Down
32 changes: 17 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@wordpress/viewport": "file:../viewport",
"@wordpress/widgets": "file:../widgets",
"@wordpress/wordcount": "file:../wordcount",
"change-case": "^4.1.2",
"classnames": "^2.3.1",
"colord": "^2.9.2",
"deepmerge": "^4.3.0",
Expand All @@ -73,7 +74,8 @@
"lodash": "^4.17.21",
"memize": "^2.1.0",
"react-autosize-textarea": "^7.1.0",
"rememo": "^4.0.2"
"rememo": "^4.0.2",
"remove-accents": "^0.4.2"
},
"peerDependencies": {
"react": "^18.0.0",
Expand Down
93 changes: 93 additions & 0 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* WordPress dependencies
*/
import { DropdownMenu } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { plus, header, file } from '@wordpress/icons';
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
*/
import CreatePatternModal from '../create-pattern-modal';
import CreateTemplatePartModal from '../create-template-part-modal';
import { unlock } from '../../lock-unlock';
import SidebarButton from '../sidebar-button';

const { useHistory } = unlock( routerPrivateApis );

export default function AddNewPattern() {
const history = useHistory();
const [ showPatternModal, setShowPatternModal ] = useState( false );
const [ showTemplatePartModal, setShowTemplatePartModal ] =
useState( false );

function handleCreatePattern( { pattern, categoryId } ) {
setShowPatternModal( false );

history.push( {
postId: pattern.id,
postType: 'wp_block',
categoryType: 'wp_block',
categoryId,
canvas: 'edit',
} );
}

function handleCreateTemplatePart( templatePart ) {
setShowTemplatePartModal( false );

// Navigate to the created template part editor.
history.push( {
postId: templatePart.id,
postType: 'wp_template_part',
canvas: 'edit',
} );
}

function handleError() {
setShowPatternModal( false );
setShowTemplatePartModal( false );
}

return (
<>
<DropdownMenu
controls={ [
{
icon: header,
onClick: () => setShowTemplatePartModal( true ),
title: 'Create a template part',
},
{
icon: file,
onClick: () => setShowPatternModal( true ),
title: 'Create a pattern',
},
] }
icon={
<SidebarButton
icon={ plus }
label={ __( 'Create a pattern' ) }
/>
}
label="Create a pattern."
/>
{ showPatternModal && (
<CreatePatternModal
closeModal={ () => setShowPatternModal( false ) }
onCreate={ handleCreatePattern }
onError={ handleError }
/>
) }
{ showTemplatePartModal && (
<CreateTemplatePartModal
closeModal={ () => setShowTemplatePartModal( false ) }
onCreate={ handleCreateTemplatePart }
onError={ handleError }
/>
) }
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
} from '@wordpress/components';
import { useDebounce } from '@wordpress/compose';
import { useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import useDebouncedInput from '../../utils/use-debounced-input';
import { mapToIHasNameAndId } from './utils';

const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -73,18 +73,6 @@ function SuggestionListItem( {
);
}

function useDebouncedInput() {
const [ input, setInput ] = useState( '' );
const [ debounced, setter ] = useState( '' );
const setDebounced = useDebounce( setter, 250 );
useEffect( () => {
if ( debounced !== input ) {
setDebounced( input );
}
}, [ debounced, input ] );
return [ input, setInput, debounced ];
}

function useSearchSuggestions( entityForSuggestions, search ) {
const { config } = entityForSuggestions;
const query = useMemo(
Expand Down
3 changes: 0 additions & 3 deletions packages/edit-site/src/components/add-new-template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { store as coreStore } from '@wordpress/core-data';
* Internal dependencies
*/
import NewTemplate from './new-template';
import NewTemplatePart from './new-template-part';

export default function AddNewTemplate( {
templateType = 'wp_template',
Expand All @@ -25,8 +24,6 @@ export default function AddNewTemplate( {

if ( templateType === 'wp_template' ) {
return <NewTemplate { ...props } postType={ postType } />;
} else if ( templateType === 'wp_template_part' ) {
return <NewTemplatePart { ...props } postType={ postType } />;
}

return null;
Expand Down
Loading