From ef14a07d09e9f82b986b7583879a32cc4e9d479a Mon Sep 17 00:00:00 2001 From: Lone Iversen <108085781+loivsen@users.noreply.github.com> Date: Mon, 13 May 2024 13:21:30 +0200 Subject: [PATCH] dont show popup if not allowed. Throw a description error --- .../media/dropzone/dropzone-manager.class.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media/dropzone/dropzone-manager.class.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media/dropzone/dropzone-manager.class.ts index d8003fe2be..c96203b8c0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media/dropzone/dropzone-manager.class.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media/dropzone/dropzone-manager.class.ts @@ -88,16 +88,21 @@ export class UmbDropzoneManager extends UmbControllerBase { // Building an array of uploadable files. Do we want to build an array of failed files to let the user know which ones? const uploadableFiles: Array = []; + const notAllowedFiles: Array = []; for (const file of files) { const extension = this.#getExtensionFromMime(file.type); if (!extension) { // Folders have no extension on file drop. We assume it is a folder being uploaded. - return; + continue; } const options = optionsArray.find((option) => option.fileExtension === extension)?.mediaTypes; - if (!options) return; // TODO Current dropped file not allowed in this area. Find a good way to show this to the user after we finish uploading the rest of the files. + if (!options || !options.length) { + // TODO Current dropped file not allowed in this area. Find a good way to show this to the user after we finish uploading the rest of the files. + notAllowedFiles.push(file); + continue; + } // Since we are uploading multiple files, we will pick first allowed option. // Consider a way we can handle this differently in the future to let the user choose. Maybe a list of all files with an allowed media type dropdown? @@ -105,6 +110,16 @@ export class UmbDropzoneManager extends UmbControllerBase { uploadableFiles.push({ unique: UmbId.new(), file, mediaTypeUnique: mediaType.unique }); } + notAllowedFiles.forEach((file) => { + try { + throw new Error(`File ${file.name} of type ${file.type} is not allowed here.`); + } catch (e) { + undefined; + } + }); + + if (!uploadableFiles.length) return; + await this.#handleUpload(uploadableFiles, parentUnique); } @@ -118,7 +133,9 @@ export class UmbDropzoneManager extends UmbControllerBase { } const optionsArray = await this.#buildOptionsArrayFrom([extension], parentUnique); - if (!optionsArray.length) throw new Error('File not allowed here.'); // Parent does not allow this file type here. + if (!optionsArray.length || !optionsArray[0].mediaTypes.length) { + throw new Error(`File ${file.name} of type ${file.type} is not allowed here.`); // Parent does not allow this file type here. + } const mediaTypes = optionsArray[0].mediaTypes; if (mediaTypes.length === 1) {