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

[Inserter]: Remove Reusable tab and move the contents inside Blocks tab #45847

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { map, groupBy, orderBy } from 'lodash';
import { __, _x } from '@wordpress/i18n';
import { useMemo, useEffect } from '@wordpress/element';
import { pipe, useAsyncList } from '@wordpress/compose';
import { addQueryArgs } from '@wordpress/url';
import { Button } from '@wordpress/components';

/**
* Internal dependencies
Expand Down Expand Up @@ -54,10 +56,7 @@ export function BlockTypesTab( {

const itemsPerCategory = useMemo( () => {
return pipe(
( itemList ) =>
itemList.filter(
( item ) => item.category && item.category !== 'reusable'
),
( itemList ) => itemList.filter( ( item ) => item.category ),
( itemList ) => groupBy( itemList, 'category' )
)( items );
}, [ items ] );
Expand Down Expand Up @@ -129,6 +128,19 @@ export function BlockTypesTab( {
onHover={ onHover }
label={ category.title }
/>
{ category.slug === 'reusable' && (
<div className="block-editor-inserter__manage-reusable-blocks-container">
<Button
className="block-editor-inserter__manage-reusable-blocks"
variant="secondary"
href={ addQueryArgs( 'edit.php', {
post_type: 'wp_block',
} ) }
>
{ __( 'Manage Reusable blocks' ) }
</Button>
</div>
) }
</InserterPanel>
);
} ) }
Expand Down
32 changes: 7 additions & 25 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import BlockTypesTab from './block-types-tab';
import BlockPatternsTabs, {
BlockPatternsCategoryDialog,
} from './block-patterns-tab';
import ReusableBlocksTab from './reusable-blocks-tab';
import InserterSearchResults from './search-results';
import useInsertionPoint from './hooks/use-insertion-point';
import InserterTabs from './tabs';
Expand Down Expand Up @@ -64,18 +63,14 @@ function InserterMenu(
insertionIndex: __experimentalInsertionIndex,
shouldFocusBlock,
} );
const { showPatterns, hasReusableBlocks } = useSelect(
const showPatterns = useSelect(
( select ) => {
const { __experimentalGetAllowedPatterns, getSettings } =
const { __experimentalGetAllowedPatterns } =
select( blockEditorStore );

return {
showPatterns: !! __experimentalGetAllowedPatterns(
destinationRootClientId
).length,
hasReusableBlocks:
!! getSettings().__experimentalReusableBlocks?.length,
};
return !! __experimentalGetAllowedPatterns(
destinationRootClientId
).length;
},
[ destinationRootClientId ]
);
Expand Down Expand Up @@ -159,27 +154,15 @@ function InserterMenu(
]
);

const reusableBlocksTab = useMemo(
() => (
<ReusableBlocksTab
rootClientId={ destinationRootClientId }
onInsert={ onInsert }
onHover={ onHover }
/>
),
[ destinationRootClientId, onInsert, onHover ]
);

const getCurrentTab = useCallback(
( tab ) => {
if ( tab.name === 'blocks' ) {
return blocksTab;
} else if ( tab.name === 'patterns' ) {
return patternsTab;
}
return reusableBlocksTab;
},
[ blocksTab, patternsTab, reusableBlocksTab ]
[ blocksTab, patternsTab ]
);

const searchRef = useRef();
Expand All @@ -191,7 +174,7 @@ function InserterMenu(

const showPatternPanel =
selectedTab === 'patterns' && ! filterValue && selectedPatternCategory;
const showAsTabs = ! filterValue && ( showPatterns || hasReusableBlocks );
const showAsTabs = ! filterValue && showPatterns;

return (
<div className="block-editor-inserter__menu">
Expand Down Expand Up @@ -231,7 +214,6 @@ function InserterMenu(
{ showAsTabs && (
<InserterTabs
showPatterns={ showPatterns }
showReusableBlocks={ hasReusableBlocks }
prioritizePatterns={ prioritizePatterns }
onSelect={ setSelectedTab }
>
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ $block-inserter-tabs-height: 44px;
border: none;
}

.block-editor-inserter__reusable-blocks-panel {
position: relative;
text-align: right;
}

.block-editor-inserter__manage-reusable-blocks-container {
margin: auto $grid-unit-20 $grid-unit-20;
}
Expand Down
19 changes: 1 addition & 18 deletions packages/block-editor/src/components/inserter/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ const patternsTab = {
/* translators: Patterns tab title in the block inserter. */
title: __( 'Patterns' ),
};
const reusableBlocksTab = {
name: 'reusable',
/* translators: Reusable blocks tab title in the block inserter. */
title: __( 'Reusable' ),
};

function InserterTabs( {
children,
showPatterns = false,
showReusableBlocks = false,
onSelect,
prioritizePatterns,
} ) {
Expand All @@ -37,19 +31,8 @@ function InserterTabs( {
if ( ! prioritizePatterns && showPatterns ) {
tempTabs.push( patternsTab );
}
if ( showReusableBlocks ) {
tempTabs.push( reusableBlocksTab );
}

return tempTabs;
}, [
prioritizePatterns,
blocksTab,
showPatterns,
patternsTab,
showReusableBlocks,
reusableBlocksTab,
] );
}, [ prioritizePatterns, blocksTab, showPatterns, patternsTab ] );

return (
<TabPanel
Expand Down
17 changes: 10 additions & 7 deletions packages/block-editor/src/components/inserter/tabs.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@ import {
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { SegmentedControl } from '@wordpress/components';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as blockEditorStore } from '../../store';
import BlockTypesTab from './block-types-tab';
import ReusableBlocksTab from './reusable-blocks-tab';
import styles from './style.scss';

const TAB_ANIMATION_DURATION = 250;

function InserterTabs( {
listProps,
onSelect,
rootClientId,
showReusableBlocks,
tabIndex,
} ) {
function InserterTabs( { listProps, onSelect, rootClientId, tabIndex } ) {
const tabAnimation = useRef( new Animated.Value( 0 ) ).current;
const lastScrollEvents = useRef( [] ).current;
const [ wrapperWidth, setWrapperWidth ] = useState( 0 );

const showReusableBlocks = useSelect(
( select ) =>
!! select( blockEditorStore ).getSettings()
.__experimentalReusableBlocks?.length,
[ rootClientId ]
);

function onScroll( event ) {
lastScrollEvents[ tabIndex ] = event.nativeEvent;
listProps.onScroll( event );
Expand Down