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

hide the most used blocks by default and add an option to enable it #23358

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 13 additions & 9 deletions packages/block-editor/src/components/inserter/block-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function InserterBlockList( {
onHover,
filterValue,
debouncedSpeak,
showMostUsedBlocks,
} ) {
const [ items, categories, collections, onSelectItem ] = useBlockTypesState(
rootClientId,
Expand Down Expand Up @@ -130,15 +131,18 @@ export function InserterBlockList( {
</ChildBlocks>
) }

{ ! hasChildItems && !! suggestedItems.length && ! filterValue && (
<InserterPanel title={ _x( 'Most used', 'blocks' ) }>
<BlockTypesList
items={ suggestedItems }
onSelect={ onSelectItem }
onHover={ onHover }
/>
</InserterPanel>
) }
{ showMostUsedBlocks &&
! hasChildItems &&
!! suggestedItems.length &&
! filterValue && (
<InserterPanel title={ _x( 'Most used', 'blocks' ) }>
<BlockTypesList
items={ suggestedItems }
onSelect={ onSelectItem }
onHover={ onHover }
/>
</InserterPanel>
) }

{ ! hasChildItems &&
map( categories, ( category ) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function InserterLibrary( {
clientId,
isAppender,
showInserterHelpPanel,
showMostUsedBlocks = false,
__experimentalSelectBlockOnInsert: selectBlockOnInsert,
onSelect = noop,
} ) {
Expand All @@ -39,6 +40,7 @@ function InserterLibrary( {
clientId={ clientId }
isAppender={ isAppender }
showInserterHelpPanel={ showInserterHelpPanel }
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalSelectBlockOnInsert={ selectBlockOnInsert }
/>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function InserterMenu( {
__experimentalSelectBlockOnInsert,
onSelect,
showInserterHelpPanel,
showMostUsedBlocks,
} ) {
const [ filterValue, setFilterValue ] = useState( '' );
const [ hoveredItem, setHoveredItem ] = useState( null );
Expand Down Expand Up @@ -86,6 +87,7 @@ function InserterMenu( {
onInsert={ onInsert }
onHover={ onHover }
filterValue={ filterValue }
showMostUsedBlocks={ showMostUsedBlocks }
/>
</div>
{ showInserterHelpPanel && (
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function Layout() {
previousShortcut,
nextShortcut,
hasBlockSelected,
showMostUsedBlocks,
} = useSelect( ( select ) => {
return {
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive(
Expand All @@ -85,6 +86,9 @@ function Layout() {
isFullscreenActive: select( 'core/edit-post' ).isFeatureActive(
'fullscreenMode'
),
showMostUsedBlocks: select( 'core/edit-post' ).isFeatureActive(
'mostUsedBlocks'
),
mode: select( 'core/edit-post' ).getEditorMode(),
isRichEditingEnabled: select( 'core/editor' ).getEditorSettings()
.richEditingEnabled,
Expand Down Expand Up @@ -176,6 +180,9 @@ function Layout() {
</div>
<div className="edit-post-layout__inserter-panel-content">
<Library
showMostUsedBlocks={
showMostUsedBlocks
}
showInserterHelpPanel
onSelect={ () => {
if ( isMobileViewport ) {
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-post/src/components/options-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
EnablePluginDocumentSettingPanelOption,
EnablePublishSidebarOption,
EnablePanelOption,
EnableFeature,
} from './options';
import MetaBoxesSection from './meta-boxes-section';

Expand All @@ -47,6 +48,12 @@ export function OptionsModal( { isModalActive, isViewable, closeModal } ) {
<EnablePublishSidebarOption
label={ __( 'Pre-publish checks' ) }
/>
<EnableFeature
featureName="mostUsedBlocks"
label={ __(
'Enable the Most Used Blocks category in the block library'
) }
/>
</Section>
<Section title={ __( 'Document panels' ) }>
<EnablePluginDocumentSettingPanelOption.Slot />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import BaseOption from './base';

export default compose(
withSelect( ( select, { featureName } ) => {
const { isFeatureActive } = select( 'core/edit-post' );
return {
isChecked: isFeatureActive( featureName ),
};
} ),
withDispatch( ( dispatch, { featureName } ) => ( {
onChange: () =>
dispatch( 'core/edit-post' ).toggleFeature( featureName ),
} ) )
)( BaseOption );
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as EnableCustomFieldsOption } from './enable-custom-fields';
export { default as EnablePanelOption } from './enable-panel';
export { default as EnablePluginDocumentSettingPanelOption } from './enable-plugin-document-setting-panel';
export { default as EnablePublishSidebarOption } from './enable-publish-sidebar';
export { default as EnableFeature } from './enable-feature';