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 block refactor: make invalid file type errors consistent #30396

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,18 @@ function GalleryEdit( props ) {
} )
: selectedImages;

if (
imageArray.some(
( image ) => image.type?.indexOf( 'image/' ) !== 0
)
) {
noticeOperations.createErrorNotice(
__(
'If uploading to a gallery all files need to be image formats'
)
);
}

const processedImages = imageArray
.filter(
( file ) => file.url || file.type?.indexOf( 'image/' ) === 0
Expand Down
10 changes: 3 additions & 7 deletions packages/block-library/src/image/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,11 @@ const transforms = {
( file ) => file.type.indexOf( 'image/' ) !== 0
)
) {
const { createWarningNotice } = dispatch( noticesStore );
createWarningNotice(
const { createErrorNotice } = dispatch( noticesStore );
createErrorNotice(
__(
'If uploading to a gallery all files need to be image formats'
),
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique id stop multiple notices only seems to work for snackbar notices

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the unique ID stops multiple notices for me within the default editor context. Unfortunately, as the gallery component's notice list is via internal state thanks to the withNotices HoC, I couldn't find a means to access it and remove other notices.

Essentially, a user can now get a max of two error notices regarding invalid files being uploaded. One when they drop the invalid file on the placeholder. The second if they drag invalid files into the gallery between other images.

id: 'image-upload-format-warning',
type: 'snackbar',
}
)
);
}
return every(
Expand Down