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 Feb 24, 2023
1 parent d517cb4 commit e630cf5
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

1 comment on commit e630cf5

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in e630cf5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4261514258
📝 Reported issues:

Please sign in to comment.