Skip to content

Commit

Permalink
fix(files): apply search text filter to allFiles list
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Jul 3, 2024
1 parent 0eedaaa commit 82eaad3
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/components/specific/files/files-manager/FilesManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
:foldersToUpload="foldersToUpload"
:loadingFileIds="loadingFileIds"
:allTags="allTags"
:allFiles="allFiles"
:allFiles="displayedAllFiles"
:filesTabs="filesTabs"
:selectedFileTab="selectedFileTab"
:selection="selection"
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand All @@ -776,6 +784,7 @@ export default {
return {
// References
currentFolder,
displayedAllFiles,
displayedFiles,
filesToDelete,
filesToUpload,
Expand Down

0 comments on commit 82eaad3

Please sign in to comment.