From 82eaad3952175fc4b0f206d326eeebb24de29d86 Mon Sep 17 00:00:00 2001 From: NicolasRichel Date: Wed, 3 Jul 2024 11:24:28 +0200 Subject: [PATCH] fix(files): apply search text filter to allFiles list --- .../files/files-manager/FilesManager.vue | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/components/specific/files/files-manager/FilesManager.vue b/src/components/specific/files/files-manager/FilesManager.vue index 1fd5c4eb3..7effeb92f 100644 --- a/src/components/specific/files/files-manager/FilesManager.vue +++ b/src/components/specific/files/files-manager/FilesManager.vue @@ -209,7 +209,7 @@ :foldersToUpload="foldersToUpload" :loadingFileIds="loadingFileIds" :allTags="allTags" - :allFiles="allFiles" + :allFiles="displayedAllFiles" :filesTabs="filesTabs" :selectedFileTab="selectedFileTab" :selection="selection" @@ -389,6 +389,27 @@ export default { const visasLoading = ref(false); const allTags = ref([]); + const getFilesInFolder = (folder) => { + const files = []; + folder.children.forEach((child) => { + if (isFolder(child)) { + files.push(...getFilesInFolder(child)); + } else { + files.push(child); + } + }); + return files; + }; + const allFiles = computed(() => + props.fileStructure.children.flatMap((file) => { + if (isFolder(file)) { + return getFilesInFolder(file); + } else { + return file; + } + }) + ); + watch( () => props.fileStructure, (struct) => { @@ -452,6 +473,14 @@ export default { (file) => file.name ); + // Apply search to "allFiles" list + const displayedAllFiles = computed(() => { + const text = searchText.value.trim().toLowerCase(); + return text ? allFiles.value.filter(file => + file.name.toLowerCase().includes(text) + ) : allFiles.value; + }); + const selection = ref([]); const setSelection = (models) => { selection.value = models; @@ -734,27 +763,6 @@ export default { openModal({ component: SubscriptionModal }); }; - const getFilesInFolder = (folder) => { - const files = []; - folder.children.forEach((child) => { - if (isFolder(child)) { - files.push(...getFilesInFolder(child)); - } else { - files.push(child); - } - }); - return files; - }; - const allFiles = computed(() => - props.fileStructure.children.flatMap((file) => { - if (isFolder(file)) { - return getFilesInFolder(file); - } else { - return file; - } - }) - ); - const filesTabs = reactive([ { id: "folders", @@ -776,6 +784,7 @@ export default { return { // References currentFolder, + displayedAllFiles, displayedFiles, filesToDelete, filesToUpload,