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

[Block Library - Query Loop]: Add block settings menu item to reset(remove the Innerblocks) #37667

Closed
wants to merge 3 commits into from
Closed
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
37 changes: 35 additions & 2 deletions packages/block-library/src/query/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
store as blockEditorStore,
useInnerBlocksProps,
__experimentalBlockPatternSetup as BlockPatternSetup,
BlockSettingsMenuControls,
} from '@wordpress/block-editor';
import { SelectControl } from '@wordpress/components';
import { SelectControl, MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -27,7 +28,35 @@ import { DEFAULTS_POSTS_PER_PAGE } from '../constants';
import { getFirstQueryClientIdFromBlocks } from '../utils';

const TEMPLATE = [ [ 'core/post-template' ] ];
export function QueryContent( { attributes, setAttributes } ) {

function ResetQueryLoopMenuItem( { clientId, isSelected } ) {
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
if ( ! isSelected ) {
return null;
}
return (
<BlockSettingsMenuControls>
{ ( { onClose } ) => (
<MenuItem
onClick={ () => {
replaceInnerBlocks( clientId, [] );
onClose();
} }
info={ __( 'Remove all innerblocks and start fresh' ) }
>
{ __( 'Reset Query Loop' ) }
</MenuItem>
) }
</BlockSettingsMenuControls>
);
}

export function QueryContent( {
attributes,
setAttributes,
clientId,
isSelected,
} ) {
const {
queryId,
query,
Expand Down Expand Up @@ -104,6 +133,10 @@ export function QueryContent( { attributes, setAttributes } ) {
setDisplayLayout={ updateDisplayLayout }
/>
</BlockControls>
<ResetQueryLoopMenuItem
clientId={ clientId }
isSelected={ isSelected }
/>
<InspectorControls __experimentalGroup="advanced">
<SelectControl
label={ __( 'HTML element' ) }
Expand Down