Skip to content

Commit

Permalink
Video: Hide some controls when multi-editing blocks (#57375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Dec 27, 2023
1 parent 489cf3d commit 9cf9a30
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ function VideoEdit( {
const posterImageButton = useRef();
const { id, controls, poster, src, tracks } = attributes;
const isTemporaryVideo = ! id && isBlobURL( src );
const mediaUpload = useSelect(
( select ) => select( blockEditorStore ).getSettings().mediaUpload,
[]
);
const { mediaUpload, multiVideoSelection } = useSelect( ( select ) => {
const { getSettings, getMultiSelectedBlockClientIds, getBlockName } =
select( blockEditorStore );
const multiSelectedClientIds = getMultiSelectedBlockClientIds();

return {
mediaUpload: getSettings().mediaUpload,
multiVideoSelection:
multiSelectedClientIds.length &&
multiSelectedClientIds.every(
( _clientId ) => getBlockName( _clientId ) === 'core/video'
),
};
}, [] );

useEffect( () => {
if ( ! id && isBlobURL( src ) ) {
Expand Down Expand Up @@ -185,25 +195,29 @@ function VideoEdit( {

return (
<>
<BlockControls>
<TracksEditor
tracks={ tracks }
onChange={ ( newTracks ) => {
setAttributes( { tracks: newTracks } );
} }
/>
</BlockControls>
<BlockControls group="other">
<MediaReplaceFlow
mediaId={ id }
mediaURL={ src }
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="video/*"
onSelect={ onSelectVideo }
onSelectURL={ onSelectURL }
onError={ onUploadError }
/>
</BlockControls>
{ ! multiVideoSelection && (
<>
<BlockControls>
<TracksEditor
tracks={ tracks }
onChange={ ( newTracks ) => {
setAttributes( { tracks: newTracks } );
} }
/>
</BlockControls>
<BlockControls group="other">
<MediaReplaceFlow
mediaId={ id }
mediaURL={ src }
allowedTypes={ ALLOWED_MEDIA_TYPES }
accept="video/*"
onSelect={ onSelectVideo }
onSelectURL={ onSelectURL }
onError={ onUploadError }
/>
</BlockControls>
</>
) }
<InspectorControls>
<PanelBody title={ __( 'Settings' ) }>
<VideoCommonSettings
Expand Down Expand Up @@ -284,6 +298,7 @@ function VideoEdit( {
isSelected={ isSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Video caption text' ) }
showToolbarButton={ ! multiVideoSelection }
/>
</figure>
</>
Expand Down

1 comment on commit 9cf9a30

@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 9cf9a30.
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/7335480368
📝 Reported issues:

Please sign in to comment.