From c2277d1d9e4a644dbc205d72e826042fd59ef25b Mon Sep 17 00:00:00 2001
From: Homada Boumedane <homada.boumedane@unige.ch>
Date: Mon, 22 Jan 2024 14:50:54 +0100
Subject: [PATCH 1/7] refactor: compute current folder after a delete

---
 .../folder-tree/folder-tree.presentational.ts            | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index 7448d72a0..796b5fadc 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -43,6 +43,7 @@ import {
 import {AbstractInternalPresentational} from "../../../../core/components/presentationals/abstract-internal/abstract-internal.presentational";
 import {SOLIDIFY_CONSTANTS} from "../../../../core/constants";
 import {
+  isEmptyString,
   isNonEmptyArray,
   isNotNullNorUndefined,
   isNotNullNorUndefinedNorWhiteString,
@@ -269,7 +270,13 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
 
   private _expandFirstLevelTree(): void {
     if (this.currentFolder !== this.ROOT) {
-      const node = this.treeControl.dataNodes.find(d => d.fullFolderName === this.currentFolder);
+      let node = this.treeControl.dataNodes.find(d => d.fullFolderName === this.currentFolder);
+      if (isNullOrUndefined(node)) {
+        const urlOfFolder = this.currentFolder.substring(0, this.currentFolder.lastIndexOf(this._SEPARATOR));
+        let lastParentPath = !isEmptyString(urlOfFolder) ? urlOfFolder : this._ROOT;
+        node = this.treeControl.dataNodes.find(d => d.fullFolderName === lastParentPath);
+        this.currentFolder = lastParentPath;
+      }
       this._expandRecursivelyParent(node);
       this.treeControl.expand(node);
       return;
-- 
GitLab


From eded8bee8e0573c2f411ff930f3fb4641d4d2502 Mon Sep 17 00:00:00 2001
From: Florent Poittevin <florent.poittevin@unige.ch>
Date: Tue, 23 Jan 2024 12:02:40 +0100
Subject: [PATCH 2/7] chore: fix lint

---
 .../presentationals/folder-tree/folder-tree.presentational.ts   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index 796b5fadc..74453fa4c 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -273,7 +273,7 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
       let node = this.treeControl.dataNodes.find(d => d.fullFolderName === this.currentFolder);
       if (isNullOrUndefined(node)) {
         const urlOfFolder = this.currentFolder.substring(0, this.currentFolder.lastIndexOf(this._SEPARATOR));
-        let lastParentPath = !isEmptyString(urlOfFolder) ? urlOfFolder : this._ROOT;
+        const lastParentPath = !isEmptyString(urlOfFolder) ? urlOfFolder : this.ROOT;
         node = this.treeControl.dataNodes.find(d => d.fullFolderName === lastParentPath);
         this.currentFolder = lastParentPath;
       }
-- 
GitLab


From b608c24721ca88651151487e5bd24a9147d506e3 Mon Sep 17 00:00:00 2001
From: Florent Poittevin <florent.poittevin@unige.ch>
Date: Wed, 24 Jan 2024 12:57:26 +0100
Subject: [PATCH 3/7] chore: fix MR

---
 .../folder-tree/folder-tree.presentational.ts   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index 74453fa4c..301efaa14 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -80,6 +80,7 @@ class FileNode {
 export class FolderTreePresentational<TDataFile extends any> extends AbstractInternalPresentational implements OnInit, AfterViewInit {
   private readonly _SEPARATOR: string = SOLIDIFY_CONSTANTS.SEPARATOR;
   readonly ROOT: string = SOLIDIFY_CONSTANTS.SEPARATOR;
+  static readonly ROOT: string = SOLIDIFY_CONSTANTS.SEPARATOR;
 
   readonly indentation: number = 10;
   readonly CDK_DROP_LIST_PREFIX: string;
@@ -388,4 +389,20 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
   mouseOut($event: MouseEvent, node: FileFlatNode): void {
     this.eventMouseOver = undefined;
   }
+
+  static computeCurrentFolderAfterDelete(intermediateFolders: string[], foldersWithIntermediateFolders: string[], searchString: string): string {
+    let folderResult = null;
+    intermediateFolders.some(folder => {
+      if (searchString.includes(folder)) {
+        return foldersWithIntermediateFolders.some(intFolder => {
+          const remainingString = intFolder.substring(folder.length);
+          if (intFolder.startsWith(folder) && intFolder !== searchString && remainingString.length > 1) {
+            folderResult = folder;
+            return true;
+          }
+        });
+      }
+    });
+    return isNotNullNorUndefined(folderResult) ? folderResult : this.ROOT;
+  }
 }
-- 
GitLab


From f1a7314bf58989be8af5ada16ea34400afe49783 Mon Sep 17 00:00:00 2001
From: Homada Boumedane <homada.boumedane@unige.ch>
Date: Wed, 24 Jan 2024 19:55:51 +0100
Subject: [PATCH 4/7] refactor: folder tree

refactor compute current folder method
---
 .../folder-tree/folder-tree.presentational.ts | 30 +++++++++++--------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index 301efaa14..49e1ea13d 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -391,18 +391,24 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
   }
 
   static computeCurrentFolderAfterDelete(intermediateFolders: string[], foldersWithIntermediateFolders: string[], searchString: string): string {
-    let folderResult = null;
-    intermediateFolders.some(folder => {
-      if (searchString.includes(folder)) {
-        return foldersWithIntermediateFolders.some(intFolder => {
-          const remainingString = intFolder.substring(folder.length);
-          if (intFolder.startsWith(folder) && intFolder !== searchString && remainingString.length > 1) {
-            folderResult = folder;
-            return true;
-          }
-        });
+    let url = searchString.substring(0, searchString.lastIndexOf(this.ROOT));
+    if (isEmptyString(url)) {
+      return this.ROOT;
+    } else {
+      let folderWithIntFolders = foldersWithIntermediateFolders.find(folder => folder === url);
+      let intFolder = intermediateFolders.find(ft => ft === folderWithIntFolders);
+      if(isNotNullNorUndefined(intFolder)) {
+         let parentWithChild = foldersWithIntermediateFolders.find(folder => folder.startsWith(intFolder)
+                                                                          && folder !== searchString
+                                                                          && folder.substring(intFolder.length).length > 1);
+         if (isNotNullNorUndefined(parentWithChild)) {
+           return intFolder;
+         }else {
+           return this.computeCurrentFolderAfterDelete(intermediateFolders, foldersWithIntermediateFolders, url);
+         }
+      } else {
+        return folderWithIntFolders;
       }
-    });
-    return isNotNullNorUndefined(folderResult) ? folderResult : this.ROOT;
+    }
   }
 }
-- 
GitLab


From 1ba87853676e209f370981ea85b6c172227ffdc1 Mon Sep 17 00:00:00 2001
From: Homada Boumedane <homada.boumedane@unige.ch>
Date: Thu, 25 Jan 2024 21:59:38 +0100
Subject: [PATCH 5/7] refactor: folder tree component

refactore the compute current folder algo, support persisted value of variable when using recursive
---
 .../folder-tree/folder-tree.presentational.ts | 72 +++++++++++--------
 1 file changed, 41 insertions(+), 31 deletions(-)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index 49e1ea13d..e9c66d9b7 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -21,8 +21,8 @@
  * ----------------------------------------------------------------------------------------------%%
  */
 
-import {CdkDragDrop} from "@angular/cdk/drag-drop";
-import {FlatTreeControl} from "@angular/cdk/tree";
+import { CdkDragDrop } from "@angular/cdk/drag-drop";
+import { FlatTreeControl } from "@angular/cdk/tree";
 import {
   AfterViewInit,
   ChangeDetectionStrategy,
@@ -40,8 +40,8 @@ import {
   BehaviorSubject,
   Observable,
 } from "rxjs";
-import {AbstractInternalPresentational} from "../../../../core/components/presentationals/abstract-internal/abstract-internal.presentational";
-import {SOLIDIFY_CONSTANTS} from "../../../../core/constants";
+import { AbstractInternalPresentational } from "../../../../core/components/presentationals/abstract-internal/abstract-internal.presentational";
+import { SOLIDIFY_CONSTANTS } from "../../../../core/constants";
 import {
   isEmptyString,
   isNonEmptyArray,
@@ -49,25 +49,25 @@ import {
   isNotNullNorUndefinedNorWhiteString,
   isNullOrUndefined,
 } from "../../../../core/tools/is/is.tool";
-import {MappingObject} from "../../../../core/types/mapping-type.type";
-import {MappingObjectUtil} from "../../../../core/utils/mapping-object.util";
-import {ObjectUtil} from "../../../../core/utils/object.util";
-import {ObservableUtil} from "../../../../core/utils/observable.util";
-import {StringUtil} from "../../../../core/utils/string.util";
+import { MappingObject } from "../../../../core/types/mapping-type.type";
+import { MappingObjectUtil } from "../../../../core/utils/mapping-object.util";
+import { ObjectUtil } from "../../../../core/utils/object.util";
+import { ObservableUtil } from "../../../../core/utils/observable.util";
+import { StringUtil } from "../../../../core/utils/string.util";
 
 class FileFlatNode {
   constructor(public folderName: string,
-              public fullFolderName: string,
-              public level: number = 0,
-              public expandable: boolean = false,
-              public postCreation: boolean = false) {
+    public fullFolderName: string,
+    public level: number = 0,
+    public expandable: boolean = false,
+    public postCreation: boolean = false) {
   }
 }
 
 class FileNode {
   constructor(public folderName: string,
-              public fullFolderName: string,
-              public children: FileNode[]) {
+    public fullFolderName: string,
+    public children: FileNode[]) {
   }
 }
 
@@ -391,24 +391,34 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
   }
 
   static computeCurrentFolderAfterDelete(intermediateFolders: string[], foldersWithIntermediateFolders: string[], searchString: string): string {
-    let url = searchString.substring(0, searchString.lastIndexOf(this.ROOT));
-    if (isEmptyString(url)) {
-      return this.ROOT;
-    } else {
-      let folderWithIntFolders = foldersWithIntermediateFolders.find(folder => folder === url);
-      let intFolder = intermediateFolders.find(ft => ft === folderWithIntFolders);
-      if(isNotNullNorUndefined(intFolder)) {
-         let parentWithChild = foldersWithIntermediateFolders.find(folder => folder.startsWith(intFolder)
-                                                                          && folder !== searchString
-                                                                          && folder.substring(intFolder.length).length > 1);
-         if (isNotNullNorUndefined(parentWithChild)) {
-           return intFolder;
-         }else {
-           return this.computeCurrentFolderAfterDelete(intermediateFolders, foldersWithIntermediateFolders, url);
-         }
+    function computeRecursively(currentSearchString: string): string {
+      // Extract the URL without the ROOT
+      let url = currentSearchString.substring(0, currentSearchString.lastIndexOf(FolderTreePresentational.ROOT));
+
+      if (isEmptyString(url)) {
+        return FolderTreePresentational.ROOT;
       } else {
-        return folderWithIntFolders;
+        let folderWithIntFolders = foldersWithIntermediateFolders.find(folder => folder === url);
+        let intFolder = intermediateFolders.find(ft => ft === folderWithIntFolders);
+
+        if (isNotNullNorUndefined(intFolder)) {
+          // Find a folder with a child.
+          let parentWithChild = foldersWithIntermediateFolders.find(folder => folder.startsWith(intFolder) &&
+            (folder.length === searchString.length && folder !== searchString) && folder.substring(intFolder.length).length > 1);
+
+          if (isNotNullNorUndefined(parentWithChild)) {
+            return intFolder;
+          } else {
+            // Recursively call the internal function with the updated search string
+            return computeRecursively(url);
+          }
+        } else {
+          return folderWithIntFolders;
+        }
       }
     }
+    // Call the internal function with the original search string
+    return computeRecursively(searchString);
   }
+
 }
-- 
GitLab


From 197e999a8fce3c9aa6216f9c5c089912ac25ea57 Mon Sep 17 00:00:00 2001
From: Homada Boumedane <homada.boumedane@unige.ch>
Date: Fri, 26 Jan 2024 10:56:30 +0100
Subject: [PATCH 6/7] refactor: correct code review

---
 .../folder-tree/folder-tree.presentational.ts        | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index e9c66d9b7..5f354321b 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -391,19 +391,19 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
   }
 
   static computeCurrentFolderAfterDelete(intermediateFolders: string[], foldersWithIntermediateFolders: string[], searchString: string): string {
-    function computeRecursively(currentSearchString: string): string {
+    const computeRecursively = (currentSearchString: string): string => {
       // Extract the URL without the ROOT
-      let url = currentSearchString.substring(0, currentSearchString.lastIndexOf(FolderTreePresentational.ROOT));
+      const url = currentSearchString.substring(0, currentSearchString.lastIndexOf(FolderTreePresentational.ROOT));
 
       if (isEmptyString(url)) {
         return FolderTreePresentational.ROOT;
       } else {
-        let folderWithIntFolders = foldersWithIntermediateFolders.find(folder => folder === url);
-        let intFolder = intermediateFolders.find(ft => ft === folderWithIntFolders);
+        const folderWithIntFolders = foldersWithIntermediateFolders.find(folder => folder === url);
+        const intFolder = intermediateFolders.find(ft => ft === folderWithIntFolders);
 
         if (isNotNullNorUndefined(intFolder)) {
           // Find a folder with a child.
-          let parentWithChild = foldersWithIntermediateFolders.find(folder => folder.startsWith(intFolder) &&
+          const parentWithChild = foldersWithIntermediateFolders.find(folder => folder.startsWith(intFolder) &&
             (folder.length === searchString.length && folder !== searchString) && folder.substring(intFolder.length).length > 1);
 
           if (isNotNullNorUndefined(parentWithChild)) {
@@ -416,7 +416,7 @@ export class FolderTreePresentational<TDataFile extends any> extends AbstractInt
           return folderWithIntFolders;
         }
       }
-    }
+    };
     // Call the internal function with the original search string
     return computeRecursively(searchString);
   }
-- 
GitLab


From 0fbddede35d898197e024e824590f81a721c0b91 Mon Sep 17 00:00:00 2001
From: Florent Poittevin <florent.poittevin@unige.ch>
Date: Fri, 26 Jan 2024 11:04:42 +0100
Subject: [PATCH 7/7] chore: fix style

---
 .../folder-tree/folder-tree.presentational.ts | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
index 5f354321b..0992f7b3a 100644
--- a/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
+++ b/projects/solidify-frontend/src/lib/application/components/presentationals/folder-tree/folder-tree.presentational.ts
@@ -21,8 +21,8 @@
  * ----------------------------------------------------------------------------------------------%%
  */
 
-import { CdkDragDrop } from "@angular/cdk/drag-drop";
-import { FlatTreeControl } from "@angular/cdk/tree";
+import {CdkDragDrop} from "@angular/cdk/drag-drop";
+import {FlatTreeControl} from "@angular/cdk/tree";
 import {
   AfterViewInit,
   ChangeDetectionStrategy,
@@ -40,8 +40,8 @@ import {
   BehaviorSubject,
   Observable,
 } from "rxjs";
-import { AbstractInternalPresentational } from "../../../../core/components/presentationals/abstract-internal/abstract-internal.presentational";
-import { SOLIDIFY_CONSTANTS } from "../../../../core/constants";
+import {AbstractInternalPresentational} from "../../../../core/components/presentationals/abstract-internal/abstract-internal.presentational";
+import {SOLIDIFY_CONSTANTS} from "../../../../core/constants";
 import {
   isEmptyString,
   isNonEmptyArray,
@@ -49,25 +49,25 @@ import {
   isNotNullNorUndefinedNorWhiteString,
   isNullOrUndefined,
 } from "../../../../core/tools/is/is.tool";
-import { MappingObject } from "../../../../core/types/mapping-type.type";
-import { MappingObjectUtil } from "../../../../core/utils/mapping-object.util";
-import { ObjectUtil } from "../../../../core/utils/object.util";
-import { ObservableUtil } from "../../../../core/utils/observable.util";
-import { StringUtil } from "../../../../core/utils/string.util";
+import {MappingObject} from "../../../../core/types/mapping-type.type";
+import {MappingObjectUtil} from "../../../../core/utils/mapping-object.util";
+import {ObjectUtil} from "../../../../core/utils/object.util";
+import {ObservableUtil} from "../../../../core/utils/observable.util";
+import {StringUtil} from "../../../../core/utils/string.util";
 
 class FileFlatNode {
   constructor(public folderName: string,
-    public fullFolderName: string,
-    public level: number = 0,
-    public expandable: boolean = false,
-    public postCreation: boolean = false) {
+              public fullFolderName: string,
+              public level: number = 0,
+              public expandable: boolean = false,
+              public postCreation: boolean = false) {
   }
 }
 
 class FileNode {
   constructor(public folderName: string,
-    public fullFolderName: string,
-    public children: FileNode[]) {
+              public fullFolderName: string,
+              public children: FileNode[]) {
   }
 }
 
-- 
GitLab