-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try making page list a controlled block #46416
Merged
Merged
Changes from all commits
Commits
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
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -25,7 +25,7 @@ import { | |
Button, | ||
} from '@wordpress/components'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { useMemo, useState, useEffect } from '@wordpress/element'; | ||
import { useMemo, useState } from '@wordpress/element'; | ||
import { useEntityRecords } from '@wordpress/core-data'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
|
||
|
@@ -39,6 +39,7 @@ import { convertDescription } from './constants'; | |
// We only show the edit option when page count is <= MAX_PAGE_COUNT | ||
// Performance of Navigation Links is not good past this value. | ||
const MAX_PAGE_COUNT = 100; | ||
const NOOP = () => {}; | ||
|
||
export default function PageListEdit( { | ||
context, | ||
|
@@ -49,8 +50,6 @@ export default function PageListEdit( { | |
const { parentPageID } = attributes; | ||
const [ pages ] = useGetPages(); | ||
const { pagesByParentId, totalPages, hasResolvedPages } = usePageData(); | ||
const { replaceInnerBlocks, __unstableMarkNextChangeAsNotPersistent } = | ||
useDispatch( blockEditorStore ); | ||
|
||
const isNavigationChild = 'showSubmenuIcon' in context; | ||
const allowConvertToLinks = | ||
|
@@ -133,6 +132,9 @@ export default function PageListEdit( { | |
renderAppender: false, | ||
__unstableDisableDropZone: true, | ||
templateLock: 'all', | ||
onInput: NOOP, | ||
onChange: NOOP, | ||
value: blockList, | ||
} ); | ||
|
||
const getBlockContent = () => { | ||
|
@@ -185,13 +187,6 @@ export default function PageListEdit( { | |
} | ||
}; | ||
|
||
useEffect( () => { | ||
__unstableMarkNextChangeAsNotPersistent(); | ||
if ( blockList ) { | ||
replaceInnerBlocks( clientId, blockList ); | ||
} | ||
}, [ clientId, blockList ] ); | ||
|
||
Comment on lines
-188
to
-194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also be sure that this change doesn't break any of the checking we did in #46223 |
||
const { replaceBlock, selectBlock } = useDispatch( blockEditorStore ); | ||
|
||
const { parentNavBlockClientId } = useSelect( ( select ) => { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what we were missing @draganescu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't use templates we just set the inner blocks. Hmm how to have thought of this :/
@talldan do we need both template lock and the onChange and onInput NOOPs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't seem to work without defining
onChange
/onInput
. Possibly a bug, or possibly intentional. 🤔Template lock does make the fact that the block is not editable visibly noticeable, I wasn't sure if you wanted to keep it for that reason.