From a282a7b3e68bbab874eda4b9aad540b63a9a3a99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABlle=20FOURNIER?= <gaelle.fournier.work@gmail.com>
Date: Mon, 6 Sep 2021 15:52:34 +0200
Subject: [PATCH] TULEAP 24198 : Fix FileFormat update with empty mimeType and
 extensions

---
 .../file-format-information-tab.component.ts          | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/ui/ui-frontend/projects/referential/src/app/file-format/file-format-preview/file-format-information-tab/file-format-information-tab.component.ts b/ui/ui-frontend/projects/referential/src/app/file-format/file-format-preview/file-format-information-tab/file-format-information-tab.component.ts
index 5d45d590a..7c54bd79e 100644
--- a/ui/ui-frontend/projects/referential/src/app/file-format/file-format-preview/file-format-information-tab/file-format-information-tab.component.ts
+++ b/ui/ui-frontend/projects/referential/src/app/file-format/file-format-preview/file-format-information-tab/file-format-information-tab.component.ts
@@ -64,7 +64,14 @@ export class FileFormatInformationTabComponent {
   private _fileFormat: FileFormat;
 
   previousValue = (): FileFormat => {
-    return this._fileFormat;
+    var cleanedFileFortmat = this._fileFormat;
+    if (!cleanedFileFortmat.mimeType) {
+      cleanedFileFortmat.mimeType = null;
+    }
+    if (!cleanedFileFortmat.extensions) {
+      cleanedFileFortmat.extensions = null;
+    }
+    return cleanedFileFortmat;
   }
 
   @Input()
@@ -127,6 +134,8 @@ export class FileFormatInformationTabComponent {
         if (formData.extensions) {
           // The extensions property must be an array of string, not a string
           formData.extensions = formData.extensions.replace(/\s/g, '').split(',');
+        } else if(isEmpty(formData.extensions)){
+          formData.extensions = [];
         }
         return this.fileFormatService.patch(formData).pipe(catchError(() => of(null)))
     }));
-- 
GitLab