Skip to content

Commit

Permalink
Include server sources in bindings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Nov 6, 2024
1 parent e27aec2 commit 0d7aeaf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/block-editor/src/hooks/block-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const useToolsPanelDropdownMenuProps = () => {

function BlockBindingsPanelDropdown( { attribute, binding } ) {
const blockContext = useContext( BlockContext );
const { updateBlockBindings } = useBlockBindingsUtils();
const registeredSources = getBlockBindingsSources();
// Get a new object with the rendered components to check if they are null.
const sourcesComponents = Object.entries( registeredSources ).reduce(
Expand All @@ -70,6 +71,9 @@ function BlockBindingsPanelDropdown( { attribute, binding } ) {
if ( SourceComponent ) {
acc[ name ] = SourceComponent;
}
} else if ( name !== 'core/pattern-overrides' ) {
// TODO: Look for a proper way to opt-in/opt-out for this.
acc[ name ] = null;
}

return acc;
Expand All @@ -84,6 +88,20 @@ function BlockBindingsPanelDropdown( { attribute, binding } ) {

return Object.entries( sourcesComponents ).map(
( [ sourceName, SourceComponent ] ) => {
if ( ! SourceComponent ) {
return (
<DropdownMenuV2.Item
onClick={ () => {
updateBlockBindings( {
[ attribute ]: { source: sourceName },
} );
} }
>
{ registeredSources[ sourceName ].label }
</DropdownMenuV2.Item>
);
}

return (
<DropdownMenuV2
key={ sourceName }
Expand Down

0 comments on commit 0d7aeaf

Please sign in to comment.