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: Display upload error notices using snackbars #43946

Merged
merged 1 commit into from
Sep 8, 2022
Merged
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
23 changes: 8 additions & 15 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
PanelBody,
SelectControl,
ToggleControl,
withNotices,
RangeControl,
Spinner,
} from '@wordpress/components';
Expand Down Expand Up @@ -80,9 +79,7 @@ function GalleryEdit( props ) {
attributes,
className,
clientId,
noticeOperations,
isSelected,
noticeUI,
insertBlocksAfter,
} = props;

Expand All @@ -95,7 +92,8 @@ function GalleryEdit( props ) {
selectBlock,
clearSelectedBlock,
} = useDispatch( blockEditorStore );
const { createSuccessNotice } = useDispatch( noticesStore );
const { createSuccessNotice, createErrorNotice } =
useDispatch( noticesStore );

const { getBlock, getSettings, preferredStyle } = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
Expand Down Expand Up @@ -244,12 +242,11 @@ function GalleryEdit( props ) {
: selectedImages;

if ( ! imageArray.every( isValidFileType ) ) {
noticeOperations.removeAllNotices();
noticeOperations.createErrorNotice(
createErrorNotice(
__(
'If uploading to a gallery all files need to be image formats'
),
{ id: 'gallery-upload-invalid-file' }
{ id: 'gallery-upload-invalid-file', type: 'snackbar' }
);
}

Expand Down Expand Up @@ -316,8 +313,7 @@ function GalleryEdit( props ) {
}

function onUploadError( message ) {
noticeOperations.removeAllNotices();
noticeOperations.createErrorNotice( message );
createErrorNotice( message, { type: 'snackbar' } );
}

function setLinkTo( value ) {
Expand Down Expand Up @@ -470,7 +466,6 @@ function GalleryEdit( props ) {
allowedTypes={ ALLOWED_MEDIA_TYPES }
multiple
onError={ onUploadError }
notices={ noticeUI }
{ ...mediaPlaceholderProps }
/>
);
Expand Down Expand Up @@ -560,7 +555,6 @@ function GalleryEdit( props ) {
addToGallery={ hasImageIds }
/>
</BlockControls>
{ noticeUI }
{ Platform.isWeb && (
<GapStyles
blockGap={ attributes.style?.spacing?.blockGap }
Expand All @@ -581,7 +575,6 @@ function GalleryEdit( props ) {
</>
);
}
export default compose( [
withNotices,
withViewportMatch( { isNarrow: '< small' } ),
] )( GalleryEdit );
export default compose( [ withViewportMatch( { isNarrow: '< small' } ) ] )(
GalleryEdit
);