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

Try making page list a controlled block #46416

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Changes from all commits
Commits
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
15 changes: 5 additions & 10 deletions packages/block-library/src/page-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand All @@ -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 =
Expand Down Expand Up @@ -133,6 +132,9 @@ export default function PageListEdit( {
renderAppender: false,
__unstableDisableDropZone: true,
templateLock: 'all',
onInput: NOOP,
onChange: NOOP,
value: blockList,
Copy link
Contributor

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

Copy link
Contributor

@draganescu draganescu Dec 12, 2022

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@talldan do we need both template lock and the onChange and onInput NOOPs?

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.

} );

const getBlockContent = () => {
Expand Down Expand Up @@ -185,13 +187,6 @@ export default function PageListEdit( {
}
};

useEffect( () => {
__unstableMarkNextChangeAsNotPersistent();
if ( blockList ) {
replaceInnerBlocks( clientId, blockList );
}
}, [ clientId, blockList ] );

Comment on lines -188 to -194
Copy link
Contributor

Choose a reason for hiding this comment

The 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 ) => {
Expand Down