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

List View: Add a rootClientId prop #49475

Merged
merged 7 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
* @param {?boolean} props.isExpanded Flag to determine whether nested levels are expanded by default. Defaults to `false`.
* @param {?boolean} props.showAppender Flag to show or hide the block appender. Defaults to `false`.
* @param {?ComponentType} props.blockSettingsMenu Optional more menu substitution. Defaults to the standard `BlockSettingsDropdown` component.
* @param {string} props.rootClientId The client id of the root block from which we determine the blocks to show in the list.
* @param {Ref} ref Forwarded ref
*/
function ListViewComponent(
Expand All @@ -71,11 +72,12 @@ function ListViewComponent(
isExpanded = false,
showAppender = false,
blockSettingsMenu: BlockSettingsMenu = BlockSettingsDropdown,
rootClientId = null,
scruffian marked this conversation as resolved.
Show resolved Hide resolved
},
ref
) {
const { clientIdsTree, draggedClientIds, selectedClientIds } =
useListViewClientIds( blocks );
useListViewClientIds( blocks, rootClientId );

const { visibleBlockCount, shouldShowInnerBlocks } = useSelect(
( select ) => {
Expand Down Expand Up @@ -219,6 +221,7 @@ function ListViewComponent(
<ListViewContext.Provider value={ contextValue }>
<ListViewBranch
blocks={ clientIdsTree }
parentId={ rootClientId }
selectBlock={ selectEditorBlock }
showBlockMovers={ showBlockMovers }
fixedListWindow={ fixedListWindow }
Expand All @@ -241,6 +244,7 @@ export default forwardRef( ( props, ref ) => {
{ ...props }
showAppender={ false }
blockSettingsMenu={ BlockSettingsDropdown }
rootClientId={ null }
/>
);
} );
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSelect } from '@wordpress/data';
*/
import { store as blockEditorStore } from '../../store';

export default function useListViewClientIds( blocks ) {
export default function useListViewClientIds( blocks, rootClientId ) {
return useSelect(
( select ) => {
const {
Expand All @@ -21,9 +21,11 @@ export default function useListViewClientIds( blocks ) {
return {
selectedClientIds: getSelectedBlockClientIds(),
draggedClientIds: getDraggedBlockClientIds(),
clientIdsTree: blocks ? blocks : __unstableGetClientIdsTree(),
clientIdsTree: blocks
? blocks
: __unstableGetClientIdsTree( rootClientId ),
};
},
[ blocks ]
[ blocks, rootClientId ]
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the changes in this file must be reverted before merge

Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/**
* WordPress dependencies
*/
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import {
privateApis as blockEditorPrivateApis,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { Button } from '@wordpress/components';
import {
useFocusOnMount,
useFocusReturn,
useInstanceId,
useMergeRefs,
} from '@wordpress/compose';
import { useDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { closeSmall } from '@wordpress/icons';
import { ESCAPE } from '@wordpress/keycodes';
Expand All @@ -35,6 +38,10 @@ export default function ListViewSidebar() {
const instanceId = useInstanceId( ListViewSidebar );
const labelId = `edit-site-editor__list-view-panel-label-${ instanceId }`;
const { PrivateListView } = unlock( blockEditorPrivateApis );
const clientIdsTree = useSelect( ( select ) => {
const { __unstableGetClientIdsTree } = select( blockEditorStore );
return __unstableGetClientIdsTree();
} );
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
Expand All @@ -60,7 +67,11 @@ export default function ListViewSidebar() {
focusOnMountRef,
] ) }
>
<PrivateListView />
<PrivateListView
rootClientId={
clientIdsTree[ 0 ].innerBlocks[ 0 ].clientId
}
/>
</div>
</div>
);
Expand Down