Skip to content
Snippets Groups Projects

refactor: compute current folder after a delete

Merged Homada.Boumedane requested to merge hbo_refactor_folder_tree into master
@@ -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,
@@ -79,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;
@@ -269,7 +271,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));
const 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;
@@ -381,4 +389,36 @@ 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 {
const computeRecursively = (currentSearchString: string): string => {
// Extract the URL without the ROOT
const url = currentSearchString.substring(0, currentSearchString.lastIndexOf(FolderTreePresentational.ROOT));
if (isEmptyString(url)) {
return FolderTreePresentational.ROOT;
} else {
const folderWithIntFolders = foldersWithIntermediateFolders.find(folder => folder === url);
const intFolder = intermediateFolders.find(ft => ft === folderWithIntFolders);
if (isNotNullNorUndefined(intFolder)) {
// Find a folder with a child.
const 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);
}
}
Loading