Skip to content

Commit

Permalink
hide nested levels from list view
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 27, 2022
1 parent 1e2aeda commit d50342a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function ListViewBranch( props ) {
listPosition = 0,
fixedListWindow,
isExpanded,
shouldShowInnerBlocks = true,
} = props;

const { expandedState, draggedClientIds } = useListViewContext();
Expand Down Expand Up @@ -124,9 +125,10 @@ function ListViewBranch( props ) {
: `${ position }`;
const hasNestedBlocks = !! innerBlocks?.length;

const shouldExpand = hasNestedBlocks
? expandedState[ clientId ] ?? isExpanded
: undefined;
const shouldExpand =
hasNestedBlocks && shouldShowInnerBlocks
? expandedState[ clientId ] ?? isExpanded
: undefined;

const isDragged = !! draggedClientIds?.includes( clientId );

Expand Down
12 changes: 8 additions & 4 deletions packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ function ListView(
selectedClientIds,
} = useListViewClientIds( blocks );

const { visibleBlockCount } = useSelect(
const { visibleBlockCount, shouldShowInnerBlocks } = useSelect(
( select ) => {
const { getGlobalBlockCount, getClientIdsOfDescendants } = select(
blockEditorStore
);
const {
getGlobalBlockCount,
getClientIdsOfDescendants,
__unstableGetEditorMode,
} = select( blockEditorStore );
const draggedBlockCount =
draggedClientIds?.length > 0
? getClientIdsOfDescendants( draggedClientIds ).length + 1
: 0;
return {
visibleBlockCount: getGlobalBlockCount() - draggedBlockCount,
shouldShowInnerBlocks: __unstableGetEditorMode() !== 'zoom-out',
};
},
[ draggedClientIds ]
Expand Down Expand Up @@ -197,6 +200,7 @@ function ListView(
fixedListWindow={ fixedListWindow }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
shouldShowInnerBlocks={ shouldShowInnerBlocks }
/>
</ListViewContext.Provider>
</TreeGrid>
Expand Down

0 comments on commit d50342a

Please sign in to comment.