Skip to content

Commit e3ebbfc

Browse files
committed
Only show binding manager if there are bindings
1 parent ccb5117 commit e3ebbfc

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

includes/manager/register-attribute-binder.js

+26-29
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
4646
'meta'
4747
);
4848

49-
// Saving the fields as serialized JSON because I was tired of fighting the REST API.
50-
const fields = meta?.fields ? JSON.parse( meta.fields ) : [];
49+
const fields = useMemo( () => {
50+
// Saving the fields as serialized JSON because I was tired of fighting the REST API.
51+
return meta?.fields ? JSON.parse( meta.fields ) : [];
52+
}, [ meta.fields ] );
5153

5254
const { attributes, setAttributes, name } = props;
5355

@@ -81,7 +83,7 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
8183
} );
8284

8385
setAttributes( newAttributes );
84-
}, [ attributes.metadata, setAttributes ] );
86+
}, [ attributes.metadata, setAttributes, fields, setMeta ] );
8587

8688
const selectedBlockType = getBlockType( name );
8789

@@ -196,43 +198,40 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
196198
return <BlockEdit { ...props } />;
197199
}
198200

201+
const bindings = attributes?.metadata?.[ window.BINDINGS_KEY ];
202+
199203
return (
200204
<>
201205
<InspectorControls>
202206
<PanelBody title="Attribute Bindings" initialOpen>
203-
{ ! editingBoundAttribute &&
204-
attributes?.metadata?.[
205-
window.BLOCK_VARIATION_NAME_ATTR
206-
] && (
207-
<ItemGroup isBordered isSeparated>
208-
{ supportedAttributes.map(
209-
( attribute ) => (
210-
<Item key={ attribute }>
211-
<Flex>
212-
<FlexBlock>
213-
{ attribute }
214-
</FlexBlock>
207+
{ ! editingBoundAttribute && bindings && (
208+
<ItemGroup isBordered isSeparated>
209+
{ supportedAttributes.map( ( attribute ) => {
210+
return (
211+
<Item key={ attribute }>
212+
<Flex>
213+
<FlexBlock>
214+
{ attribute }
215+
</FlexBlock>
216+
{ bindings[ attribute ] && (
215217
<FlexItem>
216218
<span>
217219
<code>
218220
{
219-
attributes
220-
?.metadata?.[
221-
window
222-
.BINDINGS_KEY
223-
][
221+
bindings[
224222
attribute
225223
]
226224
}
227225
</code>
228226
</span>
229227
</FlexItem>
230-
</Flex>
231-
</Item>
232-
)
233-
) }
234-
</ItemGroup>
235-
) }
228+
) }
229+
</Flex>
230+
</Item>
231+
);
232+
} ) }
233+
</ItemGroup>
234+
) }
236235
{ ! editingBoundAttribute && (
237236
<PanelRow>
238237
<ButtonGroup>
@@ -246,9 +245,7 @@ const withAttributeBinder = createHigherOrderComponent( ( BlockEdit ) => {
246245
>
247246
{ __( 'Manage Binding' ) }
248247
</Button>
249-
{ attributes?.metadata?.[
250-
window.BLOCK_VARIATION_NAME_ATTR
251-
] && (
248+
{ bindings && (
252249
<Button
253250
isDestructive
254251
onClick={ removeBindings }

0 commit comments

Comments
 (0)