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

Fix: Show add pattern label when patterns are being prioritised. #40598

Merged
merged 1 commit into from
Apr 26, 2022
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
20 changes: 20 additions & 0 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const defaultRenderToggle = ( {
blockTitle,
hasSingleBlockType,
toggleProps = {},
prioritizePatterns,
} ) => {
let label;
if ( hasSingleBlockType ) {
Expand All @@ -38,6 +39,8 @@ const defaultRenderToggle = ( {
_x( 'Add %s', 'directly add the only allowed block' ),
blockTitle
);
} else if ( prioritizePatterns ) {
label = __( 'Add pattern' );
} else {
label = _x( 'Add block', 'Generic label for block inserter button' );
}
Expand Down Expand Up @@ -106,6 +109,7 @@ class Inserter extends Component {
toggleProps,
hasItems,
renderToggle = defaultRenderToggle,
prioritizePatterns,
} = this.props;

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

Expand All @@ -138,6 +143,7 @@ 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,
} = this.props;

if ( isQuick ) {
Expand All @@ -149,6 +155,7 @@ class Inserter extends Component {
rootClientId={ rootClientId }
clientId={ clientId }
isAppender={ isAppender }
prioritizePatterns={ prioritizePatterns }
/>
);
}
Expand Down Expand Up @@ -206,7 +213,11 @@ export default compose( [
hasInserterItems,
__experimentalGetAllowedBlocks,
__experimentalGetDirectInsertBlock,
getBlockIndex,
getBlockCount,
getSettings,
} = select( blockEditorStore );

const { getBlockVariations } = select( blocksStore );

rootClientId =
Expand All @@ -218,6 +229,10 @@ export default compose( [
rootClientId
);

const index = getBlockIndex( clientId );
const blockCount = getBlockCount();
const settings = getSettings();

const hasSingleBlockType =
size( allowedBlocks ) === 1 &&
size(
Expand All @@ -236,6 +251,11 @@ export default compose( [
allowedBlockType,
directInsertBlock,
rootClientId,
prioritizePatterns:
settings.__experimentalPreferPatternsOnRoot &&
! rootClientId &&
index > 0 &&
( index < blockCount || blockCount === 0 ),
};
} ),
withDispatch( ( dispatch, ownProps, { select } ) => {
Expand Down
14 changes: 3 additions & 11 deletions packages/block-editor/src/components/inserter/quick-inserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function QuickInserter( {
rootClientId,
clientId,
isAppender,
prioritizePatterns,
} ) {
const [ filterValue, setFilterValue ] = useState( '' );
const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {
Expand All @@ -48,11 +49,7 @@ export default function QuickInserter( {
destinationRootClientId
);

const {
setInserterIsOpened,
insertionIndex,
prioritizePatterns,
} = useSelect(
const { setInserterIsOpened, insertionIndex } = useSelect(
( select ) => {
const { getSettings, getBlockIndex, getBlockCount } = select(
blockEditorStore
Expand All @@ -63,15 +60,10 @@ export default function QuickInserter( {

return {
setInserterIsOpened: settings.__experimentalSetIsInserterOpened,
prioritizePatterns:
settings.__experimentalPreferPatternsOnRoot &&
! rootClientId &&
index > 0 &&
( index < blockCount || blockCount === 0 ),
insertionIndex: index === -1 ? blockCount : index,
jorgefilipecosta marked this conversation as resolved.
Show resolved Hide resolved
};
},
[ clientId, rootClientId ]
[ clientId ]
);

const showPatterns =
Expand Down