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

Editor: Add the show most used blocks preference to the site editor #57637

Merged
merged 1 commit into from
Jan 8, 2024
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
7 changes: 1 addition & 6 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ function Layout() {
isDistractionFree,
showBlockBreadcrumbs,
showMetaBoxes,
showMostUsedBlocks,
documentLabel,
hasHistory,
} = useSelect( ( select ) => {
Expand Down Expand Up @@ -193,8 +192,6 @@ function Layout() {
showIconLabels: get( 'core', 'showIconLabels' ),
isDistractionFree: get( 'core', 'distractionFree' ),
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
showMostUsedBlocks:
select( editPostStore ).isFeatureActive( 'mostUsedBlocks' ),
// translators: Default label for the Document in the Block Breadcrumb.
documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
hasBlockSelected:
Expand Down Expand Up @@ -263,9 +260,7 @@ function Layout() {

const secondarySidebar = () => {
if ( mode === 'visual' && isInserterOpened ) {
return (
<InserterSidebar showMostUsedBlocks={ showMostUsedBlocks } />
);
return <InserterSidebar />;
}
if ( mode === 'visual' && isListViewOpened ) {
return <ListViewSidebar />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export default function EditPostPreferencesModal() {
<>
<PreferencesModalSection title={ __( 'Inserter' ) }>
<EnableFeature
scope="core"
featureName="mostUsedBlocks"
help={ __(
'Adds a category with the most frequently used blocks in the inserter.'
Expand Down
18 changes: 18 additions & 0 deletions packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,24 @@ export default function EditSitePreferencesModal() {
</>
),
},
{
name: 'blocks',
tabLabel: __( 'Blocks' ),
content: (
<>
<PreferencesModalSection title={ __( 'Inserter' ) }>
<EnableFeature
scope="core"
featureName="mostUsedBlocks"
help={ __(
'Adds a category with the most frequently used blocks in the inserter.'
) }
label={ __( 'Show most used blocks' ) }
/>
</PreferencesModalSection>
</>
),
},
];
if ( ! isModalActive ) {
return null;
Expand Down
7 changes: 5 additions & 2 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import {
} from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { useEffect, useRef } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';
import { store as editorStore } from '../../store';

export default function InserterSidebar( { showMostUsedBlocks } ) {
const { insertionPoint } = useSelect( ( select ) => {
export default function InserterSidebar() {
const { insertionPoint, showMostUsedBlocks } = useSelect( ( select ) => {
const { getInsertionPoint } = unlock( select( editorStore ) );
const { get } = select( preferencesStore );
return {
insertionPoint: getInsertionPoint(),
showMostUsedBlocks: get( 'core', 'mostUsedBlocks' ),
};
}, [] );
const { setIsInserterOpened } = useDispatch( editorStore );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function convertEditorSettings( data ) {
'focusMode',
'inactivePanels',
'keepCaretInsideBlock',
'mostUsedBlocks',
'openPanels',
'showBlockBreadcrumbs',
'showIconLabels',
Expand Down
Loading