Skip to content

Commit

Permalink
Gallery: Hide some controls when multi-editing blocks (#57378)
Browse files Browse the repository at this point in the history
* Gallery: Hide some controls when multi-editing blocks
* Fix typo
  • Loading branch information
Mamaduka authored Dec 27, 2023
1 parent 9cf9a30 commit 3880148
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
68 changes: 43 additions & 25 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,38 @@ function GalleryEdit( props ) {
getSettings,
preferredStyle,
innerBlockImages,
wasBlockJustInserted,
blockWasJustInserted,
multiGallerySelection,
} = useSelect(
( select ) => {
const settings = select( blockEditorStore ).getSettings();
const {
getBlockName,
getMultiSelectedBlockClientIds,
getSettings: _getSettings,
getBlock: _getBlock,
wasBlockJustInserted,
} = select( blockEditorStore );
const preferredStyleVariations =
settings.__experimentalPreferredStyleVariations;
_getSettings().__experimentalPreferredStyleVariations;
const multiSelectedClientIds = getMultiSelectedBlockClientIds();

return {
getBlock: select( blockEditorStore ).getBlock,
getSettings: select( blockEditorStore ).getSettings,
getBlock: _getBlock,
getSettings: _getSettings,
preferredStyle:
preferredStyleVariations?.value?.[ 'core/image' ],
innerBlockImages:
select( blockEditorStore ).getBlock( clientId )
?.innerBlocks ?? EMPTY_ARRAY,
wasBlockJustInserted: select(
blockEditorStore
).wasBlockJustInserted( clientId, 'inserter_menu' ),
_getBlock( clientId )?.innerBlocks ?? EMPTY_ARRAY,
blockWasJustInserted: wasBlockJustInserted(
clientId,
'inserter_menu'
),
multiGallerySelection:
multiSelectedClientIds.length &&
multiSelectedClientIds.every(
( _clientId ) =>
getBlockName( _clientId ) === 'core/gallery'
),
};
},
[ clientId ]
Expand Down Expand Up @@ -461,7 +476,7 @@ function GalleryEdit( props ) {
( hasImages && ! isSelected ) || imagesUploading,
value: hasImageIds ? images : {},
autoOpenMediaUpload:
! hasImages && isSelected && wasBlockJustInserted,
! hasImages && isSelected && blockWasJustInserted,
onFocus,
},
} );
Expand Down Expand Up @@ -583,20 +598,22 @@ function GalleryEdit( props ) {
</InspectorControls>
{ Platform.isWeb && (
<>
<BlockControls group="other">
<MediaReplaceFlow
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="image/*"
handleUpload={ false }
onSelect={ updateImages }
name={ __( 'Add' ) }
multiple={ true }
mediaIds={ images
.filter( ( image ) => image.id )
.map( ( image ) => image.id ) }
addToGallery={ hasImageIds }
/>
</BlockControls>
{ ! multiGallerySelection && (
<BlockControls group="other">
<MediaReplaceFlow
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="image/*"
handleUpload={ false }
onSelect={ updateImages }
name={ __( 'Add' ) }
multiple={ true }
mediaIds={ images
.filter( ( image ) => image.id )
.map( ( image ) => image.id ) }
addToGallery={ hasImageIds }
/>
</BlockControls>
) }
<GapStyles
blockGap={ attributes.style?.spacing?.blockGap }
clientId={ clientId }
Expand All @@ -614,6 +631,7 @@ function GalleryEdit( props ) {
}
blockProps={ innerBlocksProps }
insertBlocksAfter={ insertBlocksAfter }
multiGallerySelection={ multiGallerySelection }
/>
</>
);
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function Gallery( props ) {
blockProps,
__unstableLayoutClassNames: layoutClassNames,
isContentLocked,
multiGallerySelection,
} = props;

const { align, columns, imageCrop } = attributes;
Expand Down Expand Up @@ -54,7 +55,9 @@ export default function Gallery( props ) {
setAttributes={ setAttributes }
isSelected={ isSelected }
insertBlocksAfter={ insertBlocksAfter }
showToolbarButton={ ! isContentLocked }
showToolbarButton={
! multiGallerySelection && ! isContentLocked
}
className="blocks-gallery-caption"
label={ __( 'Gallery caption text' ) }
placeholder={ __( 'Add gallery caption' ) }
Expand Down

1 comment on commit 3880148

@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 3880148.
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/7336035560
📝 Reported issues:

Please sign in to comment.