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

Close inspector on pattern category select #60004

Merged
merged 4 commits into from
Mar 22, 2024
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
4 changes: 4 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(
showMostUsedBlocks = false,
__experimentalInsertionIndex,
__experimentalFilterValue,
__experimentalOnPatternCategorySelection,
onSelect = noop,
shouldFocusBlock = false,
},
Expand Down Expand Up @@ -48,6 +49,9 @@ function InserterLibrary(
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalInsertionIndex={ __experimentalInsertionIndex }
__experimentalFilterValue={ __experimentalFilterValue }
__experimentalOnPatternCategorySelection={
__experimentalOnPatternCategorySelection
}
shouldFocusBlock={ shouldFocusBlock }
ref={ ref }
/>
Expand Down
9 changes: 8 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useInsertionPoint from './hooks/use-insertion-point';
import InserterTabs from './tabs';
import { store as blockEditorStore } from '../../store';

const NOOP = () => {};
function InserterMenu(
{
rootClientId,
Expand All @@ -45,6 +46,7 @@ function InserterMenu(
showMostUsedBlocks,
__experimentalFilterValue = '',
shouldFocusBlock = true,
__experimentalOnPatternCategorySelection = NOOP,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a new public API. Just a reminder to stop adding prefixed experimental APIs like that. It's preferred to add private APIs going forward. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point! 🤦🏻 I copied #56773 verbatim. Would a linter that says no when we use __experimental help ... probably not 😁

Copy link
Contributor

@ntsekouras ntsekouras May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are is still time to make it private for 6.6, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #62110 but I am a bit unclear how to proceed with privatizing a component that was public but marked experimental - since that will create a public experimental and a private experimental component :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative PR here: #62130. Would love some testing to land this for 6.6.

},
ref
) {
Expand Down Expand Up @@ -110,12 +112,17 @@ function InserterMenu(
[ onToggleInsertionPoint ]
);

const isZoomedOutViewExperimentEnabled =
window?.__experimentalEnableZoomedOutView;
const onClickPatternCategory = useCallback(
( patternCategory, filter ) => {
setSelectedPatternCategory( patternCategory );
setPatternFilter( filter );
if ( isZoomedOutViewExperimentEnabled ) {
__experimentalOnPatternCategorySelection();
}
},
[ setSelectedPatternCategory ]
[ setSelectedPatternCategory, __experimentalOnPatternCategorySelection ]
);

const blocksTab = useMemo(
Expand Down
7 changes: 6 additions & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ function Layout( { initialPost } ) {

const secondarySidebar = () => {
if ( mode === 'visual' && isInserterOpened ) {
return <InserterSidebar />;
return (
<InserterSidebar
closeGeneralSidebar={ closeGeneralSidebar }
isRightSidebarOpen={ sidebarIsOpened }
/>
);
}
if ( mode === 'visual' && isListViewOpened ) {
return <ListViewSidebar />;
Expand Down
11 changes: 9 additions & 2 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import { Notice } from '@wordpress/components';
import { useInstanceId, useViewportMatch } from '@wordpress/compose';
import { store as preferencesStore } from '@wordpress/preferences';
Expand Down Expand Up @@ -174,6 +174,8 @@ export default function Editor( { isLoading, onClick } ) {
'edit-site-editor__loading-progress'
);

const { closeGeneralSidebar } = useDispatch( editSiteStore );

const settings = useSpecificEditorSettings();
const isReady =
! isLoading &&
Expand Down Expand Up @@ -243,7 +245,12 @@ export default function Editor( { isLoading, onClick } ) {
}
secondarySidebar={
isEditMode &&
( ( shouldShowInserter && <InserterSidebar /> ) ||
( ( shouldShowInserter && (
<InserterSidebar
closeGeneralSidebar={ closeGeneralSidebar }
isRightSidebarOpen={ isRightSidebarOpen }
/>
) ) ||
( shouldShowListView && <ListViewSidebar /> ) )
}
sidebar={
Expand Down
8 changes: 7 additions & 1 deletion packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { store as preferencesStore } from '@wordpress/preferences';
import { unlock } from '../../lock-unlock';
import { store as editorStore } from '../../store';

export default function InserterSidebar() {
export default function InserterSidebar( {
closeGeneralSidebar,
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
isRightSidebarOpen,
} ) {
const { insertionPoint, showMostUsedBlocks } = useSelect( ( select ) => {
const { getInsertionPoint } = unlock( select( editorStore ) );
const { get } = select( preferencesStore );
Expand Down Expand Up @@ -65,6 +68,9 @@ export default function InserterSidebar() {
insertionPoint.insertionIndex
}
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
}
ref={ libraryRef }
/>
</div>
Expand Down
Loading