From fb3daddc5da0615a080b35c0e604a9e2fa4edc93 Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Tue, 2 Dec 2025 14:56:20 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20exclude=20Drive=20file?= =?UTF-8?q?s=20of=20the=20attachment=20total=20size=20limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drive file are currently taken in account to compute the attachment total size to know it the size limit has been reached. But actually we only want to take in account the local attachments. --- src/frontend/public/locales/common/en-US.json | 2 -- src/frontend/public/locales/common/fr-FR.json | 3 ++- .../components/message-form/attachment-uploader.tsx | 11 ++++++++--- .../thread-attachment-list/attachment-item.tsx | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/frontend/public/locales/common/en-US.json b/src/frontend/public/locales/common/en-US.json index 5ee807ce..1e9bc98f 100644 --- a/src/frontend/public/locales/common/en-US.json +++ b/src/frontend/public/locales/common/en-US.json @@ -136,7 +136,6 @@ "Failed to refresh summary.": "Failed to refresh summary.", "Failed to save template. Please try again.": "Failed to save template. Please try again.", "Feedback?": "Feedback?", - "File too large": "File too large", "First name": "First name", "First name is required.": "First name is required.", "First, we need some information about your old mailbox": "First, we need some information about your old mailbox", @@ -300,7 +299,6 @@ "The domain {{domain}} has been created successfully.": "The domain {{domain}} has been created successfully.", "The email {{email}} is invalid.": "The email {{email}} is invalid.", "The email address is invalid.": "The email address is invalid.", - "The file is too large. It must be less than {{size}}.": "The file is too large. It must be less than {{size}}.", "The forced signature will be the only one usable for new messages.": "The forced signature will be the only one usable for new messages.", "The message could not be sent.": "The message could not be sent.", "The message could not be sent. Please try again later.": "The message could not be sent. Please try again later.", diff --git a/src/frontend/public/locales/common/fr-FR.json b/src/frontend/public/locales/common/fr-FR.json index 9e7539e7..669ef461 100644 --- a/src/frontend/public/locales/common/fr-FR.json +++ b/src/frontend/public/locales/common/fr-FR.json @@ -53,6 +53,7 @@ "At least one recipient is required.": "Il faut au moins un destinataire.", "Attachment failed to be saved into your Drive's workspace.": "Impossible de sauvegarder la pièce jointe dans votre espace de travail Fichiers.", "Attachment saved into your Drive's workspace.": "Pièce jointe sauvegardée dans votre espace de travail Fichiers.", + "Attachment size limit exceeded": "La taille des pièces jointes excède la limite autorisée.", "Attachments must be less than {{size}}.": "Les pièces jointes ne peuvent pas excéder {{size}}.", "Authentication failed. Please check your credentials and ensure you have enabled IMAP connections in your account.": "L'authentification a échoué. Veuillez vérifier vos identifiants et assurez-vous d'avoir autorisé les connexions IMAP dans votre compte.", "Auto-labeling": "Labellisation automatique", @@ -62,6 +63,7 @@ "BCC: ": "CCI : ", "Blind copy: ": "Copie cachée : ", "Cancel": "Annuler", + "Cannot add attachment(s). Total size would be more than {{maxSize}}.": "Impossible d'ajouter ces pièces jointes. La taille totale dépasserait la limite autorisée de {{maxSize}}.", "Check DNS again": "Revérifier les DNS", "Checking DNS records...": "Vérification des enregistrements DNS...", "Close": "Fermer", @@ -297,7 +299,6 @@ "The domain {{domain}} has been created successfully.": "Le domaine {{domain}} a été créé avec succès.", "The email {{email}} is invalid.": "Le courriel {{email}} est invalide.", "The email address is invalid.": "L'adresse email est invalide.", - "The file is too large. It must be less than {{size}}.": "Le fichier est trop volumineux. Il doit être inférieur à {{size}}.", "The forced signature will be the only one usable for new messages.": "La signature forcée sera la seule utilisable pour les nouveaux messages.", "The message could not be sent.": "Le message n'a pas pu être envoyé.", "The message could not be sent. Please try again later.": "Le message n'a pas pu être envoyé. Veuillez réessayer plus tard.", diff --git a/src/frontend/src/features/forms/components/message-form/attachment-uploader.tsx b/src/frontend/src/features/forms/components/message-form/attachment-uploader.tsx index 789fe654..f53f21ed 100644 --- a/src/frontend/src/features/forms/components/message-form/attachment-uploader.tsx +++ b/src/frontend/src/features/forms/components/message-form/attachment-uploader.tsx @@ -5,7 +5,7 @@ import { useMailboxContext } from '@/features/providers/mailbox'; import { useConfig } from '@/features/providers/config'; import { useFormContext } from 'react-hook-form'; import { Button, Field, useModals, VariantType } from '@openfun/cunningham-react'; -import { AttachmentItem } from '@/features/layouts/components/thread-view/components/thread-attachment-list/attachment-item'; +import { AttachmentItem, isAttachment } from '@/features/layouts/components/thread-view/components/thread-attachment-list/attachment-item'; import { useTranslation } from 'react-i18next'; import { useDropzone } from 'react-dropzone'; import { AttachmentHelper } from '@/features/utils/attachment-helper'; @@ -39,7 +39,10 @@ export const AttachmentUploader = ({ const debouncedOnChange = useDebounceCallback(onChange, 1000); // Calculate current total size of attachments and pending uploads - const attachmentsSize = attachments.reduce((acc, attachment) => acc + attachment.size, 0); + const attachmentsSize = attachments.reduce((acc, attachment) => { + if (isAttachment(attachment)) return acc + attachment.size; + return acc; + }, 0); const uploadingQueueSize = uploadingQueue.reduce((acc, file) => acc + file.size, 0); const currentTotalSize = attachmentsSize + uploadingQueueSize; @@ -181,7 +184,9 @@ export const AttachmentUploader = ({ ? t("{{count}} attachments", { count: attachments.length, defaultValue_one: "{{count}} attachment" }) : t("No attachments")} {' '} - ({AttachmentHelper.getFormattedTotalSize(attachments, i18n.resolvedLanguage)}) + {attachments.filter(isAttachment).length > 0 && ( + `(${AttachmentHelper.getFormattedTotalSize(attachments.filter(isAttachment), i18n.resolvedLanguage)})` + )}

{failedQueue.map((entry) => ( diff --git a/src/frontend/src/features/layouts/components/thread-view/components/thread-attachment-list/attachment-item.tsx b/src/frontend/src/features/layouts/components/thread-view/components/thread-attachment-list/attachment-item.tsx index bd27b27c..fc154669 100644 --- a/src/frontend/src/features/layouts/components/thread-view/components/thread-attachment-list/attachment-item.tsx +++ b/src/frontend/src/features/layouts/components/thread-view/components/thread-attachment-list/attachment-item.tsx @@ -19,10 +19,10 @@ type AttachmentItemProps = { onDelete?: () => void; } -const isAttachment = (attachment: Attachment | File | DriveFile): attachment is Attachment => { +export const isAttachment = (attachment: Attachment | File | DriveFile): attachment is Attachment => { return 'blobId' in attachment; } -const isDriveFile = (attachment: Attachment | File | DriveFile): attachment is DriveFile => { +export const isDriveFile = (attachment: Attachment | File | DriveFile): attachment is DriveFile => { return 'url' in attachment; }