Skip to content

Commit

Permalink
Improve the error message and display block types.
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vlasenko committed Oct 26, 2021
1 parent d473fa0 commit 649bade
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions packages/edit-navigation/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { difference, zip } from 'lodash';
import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { store as coreDataStore } from '@wordpress/core-data';
import { warning } from '@wordpress/warning';
import { default as logWarning } from '@wordpress/warning';

/**
* Internal dependencies
Expand Down Expand Up @@ -205,15 +205,24 @@ const batchInsertPlaceholderMenuItems = ( navigationBlock ) => async ( {
const batchUpdateMenuItems = ( navigationBlock, menuId ) => async ( {
registry,
} ) => {
const updatedMenuItems = blocksTreeToAnnotatedList( navigationBlock )
const allMenuItems = blocksTreeToAnnotatedList( navigationBlock );
const unsupportedMenuItems = allMenuItems
.filter( ( { block } ) => ! isBlockSupportedInNav( block ) )
.map( ( { block } ) => block.name );
if ( unsupportedMenuItems.length ) {
logWarning(
sprintf(
// translators: %s: Name of block (i.e. core/legacy-widget)
__(
'The following blocks haven\'t been saved because they are not supported: "%s".'
),
unsupportedMenuItems.join( '", "' )
)
);
}
const updatedMenuItems = allMenuItems
// Filter out unsupported blocks
.filter( ( { block } ) => {
const isBlockSupported = isBlockSupportedInNav( block );
if ( ! isBlockSupported ) {
warning( isBlockSupported );
}
return isBlockSupported;
} )
.filter( ( { block } ) => isBlockSupportedInNav( block ) )
// Transform the blocks into menu items
.map( ( { block, parentBlock, childIndex } ) =>
blockToMenuItem(
Expand Down

0 comments on commit 649bade

Please sign in to comment.