Remove Media Library menu item from Downloads section (#46490)

* Remove MediaLibraryMenuItem from downloads

* Add changelog
This commit is contained in:
Nathan Silveira 2024-04-12 11:03:10 -03:00 committed by GitHub
parent 0b69d4d6f7
commit 027f83f1fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 4 additions and 109 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Remove Media Library menu item from Downloads section

View File

@ -10,7 +10,6 @@ import { chevronDown, chevronUp } from '@wordpress/icons';
* Internal dependencies
*/
import { DownloadsMenuProps } from './types';
import { MediaLibraryMenuItem } from '../media-library-menu-item';
import { InsertUrlMenuItem } from '../insert-url-menu-item';
import { UploadFilesMenuItem } from '../upload-files-menu-item';
@ -50,13 +49,6 @@ export function DownloadsMenu( {
} }
onUploadError={ onUploadError }
/>
<MediaLibraryMenuItem
allowedTypes={ allowedTypes }
onUploadSuccess={ ( files ) => {
onUploadSuccess( files );
onClose();
} }
/>
<InsertUrlMenuItem
onUploadSuccess={ ( files ) => {

View File

@ -1,5 +1,4 @@
@import "./downloads-menu/style.scss";
@import "./media-library-menu-item/style.scss";
@import "./insert-url-menu-item/style.scss";
@import "./edit-downloads-modal/style.scss";

View File

@ -1,2 +0,0 @@
export * from './media-library-menu-item';
export * from './types';

View File

@ -1,75 +0,0 @@
/**
* External dependencies
*/
import { MenuItem } from '@wordpress/components';
import { createElement, useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { media } from '@wordpress/icons';
import { MediaItem } from '@wordpress/media-utils';
/**
* Internal dependencies
*/
import { MediaLibraryMenuItemProps } from './types';
import { MediaLibrary } from '../media-library';
const MODAL_CLASS_NAME =
'woocommerce-media-library-menu-item__upload_files_modal';
const MODAL_WRAPPER_CLASS_NAME =
'woocommerce-media-library-menu-item__upload_files_modal_wrapper';
export function MediaLibraryMenuItem( {
allowedTypes,
onUploadSuccess,
}: MediaLibraryMenuItemProps ) {
const [ uploadFilesModalOpen, setUploadFilesModalOpen ] = useState( false );
useEffect(
function addUploadModalClass() {
const modal = document.querySelector( `.${ MODAL_CLASS_NAME }` );
const dialog = modal?.closest( '[role="dialog"]' );
const wrapper = dialog?.parentElement;
wrapper?.classList.add( MODAL_WRAPPER_CLASS_NAME );
return () => {
wrapper?.classList.remove( MODAL_WRAPPER_CLASS_NAME );
};
},
[ uploadFilesModalOpen ]
);
function handleMediaUploadSelect( value: MediaItem[] ) {
onUploadSuccess( value );
}
function uploadFilesClickHandler( openMediaUploadModal: () => void ) {
return function handleUploadFilesClick() {
openMediaUploadModal();
setUploadFilesModalOpen( true );
};
}
return (
<MediaLibrary
className={ MODAL_CLASS_NAME }
allowedTypes={ allowedTypes }
multiple="add"
uploaderParams={ {
type: 'downloadable_product',
} }
onSelect={ handleMediaUploadSelect }
>
{ ( { open } ) => (
<MenuItem
icon={ media }
iconPosition="left"
onClick={ uploadFilesClickHandler( open ) }
info={ __( 'Choose from uploaded media', 'woocommerce' ) }
>
{ __( 'Media Library', 'woocommerce' ) }
</MenuItem>
) }
</MediaLibrary>
);
}

View File

@ -1,14 +0,0 @@
$media-modal-z-index: calc(z-index(".components-popover") + 10000);
$media-modal-backdrop-z-index: calc($media-modal-z-index - 1000);
.woocommerce-media-library-menu-item {
&__upload_files_modal_wrapper {
.media-modal {
z-index: $media-modal-z-index;
}
.media-modal-backdrop {
z-index: $media-modal-backdrop-z-index;
}
}
}

View File

@ -1,9 +0,0 @@
/**
* External dependencies
*/
import { MediaItem } from '@wordpress/media-utils';
export type MediaLibraryMenuItemProps = {
allowedTypes?: string[];
onUploadSuccess( files: MediaItem[] ): void;
};