Skip to content

Commit

Permalink
Use underlying icon for reusable blocks
Browse files Browse the repository at this point in the history
Use the underlying block type's icon as the icon that displays in an
inserter for a reusable block.
  • Loading branch information
noisysocks committed Jan 12, 2018
1 parent e5761b3 commit d884f71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 6 additions & 1 deletion editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,14 +1120,19 @@ function buildInserterItemFromReusableBlock( enabledBlockTypes, reusableBlock )
return null;
}

const referencedBlockType = getBlockType( reusableBlock.type );
if ( ! referencedBlockType ) {
return null;
}

return {
// Attributes used for insertion
name: 'core/block',
initialAttributes: { ref: reusableBlock.id },

// Attributes shown in the inserter
title: reusableBlock.title,
icon: 'layout',
icon: referencedBlockType.icon,
category: 'reusable-blocks',

// Metadata
Expand Down
15 changes: 10 additions & 5 deletions editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ describe( 'selectors', () => {
save: ( props ) => props.attributes.text,
category: 'common',
title: 'test block',
icon: 'test',
keywords: [ 'testing' ],
useOnce: true,
} );
Expand Down Expand Up @@ -2258,7 +2259,7 @@ describe( 'selectors', () => {
name: 'core/test-block',
initialAttributes: {},
title: 'test block',
icon: 'block-default',
icon: 'test',
category: 'common',
keywords: [ 'testing' ],
isDisabled: false,
Expand Down Expand Up @@ -2295,7 +2296,11 @@ describe( 'selectors', () => {
},
reusableBlocks: {
data: {
123: { id: 123, title: 'My reusable block' },
123: {
id: 123,
title: 'My reusable block',
type: 'core/test-block',
},
},
},
};
Expand All @@ -2305,7 +2310,7 @@ describe( 'selectors', () => {
name: 'core/block',
initialAttributes: { ref: 123 },
title: 'My reusable block',
icon: 'layout',
icon: 'test',
category: 'reusable-blocks',
keywords: [],
isDisabled: false,
Expand Down Expand Up @@ -2337,7 +2342,7 @@ describe( 'selectors', () => {
},
reusableBlocks: {
data: {
123: { id: 123 },
123: { id: 123, type: 'core/test-block' },
},
},
};
Expand Down Expand Up @@ -2391,7 +2396,7 @@ describe( 'selectors', () => {
},
reusableBlocks: {
data: {
123: { id: 123 },
123: { id: 123, type: 'core/test-block' },
},
},
};
Expand Down

0 comments on commit d884f71

Please sign in to comment.