Nav Block - enable page creation from within Block#19775
Conversation
Question:In this implementation you cannot use the arrow to move to the Is this valid a11y wise? My concern is that the If we want to promote the |
|
Note: in order to make this PR work we're going to need:
Will tackle this tomorrow. |
getdave
left a comment
There was a problem hiding this comment.
Noticed some inconsistencies and problems building up. We should look to tackle these before they become any more "baked in" @marekhrabe.
packages/block-editor/src/components/link-control/search-create-button.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/link-control/search-create-button.js
Outdated
Show resolved
Hide resolved
37d322c to
49f0b2e
Compare
|
@aduth I rebased this branch and found a tonne of conflicts as a result of your refactoring of If you have time to glance at the rebased file in this branch I'd feel a lot more confident knowing the rebase hadn't nuked any of your changes. |
|
I can plan to take a look in my morning. Are you otherwise expecting this to be review ready? |
Thanks (with caveat below).
No. Actually there is a bug whereby hitting Maybe best wait until that's fixed. That said, weren't you looking at the handling of form |
|
What I was working on with regards to the submission is already merged, so if there's an issue, it's not one I'd be aware of or am actively working on. See: #19651 |
d98b989 to
6882363
Compare
|
Working on rebase to accommodate changes from #19462 |
jeryj
left a comment
There was a problem hiding this comment.
So much great work in here, @getdave! IMO, anything else that needs fixed other than very, very minor things should be broken out into new Issues and PRs, as this one has grown so much as to be difficult to review and discuss. I think this is in a mergeable state. Great work! 🚢
| return ( | ||
| <LinkControlSearchItem | ||
| key={ `${ suggestion.id }-${ suggestion.type }` } | ||
| itemProps={ buildSuggestionItemProps( | ||
| suggestion, | ||
| index | ||
| ) } | ||
| suggestion={ suggestion } | ||
| index={ index } | ||
| onClick={ () => { | ||
| stopEditing(); | ||
| onChange( { ...value, ...suggestion } ); | ||
| } } | ||
| isSelected={ index === selectedSuggestion } | ||
| isURL={ directLinkEntryTypes.includes( | ||
| suggestion.type.toLowerCase() | ||
| ) } | ||
| searchTerm={ inputValue } | ||
| /> | ||
| ); |
There was a problem hiding this comment.
It would be nice if we could refactor to reduce the code duplication between this and the LinkControlSearchCreate above. It seems like the two receive largely the same props, with few exceptions.
There was a problem hiding this comment.
Only three props are actually shared. I really think given the potential for rebases we should do this in a followup.
packages/block-editor/src/components/link-control/search-create-button.js
Outdated
Show resolved
Hide resolved
|
With approval from Andrew lets fix up his final review notes on Monday next week and get this merged |
This was a throw back to a previous state of the `LinkControl` component whereby we wanted to render a create option to allow the user to create blank pages. This was removed as a requirement but the component was not fixed to account for that. Addresses: #19775 (comment)
|
Build failures are due to a known |
Previously the code to handle the async flow including error handling was duplicated across two handler props. Consolidating helps DRY things and avoid accidental errors being introduced. Addresses #19775 (comment)
… if provided. Addresses #19775 (comment)
|
I will merge this shortly following 👍 from @obenland. |
obenland
left a comment
There was a problem hiding this comment.
Did a final smoke test with admin, editor, and author roles and everything works as expected.
Really nice work @getdave, thank you for your persistence! Also thanks to @marekhrabe, @jeryj, and @aduth for your tremendous help.
![]()
|
Ok that's all folks. It's merged! |

Closes #18900
This PR aims to allow users to create new Pages (only) on the fly from within the Navigation Block.
A Note on coupling with WordPress
Note that the
LinkControlis within the Block Editor which is supposed to be "unaware" of WordPress. That said the existing implementation inmasteris already coupled to WordPress viaURLInputwhich requests data from WP endpoints. Therefore we're following existing precedent here by introducing a prop to pass a handler function create entities on the fly. This is entirely optional and can be configured by the developer so it is less coupled to WP than you might imagine. There is a concept of "creating something" but that's it. We feel this is a good compromise.Testing Instructions
Dashboard > PagesOther testing scenarios
Todo
Consider using
core/datato create the Pages rather than manualapiFetch.Fix to ensure Create Page option is displayed if the entry contains spaces (eg:
This is a Test).Implement error handling for when Page cannot be created or times-out.
Implement handling when Page already exists. Perhaps when attempting to create a page which already exists, it seamlessly reuses the existing Page without any need for erroring.@marekhrabe and I decided that as per current WP convention a new page should be created with the entered title but with a different slug (eg:new-page-2).Handle a11y concerns regarding the "Create" option not being a valid suggestion which you can move to via the Arrow keys.
Avoid showing the option to create pages when user doesn't have the capability (
wp.data.select('core').canUser('create', 'pages'))Ensure entity (aka Page creation) is possible using keyboard.
Implement checks against failure
saveEntityRecordresult types and alsoentryresults which are missing appropriate values. This is needed in Nav Link BlockeditcreateEntity()definition.Avoid suggesting URLs for input that isn't a valid URL. This may be better handled in a separate PR as having both options isn't causing any regression. Waiting on URL: Conform to URL Living Standard definition of valid URL #19871.
Add "Loading" spinner Icon to
isResolvingstate when creating a Page (@jeryj ) - see Navigation: Add option to create a new page #18900 (comment)Ensure Error notice has correct spacing as per Design (@jeryj ).
Fix failing e2e tests due to use of
uniqueIdinvalidating the snapshots. Check with @aduth that usinguniqueIdis a good idea. (@jeryj ).Solve creation of unique IDs for the x2 manually created suggestion types.
Resolve suggestions label a11y issue (@jeryj).
Fix additional unwanted spacing below input when no search results. See here. (@jeryj)
Write e2e test for Nav Block to cover creating Pages from within Block.
Update color references to Sass vars in consultation with Designer (@jeryj )
Fix component possibly unmounted when state change occurs issue.
How has this been tested?
Unit tests. Manual tests.
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: