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

Add: Disabled block count in the block manager #17103

Merged
merged 1 commit into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 21 additions & 2 deletions packages/edit-post/src/components/manage-blocks-modal/manager.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* External dependencies
*/
import { filter } from 'lodash';
import { filter, isArray } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { compose, withState } from '@wordpress/compose';
import { TextControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { __, _n, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -23,6 +23,7 @@ function BlockManager( {
categories,
hasBlockSupport,
isMatchingSearchTerm,
numberOfHiddenBlocks,
} ) {
// Filtering occurs here (as opposed to `withSelect`) to avoid wasted
// wasted renders by consequence of `Array#filter` producing a new
Expand All @@ -43,6 +44,20 @@ function BlockManager( {
} ) }
className="edit-post-manage-blocks-modal__search"
/>
{ !! numberOfHiddenBlocks && (
<div className="edit-post-manage-blocks-modal__disabled-blocks-count">
{
sprintf(
_n(
'%1$d block is disabled.',
'%1$d blocks are disabled.',
numberOfHiddenBlocks
),
numberOfHiddenBlocks
)
}
</div>
) }
<div
tabIndex="0"
role="region"
Expand Down Expand Up @@ -77,12 +92,16 @@ export default compose( [
hasBlockSupport,
isMatchingSearchTerm,
} = select( 'core/blocks' );
const { getPreference } = select( 'core/edit-post' );
const hiddenBlockTypes = getPreference( 'hiddenBlockTypes' );
const numberOfHiddenBlocks = isArray( hiddenBlockTypes ) && hiddenBlockTypes.length;

return {
blockTypes: getBlockTypes(),
categories: getCategories(),
hasBlockSupport,
isMatchingSearchTerm,
numberOfHiddenBlocks,
};
} ),
] )( BlockManager );
11 changes: 11 additions & 0 deletions packages/edit-post/src/components/manage-blocks-modal/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@
}
}

.edit-post-manage-blocks-modal__disabled-blocks-count {
border-top: 1px solid $light-gray-500;
margin-left: -$grid-size-xlarge;
margin-right: -$grid-size-xlarge;
padding-top: 0.6rem;
padding-bottom: 0.6rem;
padding-left: $grid-size-xlarge;
padding-right: $grid-size-xlarge;
background-color: $light-gray-200;
}

.edit-post-manage-blocks-modal__category {
margin: 0 0 2rem 0;
}
Expand Down