Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation Editor: show a warning when trying to save unsupported blocks #35993

Merged
merged 4 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/edit-navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/url": "file:../url",
"@wordpress/warning": "file:../warning",
"classnames": "^2.3.1",
"lodash": "^4.17.21",
"rememo": "^3.0.0",
Expand Down
18 changes: 17 additions & 1 deletion packages/edit-navigation/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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 { default as logWarning } from '@wordpress/warning';

/**
* Internal dependencies
Expand Down Expand Up @@ -204,7 +205,22 @@ 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function exists for development purposes, to show warnings in the development mode related to code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo Ah, I see. It's not going to work in the browser because process.env.NODE_ENV won't be defined.
Should we simply use console.warn instead?
Do you have a better alternative?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, console.warn should work. We might have usage of it also in other places.

Copy link
Contributor Author

@anton-vlasenko anton-vlasenko Oct 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo Fixed in 70ed0ed
Could you please approve this PR if you think it's OK?

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 } ) => isBlockSupportedInNav( block ) )
// Transform the blocks into menu items
Expand Down