Skip to content

Commit

Permalink
Widget Importer: Don't render controls when there's nothing to import (
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored and ntsekouras committed Feb 27, 2023
1 parent 19af130 commit eec1d09
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions packages/block-library/src/template-part/edit/import-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ import { store as noticesStore } from '@wordpress/notices';
import { useCreateTemplatePartFromBlocks } from './utils/hooks';
import { transformWidgetToBlock } from './utils/transformers';

const SIDEBARS_QUERY = {
per_page: -1,
_fields: 'id,name,description,status,widgets',
};

export function TemplatePartImportControls( { area, setAttributes } ) {
const [ selectedSidebar, setSelectedSidebar ] = useState( '' );
const [ isBusy, setIsBusy ] = useState( false );

const registry = useRegistry();
const sidebars = useSelect( ( select ) => {
return select( coreStore ).getSidebars( {
per_page: -1,
_fields: 'id,name,description,status,widgets',
} );
const { sidebars, hasResolved } = useSelect( ( select ) => {
const { getSidebars, hasFinishedResolution } = select( coreStore );

return {
sidebars: getSidebars( SIDEBARS_QUERY ),
hasResolved: hasFinishedResolution( 'getSidebars', [
SIDEBARS_QUERY,
] ),
};
}, [] );
const { createErrorNotice } = useDispatch( noticesStore );

Expand Down Expand Up @@ -67,6 +76,16 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
];
}, [ sidebars ] );

// Render an empty node while data is loading to avoid SlotFill re-positioning bug.
// See: https://github.com/WordPress/gutenberg/issues/15641.
if ( ! hasResolved ) {
return <Spacer marginBottom="0" />;
}

if ( hasResolved && ! options.length ) {
return null;
}

async function createFromWidgets( event ) {
event.preventDefault();

Expand Down

0 comments on commit eec1d09

Please sign in to comment.