From d7424d4ac4a403af902eef7da0bb0a86508bfa31 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 23 Mar 2023 11:18:17 +0400 Subject: [PATCH 1/2] MediaReplaceFlow: Check permissions before displaying the 'Media Library' menu item --- .../components/media-replace-flow/index.js | 60 +++++++++++-------- .../components/media-replace-flow/style.scss | 5 ++ 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/packages/block-editor/src/components/media-replace-flow/index.js b/packages/block-editor/src/components/media-replace-flow/index.js index a2fb5f36036aa..9176fd588b700 100644 --- a/packages/block-editor/src/components/media-replace-flow/index.js +++ b/packages/block-editor/src/components/media-replace-flow/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -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 }`; @@ -152,7 +158,7 @@ const MediaReplaceFlow = ( { renderContent={ ( { onClose } ) => ( <> - <> + ) } /> - - { - uploadFiles( event, onClose ); - } } - accept={ accept } - multiple={ multiple } - render={ ( { openFileDialog } ) => { - return ( - { - openFileDialog(); - } } - > - { __( 'Upload' ) } - - ); - } } - /> - - + { + uploadFiles( event, onClose ); + } } + accept={ accept } + multiple={ multiple } + render={ ( { openFileDialog } ) => { + return ( + { + openFileDialog(); + } } + > + { __( 'Upload' ) } + + ); + } } + /> + { onToggleFeaturedImage && ( { onSelectURL && ( // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -
+ { __( 'Current media URL:' ) } diff --git a/packages/block-editor/src/components/media-replace-flow/style.scss b/packages/block-editor/src/components/media-replace-flow/style.scss index 81484cbf80662..eacc5663f3f40 100644 --- a/packages/block-editor/src/components/media-replace-flow/style.scss +++ b/packages/block-editor/src/components/media-replace-flow/style.scss @@ -16,6 +16,11 @@ margin-left: -$grid-unit-10; padding: $grid-unit-20; + &.has-siblings { + border-top: none; + margin-top: 0; + } + .block-editor-media-replace-flow__image-url-label { display: block; top: $grid-unit-20; From 4d8d5742600caa15d5f6613a37c534567bc2eee8 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Thu, 23 Mar 2023 11:39:13 +0400 Subject: [PATCH 2/2] Adjust 'has-siblings' logic --- .../block-editor/src/components/media-replace-flow/index.js | 2 +- .../src/components/media-replace-flow/style.scss | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/block-editor/src/components/media-replace-flow/index.js b/packages/block-editor/src/components/media-replace-flow/index.js index 9176fd588b700..29790419af131 100644 --- a/packages/block-editor/src/components/media-replace-flow/index.js +++ b/packages/block-editor/src/components/media-replace-flow/index.js @@ -215,7 +215,7 @@ const MediaReplaceFlow = ( { 'block-editor-media-flow__url-input', { 'has-siblings': - ! canUpload && ! onToggleFeaturedImage, + canUpload || onToggleFeaturedImage, } ) } > diff --git a/packages/block-editor/src/components/media-replace-flow/style.scss b/packages/block-editor/src/components/media-replace-flow/style.scss index eacc5663f3f40..dd3b0563c3ca8 100644 --- a/packages/block-editor/src/components/media-replace-flow/style.scss +++ b/packages/block-editor/src/components/media-replace-flow/style.scss @@ -10,15 +10,13 @@ } .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: none; - margin-top: 0; + border-top: $border-width solid $gray-900; + margin-top: $grid-unit-10; } .block-editor-media-replace-flow__image-url-label {