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]: Pass filter value when clicking Browse All #34912

Merged
merged 2 commits into from
Sep 22, 2021
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
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function InserterLibrary( {
showInserterHelpPanel,
showMostUsedBlocks = false,
__experimentalInsertionIndex,
__experimentalFilterValue,
onSelect = noop,
shouldFocusBlock = false,
} ) {
Expand All @@ -44,6 +45,7 @@ function InserterLibrary( {
showInserterHelpPanel={ showInserterHelpPanel }
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalInsertionIndex={ __experimentalInsertionIndex }
__experimentalFilterValue={ __experimentalFilterValue }
shouldFocusBlock={ shouldFocusBlock }
/>
);
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ function InserterMenu( {
onSelect,
showInserterHelpPanel,
showMostUsedBlocks,
__experimentalFilterValue = '',
shouldFocusBlock = true,
} ) {
const [ filterValue, setFilterValue ] = useState( '' );
const [ filterValue, setFilterValue ] = useState(
__experimentalFilterValue
);
const [ hoveredItem, setHoveredItem ] = useState( null );
const [ selectedPatternCategory, setSelectedPatternCategory ] = useState(
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function QuickInserter( {
// When clicking Browse All select the appropriate block so as
// the insertion point can work as expected
const onBrowseAll = () => {
setInserterIsOpened( { rootClientId, insertionIndex } );
setInserterIsOpened( { rootClientId, insertionIndex, filterValue } );
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
searchForBlock,
setBrowserViewport,
showBlockToolbar,
pressKeyWithModifier,
} from '@wordpress/e2e-test-utils';

/** @typedef {import('puppeteer').ElementHandle} ElementHandle */
Expand Down Expand Up @@ -354,6 +355,28 @@ describe( 'Inserting blocks', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'passes the search value in the main inserter when clicking `Browse all`', async () => {
const INSERTER_SEARCH_SELECTOR =
'.block-editor-inserter__search input,.block-editor-inserter__search-input,input.block-editor-inserter__search';
await insertBlock( 'Group' );
await insertBlock( 'Paragraph' );
await page.keyboard.type( 'Text' );
await page.click( '[data-type="core/group"] [aria-label="Add block"]' );
await page.waitForSelector( INSERTER_SEARCH_SELECTOR );
await page.focus( INSERTER_SEARCH_SELECTOR );
await pressKeyWithModifier( 'primary', 'a' );
const searchTerm = 'Heading';
await page.keyboard.type( searchTerm );
const browseAll = await page.waitForXPath(
'//button[text()="Browse all"]'
);
await browseAll.click();
const availableBlocks = await page.$$(
'.block-editor-block-types-list__list-item'
);
expect( availableBlocks ).toHaveLength( 1 );
} );

// Check for regression of https://github.com/WordPress/gutenberg/issues/27586
it( 'closes the main inserter after inserting a single-use block, like the More block', async () => {
await insertBlock( 'More' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function InserterSidebar() {
__experimentalInsertionIndex={
insertionPoint.insertionIndex
}
__experimentalFilterValue={ insertionPoint.filterValue }
/>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,15 @@ export function isInserterOpened( state ) {
*
* @param {Object} state Global application state.
*
* @return {Object} The root client ID and index to insert at.
* @return {Object} The root client ID, index to insert at and starting filter value.
*/
export function __experimentalGetInsertionPoint( state ) {
const { rootClientId, insertionIndex } = state.blockInserterPanel;
return { rootClientId, insertionIndex };
const {
rootClientId,
insertionIndex,
filterValue,
} = state.blockInserterPanel;
return { rootClientId, insertionIndex, filterValue };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function InserterSidebar() {
__experimentalInsertionIndex={
insertionPoint.insertionIndex
}
__experimentalFilterValue={ insertionPoint.filterValue }
/>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,15 @@ export function isInserterOpened( state ) {
*
* @param {Object} state Global application state.
*
* @return {Object} The root client ID and index to insert at.
* @return {Object} The root client ID, index to insert at and starting filter value.
*/
export function __experimentalGetInsertionPoint( state ) {
const { rootClientId, insertionIndex } = state.blockInserterPanel;
return { rootClientId, insertionIndex };
const {
rootClientId,
insertionIndex,
filterValue,
} = state.blockInserterPanel;
return { rootClientId, insertionIndex, filterValue };
}

/**
Expand Down