Skip to content

Commit

Permalink
Remove patterns from the Quick Inserter to prevent misuse in block-sp…
Browse files Browse the repository at this point in the history
…ecific contexts (WordPress#67738)

* Remove patterns from quick inserter

* Remove commented code

* Removed prioritizePatterns instances where possible

----

Co-authored-by: rohitmathur-7 <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: richtabor <[email protected]>
  • Loading branch information
4 people authored and yogeshbhutkar committed Dec 18, 2024
1 parent e6cb5bd commit b1e5753
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
13 changes: 0 additions & 13 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const defaultRenderToggle = ( {
blockTitle,
hasSingleBlockType,
toggleProps = {},
prioritizePatterns,
} ) => {
const {
as: Wrapper = Button,
Expand All @@ -45,8 +44,6 @@ const defaultRenderToggle = ( {
_x( 'Add %s', 'directly add the only allowed block' ),
blockTitle
);
} else if ( ! label && prioritizePatterns ) {
label = __( 'Add pattern' );
} else if ( ! label ) {
label = _x( 'Add block', 'Generic label for block inserter button' );
}
Expand Down Expand Up @@ -113,7 +110,6 @@ class Inserter extends Component {
toggleProps,
hasItems,
renderToggle = defaultRenderToggle,
prioritizePatterns,
} = this.props;

return renderToggle( {
Expand All @@ -124,7 +120,6 @@ class Inserter extends Component {
hasSingleBlockType,
directInsertBlock,
toggleProps,
prioritizePatterns,
} );
}

Expand All @@ -147,7 +142,6 @@ class Inserter extends Component {
// This prop is experimental to give some time for the quick inserter to mature
// Feel free to make them stable after a few releases.
__experimentalIsQuick: isQuick,
prioritizePatterns,
onSelectOrClose,
selectBlockOnInsert,
} = this.props;
Expand All @@ -171,7 +165,6 @@ class Inserter extends Component {
rootClientId={ rootClientId }
clientId={ clientId }
isAppender={ isAppender }
prioritizePatterns={ prioritizePatterns }
selectBlockOnInsert={ selectBlockOnInsert }
/>
);
Expand Down Expand Up @@ -230,7 +223,6 @@ export default compose( [
hasInserterItems,
getAllowedBlocks,
getDirectInsertBlock,
getSettings,
} = select( blockEditorStore );

const { getBlockVariations } = select( blocksStore );
Expand All @@ -243,8 +235,6 @@ export default compose( [
const directInsertBlock =
shouldDirectInsert && getDirectInsertBlock( rootClientId );

const settings = getSettings();

const hasSingleBlockType =
allowedBlocks?.length === 1 &&
getBlockVariations( allowedBlocks[ 0 ].name, 'inserter' )
Expand All @@ -262,9 +252,6 @@ export default compose( [
allowedBlockType,
directInsertBlock,
rootClientId,
prioritizePatterns:
settings.__experimentalPreferPatternsOnRoot &&
! rootClientId,
};
}
),
Expand Down
27 changes: 2 additions & 25 deletions packages/block-editor/src/components/inserter/quick-inserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ import { useSelect } from '@wordpress/data';
*/
import InserterSearchResults from './search-results';
import useInsertionPoint from './hooks/use-insertion-point';
import usePatternsState from './hooks/use-patterns-state';
import useBlockTypesState from './hooks/use-block-types-state';
import { store as blockEditorStore } from '../../store';

const SEARCH_THRESHOLD = 6;
const SHOWN_BLOCK_TYPES = 6;
const SHOWN_BLOCK_PATTERNS = 2;
const SHOWN_BLOCK_PATTERNS_WITH_PRIORITIZATION = 4;

export default function QuickInserter( {
onSelect,
rootClientId,
clientId,
isAppender,
prioritizePatterns,
selectBlockOnInsert,
hasSearch = true,
} ) {
Expand All @@ -47,12 +43,6 @@ export default function QuickInserter( {
onInsertBlocks,
true
);
const [ patterns ] = usePatternsState(
onInsertBlocks,
destinationRootClientId,
undefined,
true
);

const { setInserterIsOpened, insertionIndex } = useSelect(
( select ) => {
Expand All @@ -70,12 +60,7 @@ export default function QuickInserter( {
[ clientId ]
);

const showPatterns =
patterns.length && ( !! filterValue || prioritizePatterns );
const showSearch =
hasSearch &&
( ( showPatterns && patterns.length > SEARCH_THRESHOLD ) ||
blockTypes.length > SEARCH_THRESHOLD );
const showSearch = hasSearch && blockTypes.length > SEARCH_THRESHOLD;

useEffect( () => {
if ( setInserterIsOpened ) {
Expand All @@ -94,13 +79,6 @@ export default function QuickInserter( {
} );
};

let maxBlockPatterns = 0;
if ( showPatterns ) {
maxBlockPatterns = prioritizePatterns
? SHOWN_BLOCK_PATTERNS_WITH_PRIORITIZATION
: SHOWN_BLOCK_PATTERNS;
}

return (
<div
className={ clsx( 'block-editor-inserter__quick-inserter', {
Expand Down Expand Up @@ -128,10 +106,9 @@ export default function QuickInserter( {
rootClientId={ rootClientId }
clientId={ clientId }
isAppender={ isAppender }
maxBlockPatterns={ maxBlockPatterns }
maxBlockPatterns={ 0 }
maxBlockTypes={ SHOWN_BLOCK_TYPES }
isDraggable={ false }
prioritizePatterns={ prioritizePatterns }
selectBlockOnInsert={ selectBlockOnInsert }
isQuick
/>
Expand Down

0 comments on commit b1e5753

Please sign in to comment.