From 24257f977137c239598eedcec08e86104fdb191f Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Fri, 31 Jan 2025 18:28:28 +0530 Subject: [PATCH] chore: Always display the extension of an attached file (#10806) --- .../components-next/message/chips/File.vue | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/app/javascript/dashboard/components-next/message/chips/File.vue b/app/javascript/dashboard/components-next/message/chips/File.vue index 07ca522cf..8638fd15d 100644 --- a/app/javascript/dashboard/components-next/message/chips/File.vue +++ b/app/javascript/dashboard/components-next/message/chips/File.vue @@ -16,15 +16,41 @@ const { t } = useI18n(); const fileName = computed(() => { const url = attachment.dataUrl; - if (url) { - const filename = url.substring(url.lastIndexOf('/') + 1); - return filename || t('CONVERSATION.UNKNOWN_FILE_TYPE'); + if (!url) return t('CONVERSATION.UNKNOWN_FILE_TYPE'); + + try { + const encodedFilename = url.substring(url.lastIndexOf('/') + 1); + return decodeURIComponent(encodedFilename); + } catch { + return t('CONVERSATION.UNKNOWN_FILE_TYPE'); } - return t('CONVERSATION.UNKNOWN_FILE_TYPE'); }); -const fileType = computed(() => { - return fileName.value.split('.').pop(); +const fileType = computed(() => fileName.value.split('.').pop()?.toLowerCase()); + +const fileNameWithoutExt = computed(() => { + const parts = fileName.value.split('.'); + + // If there's no extension (no dots in filename) + if (parts.length === 1) { + return fileName.value.trim(); + } + + // Take all parts except the last one (extension) + const nameWithoutExt = parts.slice(0, -1).join('.'); + return nameWithoutExt.trim(); +}); + +const displayFileName = computed(() => { + const name = fileNameWithoutExt.value; + const truncatedName = (str, maxLength, hasExt) => + str.length > maxLength + ? `${str.substring(0, maxLength).trimEnd()}${hasExt ? '..' : '...'}` + : str; + + return fileType.value + ? `${truncatedName(name, 14, true)}.${fileType.value}` + : truncatedName(name, 16, false); }); const textColorClass = computed(() => { @@ -53,15 +79,19 @@ const textColorClass = computed(() => {