Skip to content

Commit

Permalink
MediaReplaceFlow: Check permissions before displaying the 'Media Libr…
Browse files Browse the repository at this point in the history
…ary' menu item (#49298)
  • Loading branch information
Mamaduka authored Mar 23, 2023
1 parent 3fd9bf4 commit 87dcd7a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
60 changes: 36 additions & 24 deletions packages/block-editor/src/components/media-replace-flow/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -58,6 +63,7 @@ const MediaReplaceFlow = ( {
const mediaUpload = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings().mediaUpload;
}, [] );
const canUpload = !! mediaUpload;
const editMediaButtonRef = useRef();
const errorNoticeID = `block-editor/media-replace-flow/error-notice/${ ++uniqueId }`;

Expand Down Expand Up @@ -152,7 +158,7 @@ const MediaReplaceFlow = ( {
renderContent={ ( { onClose } ) => (
<>
<NavigableMenu className="block-editor-media-replace-flow__media-upload-menu">
<>
<MediaUploadCheck>
<MediaUpload
gallery={ gallery }
addToGallery={ addToGallery }
Expand All @@ -171,28 +177,26 @@ const MediaReplaceFlow = ( {
</MenuItem>
) }
/>
<MediaUploadCheck>
<FormFileUpload
onChange={ ( event ) => {
uploadFiles( event, onClose );
} }
accept={ accept }
multiple={ multiple }
render={ ( { openFileDialog } ) => {
return (
<MenuItem
icon={ upload }
onClick={ () => {
openFileDialog();
} }
>
{ __( 'Upload' ) }
</MenuItem>
);
} }
/>
</MediaUploadCheck>
</>
<FormFileUpload
onChange={ ( event ) => {
uploadFiles( event, onClose );
} }
accept={ accept }
multiple={ multiple }
render={ ( { openFileDialog } ) => {
return (
<MenuItem
icon={ upload }
onClick={ () => {
openFileDialog();
} }
>
{ __( 'Upload' ) }
</MenuItem>
);
} }
/>
</MediaUploadCheck>
{ onToggleFeaturedImage && (
<MenuItem
icon={ postFeaturedImage }
Expand All @@ -206,7 +210,15 @@ const MediaReplaceFlow = ( {
</NavigableMenu>
{ onSelectURL && (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<form className="block-editor-media-flow__url-input">
<form
className={ classnames(
'block-editor-media-flow__url-input',
{
'has-siblings':
canUpload || onToggleFeaturedImage,
}
) }
>
<span className="block-editor-media-replace-flow__image-url-label">
{ __( 'Current media URL:' ) }
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
}

.block-editor-media-flow__url-input {
border-top: $border-width solid $gray-900;
margin-top: $grid-unit-10;
margin-right: -$grid-unit-10;
margin-left: -$grid-unit-10;
padding: $grid-unit-20;

&.has-siblings {
border-top: $border-width solid $gray-900;
margin-top: $grid-unit-10;
}

.block-editor-media-replace-flow__image-url-label {
display: block;
top: $grid-unit-20;
Expand Down

1 comment on commit 87dcd7a

@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 87dcd7a.
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/4498940524
📝 Reported issues:

Please sign in to comment.