List view: Try collapsing/expanding all blocks in branch on ctrl/cmd + click - #35734
List view: Try collapsing/expanding all blocks in branch on ctrl/cmd + click#35734walbo wants to merge 7 commits into
Conversation
|
Size Change: +80 B (0%) Total Size: 1.09 MB
ℹ️ View Unchanged
|
| return state; | ||
| case 'expand': { | ||
| castArray( action.clientIds ).forEach( ( clientId ) => { | ||
| nextState[ clientId ] = true; |
There was a problem hiding this comment.
Currently the expanded object is sparsely defined. If a key is not set we assume that a branch is expanded.
If we're only concerned with root level expand/collapse then I'd recommend instead adding two new actions: "expandAll" and "collapseAll".
To keep things sparse, we may need to define a new flag defaultExpanded.
const expanded ( state = { defaultExpanded: true }, action ) => {
switch ( action.type ) {
case 'expand':
return { ...state, ...{ [ action.clientId ]: state.defaultExpanded };
case 'collapse':
return { ...state, ...{ [ action.clientId ]: ! state.defaultExpanded };
case 'expandAll':
return { defaultExpanded: true }; //basically the same as a reset
case 'collapseAll':
return { defaultExpanded: false };
}There was a problem hiding this comment.
Not sure if this is any better, but I had an alternative here to just expect an array in the reducer.
While getting the root level ids from the tree like this:
setExpandedState( {
type,
clientIds: clientIdsTree.map( ( { clientId } ) => clientId ),
} );There was a problem hiding this comment.
Not sure about the expandAll/collapseAll actions that resets the store. They will effect all levels right? I personally prefer that only the level you expand/collapse is effected and everything else stays the same.
Since the branch assumes is expanded when the key doesn’t exists we could remove the key from the store instead of setting false, to keep it sparse.
Yes. Expecting an array would remove the need for castArray, so I agree that the reducer can done in another way 👍
I'll take another look at it later this week.
| return state; | ||
| case 'expand': { | ||
| for ( const clientId of action.clientIds ) { | ||
| delete nextState[ clientId ]; |
There was a problem hiding this comment.
This causes nodes without children to disappear since the visibility of <ListViewBranch /> relies on an isExpanded state.
Changing it to nextState[ clientId ] = true; prevents this.
Also I don't see much usage of the for ... of statement in the clientside javascript. I guess it's because IE didn't support it. I'm not sure whether have to worry about it given this post: https://make.wordpress.org/core/2021/04/22/ie-11-support-phase-out-plan/
|
Browser Shorcut conflict Feature Request:
|
Description
POC to let user collapse/expand all items of a branch in the list view by pressing cmd/ctrl when clicking the toggle button. This will help getting a quick overview of the items and navigate to the correct block.
Related issues: #34759
How has this been tested?
In the navigation editor, post editor and the site editor.
Screenshots
Skjermopptak.2021-10-18.kl.16.32.37.mov
Types of changes
New feature
Checklist:
*.native.jsfiles for terms that need renaming or removal).