Skip to content

Commit

Permalink
Unfold also shared blocks
Browse files Browse the repository at this point in the history
A shared block can contain nested blocks, so we need to unfold them.
  • Loading branch information
oandregal committed Jul 26, 2018
1 parent 2bac14c commit 72b305b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
14 changes: 10 additions & 4 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,16 @@ export const getBlocks = createSelector(
* @return {Array} ids of referenced and inner blocks.
*/
const unfoldClientIds = ( state, block ) => {
const getClientIdsFromSharedBlock = ( globalState, sharedBlock ) =>
sharedBlock.name === 'core/block' ?
[ get( getSharedBlock( globalState, sharedBlock.attributes.ref ), [ 'clientId' ], null ) ] :
[ null ];
const getClientIdsFromSharedBlock = ( globalState, sharedBlock ) => {
if ( sharedBlock.name === 'core/block' ) {
const clientId = get( getSharedBlock( globalState, sharedBlock.attributes.ref ), [ 'clientId' ], null );
return [
clientId,
...unfoldClientIds( globalState, ...getBlocksByClientId( globalState, clientId ) ),
];
}
return [ null ];
};
const getClientIdsFromInnerBlock = ( globalState ) => ( innerBlock ) => [
innerBlock.clientId,
...unfoldClientIds( globalState, innerBlock ),
Expand Down
17 changes: 16 additions & 1 deletion editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1749,9 +1749,14 @@ describe( 'selectors', () => {
'uuid-16': { clientId: 'uuid-16', name: 'core/quote', attributes: {} },
'uuid-18': { clientId: 'uuid-18', name: 'core/block', attributes: { ref: 5 } },
'uuid-20': { clientId: 'uuid-20', name: 'core/gallery', attributes: {} },
'uuid-22': { clientId: 'uuid-22', name: 'core/block', attributes: { ref: 7 } },
'uuid-24': { clientId: 'uuid-24', name: 'core/columns', attributes: { } },
'uuid-26': { clientId: 'uuid-26', name: 'core/column', attributes: { } },
'uuid-28': { clientId: 'uuid-28', name: 'core/column', attributes: { } },
'uuid-30': { clientId: 'uuid-30', name: 'core/paragraph', attributes: { } },
},
blockOrder: {
'': [ 'uuid-6', 'uuid-8', 'uuid-10' ],
'': [ 'uuid-6', 'uuid-8', 'uuid-10', 'uuid-22' ],
'uuid-2': [ ],
'uuid-4': [ ],
'uuid-6': [ ],
Expand All @@ -1762,6 +1767,10 @@ describe( 'selectors', () => {
'uuid-16': [ ],
'uuid-18': [ ],
'uuid-20': [ ],
'uuid-22': [ ],
'uuid-24': [ 'uuid-26', 'uuid-28' ],
'uuid-26': [ ],
'uuid-28': [ 'uuid-30' ],
},
edits: {},
},
Expand All @@ -1771,6 +1780,7 @@ describe( 'selectors', () => {
1: { clientId: 'uuid-2', title: 'SharedImage' },
3: { clientId: 'uuid-4', title: 'SharedParagraph' },
5: { clientId: 'uuid-20', title: 'SharedGallery' },
7: { clientId: 'uuid-24', title: 'SharedColumns' },
},
},
};
Expand All @@ -1784,6 +1794,11 @@ describe( 'selectors', () => {
'uuid-14',
'uuid-18',
'uuid-20',
'uuid-22',
'uuid-24',
'uuid-26',
'uuid-28',
'uuid-30',
] );
} );
} );
Expand Down

0 comments on commit 72b305b

Please sign in to comment.