Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gallery: Hide some controls when multi-editing blocks #57378

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading