-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add create new overlay button to Navigation block #73919
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d2dd482
Add create new overlay button to Navigation block
getdave 8fcca71
Move utils
getdave 1597ca2
Refactor overlay creation to use createInterpolateElement in help text
getdave 6ef4dd9
Simplify saving state
getdave f4718a5
Remove passing content to create empty
getdave b9d6054
Avoid manually constructing the template id when we have it from the …
getdave 4c4972c
Decouple creation and update handling
getdave dbe2c16
Avoid custom loading UI
getdave b12671a
Remove reundant invalidation
getdave b1ca436
remove redundant util
getdave 5aae77b
Update tests
getdave 074e97e
Tweak test wording
getdave e83f9c7
Slim down tests
getdave d57a975
More tweaks to test names
getdave ace2a7e
Add test coverage for create
getdave 64a7f45
Test hook
getdave 76bf934
Add more tests coverage
getdave f4d87b4
Fix Edit button visibility when overlay template is deleted
getdave d19fc85
Improve accessibility of create overlay button
getdave 9516a48
Refactor create overlay button to icon-based button with tooltip
getdave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add test coverage for create
- Loading branch information
commit ace2a7eb066b61f6a8931a3642d872faa41883cf
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/block-library/src/navigation/edit/use-create-overlay.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useCallback } from '@wordpress/element'; | ||
| import { useDispatch } from '@wordpress/data'; | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getUniqueTemplatePartTitle, getCleanTemplatePartSlug } from './utils'; | ||
|
|
||
| /** | ||
| * Hook to create a new overlay template part. | ||
| * | ||
| * @param {Array} overlayTemplateParts Array of existing overlay template parts. | ||
| * @return {Function} Function to create a new overlay template part. | ||
getdave marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| export default function useCreateOverlayTemplatePart( overlayTemplateParts ) { | ||
| const { saveEntityRecord } = useDispatch( coreStore ); | ||
|
|
||
| const createOverlayTemplatePart = useCallback( async () => { | ||
| // Generate unique name using only overlay area template parts | ||
| // Filter to only include template parts with titles for uniqueness check | ||
| const templatePartsWithTitles = overlayTemplateParts.filter( | ||
| ( templatePart ) => templatePart.title?.rendered | ||
| ); | ||
| const uniqueTitle = getUniqueTemplatePartTitle( | ||
| __( 'Overlay' ), | ||
| templatePartsWithTitles | ||
| ); | ||
| const cleanSlug = getCleanTemplatePartSlug( uniqueTitle ); | ||
|
|
||
| // Create the template part | ||
| const templatePart = await saveEntityRecord( | ||
| 'postType', | ||
| 'wp_template_part', | ||
| { | ||
| slug: cleanSlug, | ||
| title: uniqueTitle, | ||
| area: 'overlay', | ||
| }, | ||
| { throwOnError: true } | ||
| ); | ||
|
|
||
| return templatePart; | ||
| }, [ overlayTemplateParts, saveEntityRecord ] ); | ||
|
|
||
| return createOverlayTemplatePart; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.